Read the remote CHANGES.md file.

@param string $git github|bitbucket|gitlab|gitea)
@param string $changes Changelog filename.
@param string $request API request.

@return bool
192451
public function get_remote_api_changes( $git, $changes, $request ) {
		$response = isset( $this->response['changes'] ) ? $this->response['changes'] : false;

		// Set $response from local file if no update available.
		if ( ! $response && ! $this->can_update_repo( $this->type ) ) {
			$response = $this->get_local_info( $this->type, $changes );
		}

		if ( ! $response ) {
			self::$method = 'changes';
			$response     = $this->api( $request );
			$response     = $this->decode_response( $git, $response );
		}

		if ( ! $response && ! is_wp_error( $response ) ) {
			$response          = new \stdClass();
			$response->message = 'No changelog found';
		}

		if ( $this->validate_response( $response ) ) {
			return false;
		}

		if ( $response && ! isset( $this->response['changes'] ) ) {
			$parser   = new \Parsedown();
			$response = $parser->text( $response );
			$this->set_repo_cache( 'changes', $response );
		}

		$this->type->sections['changelog'] = $response;

		return true;
	}
52482
@RequestMapping(value = "changelog/export", method = RequestMethod.GET)
    public ResponseEntity<String> changeLog(IssueChangeLogExportRequest request) {
        // Gets the change log
        GitChangeLog changeLog = gitService.changeLog(request);
        // Gets the associated project
        Project project = changeLog.getProject();
        // Gets the configuration for the project
        GitConfiguration gitConfiguration = gitService.getProjectConfiguration(project);
        if (gitConfiguration == null) {
            throw new GitProjectNotConfiguredException(project.getId());
        }
        // Gets the issue service
        Optional<ConfiguredIssueService> optConfiguredIssueService = gitConfiguration.getConfiguredIssueService();
        if (!optConfiguredIssueService.isPresent()) {
            return new ResponseEntity<>(
                    "The branch is not configured for issues",
                    HttpStatus.NO_CONTENT
            );
        }
        ConfiguredIssueService configuredIssueService = optConfiguredIssueService.get();
        // Gets the issue change log
        GitChangeLogIssues changeLogIssues = gitService.getChangeLogIssues(changeLog);
        // List of issues
        List<Issue> issues = changeLogIssues.getList().stream()
                .map(SCMChangeLogIssue::getIssue)
                .collect(Collectors.toList());
        // Exports the change log using the given format
        ExportedIssues exportedChangeLogIssues = configuredIssueService.getIssueServiceExtension()
                .exportIssues(
                        configuredIssueService.getIssueServiceConfiguration(),
                        issues,
                        request
                );
        // Content type
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("Content-Type", exportedChangeLogIssues.getFormat() + "; charset=utf-8");
        // Body and headers
        return new ResponseEntity<>(exportedChangeLogIssues.getContent(), responseHeaders, HttpStatus.OK);
    }
413905
private function fetchAllCommits(GitRepository $git)
    {
        $currentCommit = $this->fetchCurrentCommit($git);

        $cacheId = \md5(__FUNCTION__ . \serialize($currentCommit));

        if (!$this->cachePool->has($cacheId)) {
            $logList = \json_decode(
                \sprintf(
                    '[%s]',
                    \trim(
                        // git log --simplify-merges --format=$this->logFormat()
                        $git->log()->simplifyMerges()->format($this->logFormat() . ',')->execute(),
                        ','
                    )
                ),
                true
            );

            $this->cachePool->set($cacheId, $logList);

            return $logList;
        }

        return $this->cachePool->get($cacheId);
    }
921167
public function getTheReadme($owner, $repo, $ref = null)
	{
		$data = array();
		if(!is_null($ref))
			$data['ref'] = $ref;
		
		return $this->client->request("/repos/$owner/$repo/readme", 'GET', $data, 200, 'GitHubRepoContent');
	}
1099893
private function buildFileHistory(GitRepository $git)
    {
        $filePath = $this->getFilePathCollection($this->currentPath);

        // If the commit history only merges,
        // then use the last merge commit for find the renaming file for follow the history.
        if (\count((array) $filePath['commits']) === $this->countMergeCommits($filePath['commits'])) {
            $commit = $filePath['commits'][\array_reverse(\array_keys($filePath['commits']))[0]];
            if ($this->isMergeCommit($commit)) {
                $parents = \explode(' ', $commit['parent']);

                $arguments = [
                    $git->getConfig()->getGitExecutablePath(),
                    'diff',
                    $commit['commit'],
                    $parents[1],
                    '--diff-filter=R',
                    '--name-status',
                    '--format=',
                    '-M'
                ];

                // git diff currentCommit rightCommit --diff-filter=R --name-status --format='' -M
                $matches = $this->matchFileInformation($this->runCustomGit($arguments, $git));
                foreach ($matches as $match) {
                    if (!\in_array($this->currentPath, $match)) {
                        continue;
                    }

                    $this->currentPath = $match['to'];
                    $filePath          = $this->getFilePathCollection($this->currentPath);
                    break;
                }
            }
        }

        $fileHistory = $this->fetchFileHistory($this->currentPath, $git);
        if (!\count($fileHistory)) {
            return;
        }

        foreach ($fileHistory as $pathHistory) {
            $filePath['pathHistory'][\md5($pathHistory)] = $this->getFilePathCollection($pathHistory);
        }

        $this->setFilePathCollection($this->currentPath, $filePath);
    }
668296
@RequestMapping(value = "changelog", method = RequestMethod.GET)
    public BuildDiff changeLog(BuildDiffRequest request) {
        GitChangeLog changeLog = gitService.changeLog(request);
        // Stores in cache
        logCache.put(changeLog.getUuid(), changeLog);
        // OK
        return changeLog;
    }
364016
private function decode_response( $git, $response ) {
		switch ( $git ) {
			case 'github':
			case 'gitlab':
				$response = isset( $response->content ) ? base64_decode( $response->content ) : $response;
				break;
			case 'bbserver':
				$response = isset( $response->lines ) ? $this->bbserver_recombine_response( $response ) : $response;
				break;
		}

		return $response;
	}
231809
def get_changed_files_from(old_commit_sha, new_commit_sha):
        
        return check_output(
            "git diff-tree --no-commit-id --name-only -r {0}..{1}".format(
                old_commit_sha,
                new_commit_sha
            ).split(" ")
            ).decode('utf-8').strip()
227607
public function findChangedByGit(): ?\Generator
    {
        // -u expand dir's files
        [, $output,] = Sys::run('git status -s -u', $this->basePath);

        // 'D some.file'    deleted
        // ' M some.file'   modified
        // '?? some.file'   new file
        foreach (\explode("\n", \trim($output)) as $file) {
            $file = \trim($file);

            // only php file.
            if (!\strpos($file, '.php')) {
                continue;
            }

            // modified files
            if (\strpos($file, 'M ') === 0) {
                yield \substr($file, 2);

                // new files
            } elseif (\strpos($file, '?? ') === 0) {
                yield \substr($file, 3);
            }
        }
    }
1279551
protected function get_changelog_filename( $repo ) {
		$changelogs  = [ 'CHANGES.md', 'CHANGELOG.md', 'changes.md', 'changelog.md' ];
		$changes     = null;
		$local_files = null;

		if ( is_dir( $repo->local_path ) ) {
			$local_files = scandir( $repo->local_path, 0 );
		}

		$changes = array_intersect( (array) $local_files, $changelogs );
		$changes = array_pop( $changes );

		if ( ! empty( $changes ) ) {
			return $changes;
		}

		return false;
	}
1704
private function fetchNameStatusFromCommit($commitId, GitRepository $git)
    {
        $arguments = [
            $git->getConfig()->getGitExecutablePath(),
            'show',
            $commitId,
            '-M',
            '--name-status',
            '--format='
        ];

        // git show $commitId -M --name-status --format=''
        return $this->runCustomGit($arguments, $git);
    }
232494
private function parse_release_asset( $git, $request, $response ) {
		switch ( $git ) {
			case 'github':
				$download_link = isset( $response->assets[0] ) && ! is_wp_error( $response ) ? $response->assets[0]->browser_download_url : null;

				// Private repo.
				$response = ( null !== $download_link && ( property_exists( $this->type, 'is_private' ) && $this->type->is_private ) ) ? $response->assets[0]->url : $download_link;
				break;
			case 'bitbucket':
				$download_base = $this->get_api_url( $request, true );
				$response      = isset( $response->values[0] ) && ! is_wp_error( $response ) ? $download_base . '/' . $response->values[0]->name : null;
				break;
			case 'bbserver':
				// TODO: make work.
				break;
			case 'gitlab':
				$response = $this->get_api_url( $request );
				break;
			case 'gitea':
				break;
		}

		return $response;
	}
736499
public function collect(Request $request, Response $response, \Exception $exception = null)
	{

		$fs = new Filesystem();

		// is there a web directory ?

		if ($fs->exists('../web') || $fs->exists('../public_html') || $fs->exists('../public')) {
			$gitPath = '../.git';
		} else {
			// unit tests
			$gitPath = '.git';
		}

		// if there is no .git directory
		if (!$fs->exists($gitPath)) {
			$this->data['gitData'] = false;
			return;
		}

		// get latest commit information
		exec("git log -1", $data);

		if (isset($data) && !empty($data)) {

			// there is some information
			$this->data['gitData'] = true;

			foreach ($data as $d) {

				if (strpos($d, 'commit') === 0) {

					// commit Id

					$this->data['commit'] = substr($d, 7);

				} elseif (strpos($d, 'Author') === 0) {

					// author and email

					preg_match('$Author: ([^<]+)<(.+)>$', $d, $author);

					if (isset($author[1])) {
						$this->data['author'] = trim($author[1]);
					}
					if (isset($author[2])) {
						$this->data['email'] = $author[2];
					}

				} elseif (strpos($d, 'Date') === 0) {

					$date = trim(substr($d, 5)); // ddd mmm n hh:mm:ss yyyy +gmt

					// date of commit
					$dateCommit = date_create($date);

					// actual date at runtime
					$dateRuntime = new \DateTime();
					$dateNow = date_create($dateRuntime->format('Y-m-d H:i:s'));

					// difference
					$time = date_diff($dateCommit, $dateNow);

					// static time difference : minutes and seconds
					$this->data['timeCommitIntervalMinutes'] = $time->format('%y')*365*24*60+$time->format('%m')*30*24*60+$time->format('%d')*24*60+$time->format('%h')*60+$time->format('%i');
					$this->data['timeCommitIntervalSeconds'] = $time->format('%s');

					// full readable date
					$this->data['date'] = $date;

				} elseif (strpos($d, 'Merge') === 0) {

					// merge information

					$this->data['merge'] = trim(substr($d, 6));

				} else {

					// commit message

					$this->data['message'] = trim($d);

				}

			}

			unset($data);

			exec("git status", $data);

			if (isset($data[0])) {

				if (strstr($data[0], 'On branch')) {

					// branch name

					$this->data['branch'] = trim(substr($data[0], strpos($data[0], 'On branch')+9));

				}
			}

		} else {

			// no git data

			$this->data['gitData'] = false;

		}


	}
5038
public function compare()
    {
        $remoteRevision = null;
        $filesToUpload = array();
        $filesToDelete = array();

        // The revision file goes inside the submodule.
        if ($this->isSubmodule) {
            $this->revisionFile = $this->isSubmodule . '/' . $this->revisionFile;
        }

        if ($this->bridge->exists($this->revisionFile)) {
            $remoteRevision = $this->bridge->get($this->revisionFile);

            $message = "\r\n» Taking it from '" . substr($remoteRevision, 0, 7) . "'";
        } else {
            $message = "\r\n» Fresh deployment - grab a coffee";
        }

        // A remote version exists.
        if ($remoteRevision) {
            // Get the files from the diff.
            $output = $this->git->diff($remoteRevision);

            foreach ($output as $line) {
                // Added, changed or modified.
                if ($line[0] == 'A' or $line[0] == 'C' or $line[0] == 'M') {
                    $filesToUpload[] = trim(substr($line, 1));
                }
                // Deleted.
                elseif ($line[0] == 'D') {
                    $filesToDelete[] = trim(substr($line, 1));
                }
                // Unknown status.
                else {
                    throw new Exception("Unknown git-diff status: {$line[0]}");
                }
            }
        }
        // No remote version. Get all files.
        else {
            $filesToUpload = $this->git->files();
        }

        // Remove ignored files from the list of uploads.
        $filesToUpload = array_diff($filesToUpload, $this->ignoredFiles);

        $this->filesToUpload = $filesToUpload;
        $this->filesToDelete = $filesToDelete;

        return $message;
    }
915490
public function changelogAction(Request $request, $canonicalName)
    {
        $kernel = $this->get('kernel');
        $em = $this->getDoctrine()->getManager();
        $application = $em
            ->getRepository('CanalTPSamCoreBundle:Application')
            ->findOneByCanonicalName($canonicalName);

        if (is_null($application)) {
            throw $this->createNotFoundException('Application (' . $canonicalName . ') not found.');
        }
        try {
            $path = $kernel->locateResource('@' . $application->getBundleName() . '/CHANGELOG.md');
        } catch (\InvalidArgumentException $e) {
            throw $this->createNotFoundException('Changelog file for ' . $application->getName() . ' not found.');
        }
        return new BinaryFileResponse($path);
    }
280342
def do_update
      # note that a recent fetch was performed by remote_differs? and even if
      # remotes have changed again in the brief interim it would invalidate
      # the decisions already made if we refetched now.
      git_repo = git_repo_for(@repo_dir)
      @logger.operation(:cleanup, "ensure no untracked files in #{@repo_dir}") do
        git_repo.hard_reset_to(nil)
        do_clean_all(git_repo)
      end
      do_checkout_revision(git_repo)
      do_clean_all(git_repo)  # clean again once we are on requested revision
      internal_update_tag(git_repo)
      true
    end
55138
def get_changed_files(self) -> List[str]:
        
        out = shell_tools.output_of(
            'git',
            'diff',
            '--name-only',
            self.compare_commit_id,
            self.actual_commit_id,
            '--',
            cwd=self.destination_directory)
        return [e for e in out.split('\n') if e.strip()]