@param string $repo
@param null   $path
@param null   $ref

@return array
@throws \DreamFactory\Core\Exceptions\RestException
556473
public function repoList($repo, $path = null, $ref = null)
    {
        $src = $this->client->api('Repositories\Src');
        /** @var \Buzz\Message\Response $response */
        $response = $this->checkResponse($src->get($this->username, $repo, $ref, $path));

        return $this->cleanSrcList(json_decode($response->getContent(), true));
    }
1022155
public function download($owner, $repo, $ref)
    {
        // local filesystem
        $fs = $this->getFs();
        // projects filesystem
        $pfs = $this->project->getFiles();
        // remote filesystem (repo on github/bitbucket)
        $rfs = $this->remote->getFilesystem($repo, $owner, $ref);

        $files = $rfs->allFiles($this->docPath);
        $files = Arr::without($files, [ $this->indexPath, $this->menuPath ]);
        $total = count($files);

        if ( !$rfs->exists($this->indexPath) )
        {
            return $this->syncer->log('error', 'syncRef could not find the index file', [ $this->indexPath ]);
        }

        if ( !$rfs->exists($this->menuPath) )
        {
            return $this->syncer->log('error', 'syncRef could not find the menu file', [ $this->menuPath ]);
        }

        foreach ( $files as $current => $filePath )
        {
            $destPath = path_relative($filePath, $this->docPath);
            if ( $rfs->exists($filePath) )
            {
                $pfs->put(path_join($ref, $destPath), $rfs->get($filePath));
            }
            $this->getSyncer()->fire('tick.file', [ $current, $total, $filePath, $this->syncer, $this ]);
        }

        // index and menu resolving
        $pfs->put(path_join($ref, 'index.md'), $rfs->get($this->indexPath));
        $pfs->put(path_join($ref, 'menu.yml'), $rfs->get($this->menuPath));

        return $this;
    }
36480
public function get($name, $repoName = null, ...$args)
    {
        $repo = $this->getRepository($repoName);

        if (!$repo) {
            return null;
        }

        $method = 'get' . ucfirst($name);

        if (!is_callable([$repo, $method])) {
            return null;
        }

        return $repo->$method(...$args);
    }
1097009
protected function waiting_for_background_update( $repo = null ) {
		$caches = [];
		if ( null !== $repo ) {
			$cache = isset( $repo->slug ) ? $this->get_repo_cache( $repo->slug ) : null;

			return empty( $cache );
		}
		$repos = array_merge(
			Singleton::get_instance( 'Plugin', $this )->get_plugin_configs(),
			Singleton::get_instance( 'Theme', $this )->get_theme_configs()
		);
		foreach ( $repos as $git_repo ) {
			$caches[ $git_repo->slug ] = $this->get_repo_cache( $git_repo->slug );
		}
		$waiting = array_filter(
			$caches,
			function ( $e ) {
				return empty( $e );
			}
		);

		return ! empty( $waiting );
	}
749449
def get_repos(path):
    
    p = str(path)
    ret = []
    if not os.path.exists(p):
        return ret
    for d in os.listdir(p):
        pd = os.path.join(p, d)
        if os.path.exists(pd) and is_repo(pd):
            ret.append(Local(pd))
    return ret
327352
def get_repo(self, repo: str, branch: str, *,
                 depth: Optional[int]=1,
                 reference: Optional[Path]=None
                 ) -> Repo:
        
        git_repo, _ = self.get_files(repo, branch, depth=depth, reference=reference)

        return git_repo
4578
public function main($params, $ref)
    {
        $params['pathParts'] = array_filter($params['pathParts'], function ($v, $k) {
            return !empty($v);
        }, ARRAY_FILTER_USE_BOTH);

        return null;
    }
1091459
public function getAction(Request $request, $reference, $path)
    {
        $path = '/' . $path;
        $session = $this->getSessionByHash($reference);
        $tree = $session->getDirectory($path);

        return $this->handleView(
            $this->view(
                new Directory(
                    $tree,
                    basename($path),
                    $reference,
                    $request->get('depth', -1),
                    $this->getBooleanRequestParameter($request, 'name-as-key', false, false),
                    $this->getBooleanRequestParameter($request, 'only-directories', false, false),
                    $this->getBooleanRequestParameter($request, 'only-files', false, false)
                )
            )
        );
    }
229043
public function actionClone($vendor = null, $repo = null)
    {
        // if `vendor/repo` notation is provided
        if ($vendor !== null && strpos($vendor, '/')) {
            list($vendor, $repo) = explode("/", $vendor);
        }
        
        if (empty($vendor)) {
            $vendor = $this->prompt("Enter the username/vendor for this repo (e.g. luyadev)");
        }
        
        if (empty($repo)) {
            $repo = $this->prompt("Enter the name of the repo you like to clone (e.g. luya-module-news)");
        }
        
        $clones = $this->getConfig(self::CONFIG_VAR_CUSTOMCLONES, []);
        
        $repoFileSystemPath = $this->getFilesystemRepoPath($repo);
        
        $clones[$repo] = $repoFileSystemPath;
        
        $this->cloneRepo($repo, $this->getCloneUrlBasedOnType($repo, $vendor), $repoFileSystemPath, $vendor);
        
        $this->saveConfig(self::CONFIG_VAR_CUSTOMCLONES, $clones);
        
        $composerReader = new ComposerReader($repoFileSystemPath . DIRECTORY_SEPARATOR . 'composer.json');
        
        if ($composerReader->canRead()) {
            $section = new AutoloadSection($composerReader);
            $autoloaders = [];
            foreach ($section as $autoload) {
                $newSrc = $repoFileSystemPath . DIRECTORY_SEPARATOR . $autoload->source;
                $autoloaders[] = ['autoload' => $autoload, 'src' => $newSrc];
            }
            
            if (!empty($autoloaders)) {
                foreach ($autoloaders as $item) {
                    $projectComposer = $this->getProjectComposerReader();
                    if ($projectComposer->canWrite()) {
                        $new = new Autoload($projectComposer, $item['autoload']->namespace, $item['src'], $item['autoload']->type);
                        
                        $section = new AutoloadSection($projectComposer);
                        $section->add($new)->save();
                        
                        $this->outputSuccess("{$repo}: autoload ✔ (namespace '{$item['autoload']->namespace}' for '{$item['autoload']->source}')");
                    }
                }
                
                $projectComposer = $this->getProjectComposerReader();
                $projectComposer->runCommand('dump-autoload');
            }
        }
    }
1286740
public function init($path = null)
    {
        $path = is_null($path) ? $this->environment->path : $path;

        // Check if clone already exists at this path. If so we can safely skip.
        if (file_exists($path)) {
            $wrapper = new GitWrapper();
            $wrapper->setTimeout(3600);

            try {
                $working_copy = new GitWorkingCopy($wrapper, $path);
                $output = $working_copy->remote('-v');
            } catch (GitException $e) {
                throw new \Exception('Path already exists.');
            }

            // if repo exists in the remotes already, this working copy is ok.
            if (strpos(strtolower($output), strtolower($this->app->repo)) !== false) {
                return true;
            } else {
                throw new Exception('Git clone already exists at that path, but it is not for this app.');
            }
        }

        try {
            // Create App folder
            mkdir($path, 0755, TRUE);
            chdir($path);

            // Clone repo
            $wrapper = new GitWrapper();
            $wrapper->setTimeout(3600);
            $wrapper->streamOutput();
            $wrapper->cloneRepository($this->app->repo, $path);

            // Checkout correct version.
            $git = new GitWorkingCopy($wrapper, $this->getSourcePath());
            $git->checkout($this->environment->version);

        } catch (\GitWrapper\GitException $e) {

            // If exception is because there is no git ref, continue.
            if (strpos($e->getMessage(), 'error: pathspec') !== 0) {
                return false;
            }
        }

        chdir($path);
        $wrapper->git('branch');
        $wrapper->git('status');
        $this->loadConfig();

        // Run the build hooks
        if (!empty($this->config['hooks']['build'])) {
            chdir($this->getSourcePath());
            $process = new Process($this->config['hooks']['build']);
            $process->run(function ($type, $buffer) {
                if (Process::ERR === $type) {
                    echo $buffer;
                } else {
                    echo $buffer;
                }
            });
        }

        return $this->writeConfig();
    }
336168
public function repository(string $user, string $repo): ?array
    {
        $api = $this->client->api('repo');
        $params = [$user, $repo];

        $repo = $this->callGitHub([$api, 'show'], $params);

        return is_array($repo) ? $repo : null;
    }
636072
public function remove(string $repo, array $params = [])
    {
        $path = $this->buildUsersPath($repo);

        return $this->delete($path, $params);
    }
413420
public static function create($repo_path, $source = null)
    {
        try {
            $repo = new Repository($repo_path);
            $remote = $repo->getRemoteOriginUrl();
            if ($remote===$source || $remote.'.git'===$source || $remote===$source.'.git') {
                $branch = $repo->getCurrentBranch();
                $repo->pull($remote, $branch);
                return $repo;
            }
        } catch (\Exception $e) {
        }
        return Repository::createNew($repo_path, $source);
    }
430028
public function urlForReference(string $user, string $repo, string $ref): string
    {
        $key = sprintf(self::CACHE_KEY_TEMPLATE, md5($user . $repo), 'ref_url_' . md5($ref));

        if (($latest = $this->getFromCache($key)) !== null) {
            return $latest;
        }

        [$type, $resolved] = $this->resolveRefType($ref);
        $repoURL = $this->urlForRepository($user, $repo);

        switch ($type) {
            case 'commit':
                $url = "${repoURL}/commit/${resolved}";
                break;

            case 'tag':
                $url = "${repoURL}/releases/tag/${resolved}";
                break;

            case 'pull':
                $url = "${repoURL}/pull/${resolved}";
                break;

            case 'branch':
            default:
                $url = "${repoURL}/tree/${resolved}";
        }

        $this->setToCache($key, $url, 30);
        return $url;
    }
583450
public function getArchiveLink(string $archiveFormat = AbstractApi::ARCHIVE_TARBALL,
                                   string $ref = AbstractApi::BRANCH_MASTER): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/:archive_format/:ref',
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $archiveFormat, $ref));
    }
277032
public static function add_to_repo($repository_path, $files = null)
    {
        $repo = new pakeMercurial($repository_path);
        $repo->add($files);

        return $repo;
    }
55001
private function getCommits($org, $repo, $version)
    {
        $url = sprintf(
            self::GITHUB_COMPARE_ENDPOINT,
            $org,
            $repo,
            $version
        );

        $res = json_decode($this->http->get($url, [
            'auth' => [null, $this->token]
        ])->getBody(), true);
        $commits = [];
        foreach ($res['commits'] as $commit) {
            $message = $commit['commit']['message'];

            $description = explode("\n", $message)[0];
            $matches = [];
            if (preg_match('/(.{0,})\(\#(\d{1,})\)/', $description, $matches) === 1) {
                $message = trim($matches[1]);
                $prNumber = isset($matches[2]) ? $matches[2] : null;
            } else {
                $prNumber = $this->askForPrNumber($message);
            }

            if (strpos($message, '[CHANGE ME]') === 0 && $prNumber) {
                $message = $this->getMessageFromPullRequest($org, $repo, $prNumber);
            }

            $commits[] = [
                'url' => $commit['url'],
                'htmlUrl' => $commit['html_url'],
                'message' => $message,
                'reference' => $prNumber,
                'hash' => $commit['sha']
            ];
        }

        return $commits;
    }