Create a new git repository

Accepts a creation path, and, optionally, a source path

@access  public
@param   string  repository path
@param   string  directory to source
@param   string  reference path
@return  GitRepo
429155
public static function &create_new($repo_path, $source = null, $remote_source = false, $reference = null) {
		if (is_dir($repo_path) && file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
			throw new \Exception('"'.$repo_path.'" is already a git repository');
		} else {
			$repo = new self($repo_path, true, false);
			if (is_string($source)) {
				if ($remote_source) {
					if (!is_dir($reference) || !is_dir($reference.'/.git')) {
						throw new \Exception('"'.$reference.'" is not a git repository. Cannot use as reference.');
					} else if (strlen($reference)) {
						$reference = realpath($reference);
						$reference = "--reference $reference";
					}
					$repo->clone_remote($source, $reference);
				} else {
					$repo->clone_from($source);
				}
			} else {
				$repo->run('init');
			}
			return $repo;
		}
	}
277032
public static function add_to_repo($repository_path, $files = null)
    {
        $repo = new pakeMercurial($repository_path);
        $repo->add($files);

        return $repo;
    }
850168
function clone(git_url, git_ref, clone_dir){
    
    var needsGitCheckout = !!git_ref;
    if (!shell.which('git')) {
        return Q.reject(new Error('"git" command line tool is not installed: make sure it is accessible on your PATH.'));
    }

    // If no clone_dir is specified, create a tmp dir which git will clone into.
    var tmp_dir = clone_dir;
    if(!tmp_dir){
        tmp_dir = path.join(os.tmpdir(), 'git', String((new Date()).valueOf()));
    }
    shell.rm('-rf', tmp_dir);
    shell.mkdir('-p', tmp_dir);
    
    var cloneArgs = ['clone'];
    if(!needsGitCheckout) {
        // only get depth of 1 if there is no branch/commit specified
        cloneArgs.push('--depth=1');
    }
    cloneArgs.push(git_url, tmp_dir);
    return superspawn.spawn('git', cloneArgs)
    .then(function() {
        if (needsGitCheckout){
            return superspawn.spawn('git', ['checkout', git_ref], {
                cwd: tmp_dir
            });
        }
    })
    .then(function(){
        events.emit('log', 'Repository "' + git_url + '" checked out to git ref "' + (git_ref || 'master') + '".');
        return tmp_dir;
    })
    .fail(function (err) {
        shell.rm('-rf', tmp_dir);
        return Q.reject(err);
    });
}
857928
def rootdir(path = Dir.pwd)
      g = MiniGit.new
      g.find_git_dir(path)[1]
    end
90881
function resolveGitRoot(filepath) {
    var relativeToGit, repoId;

    // No git repo cloned, or file is not in a git repository
    if (!GIT_TMP || !pathUtil.isInRoot(GIT_TMP, filepath)) return null;

    // Extract first directory (is the repo id)
    relativeToGit = path.relative(GIT_TMP, filepath);
    repoId = _.first(relativeToGit.split(path.sep));
    if (!repoId) return;

    // Return an absolute file
    return path.resolve(GIT_TMP, repoId);
}
1372346
private void initClonedRepository() throws GitAPIException, IOException {
		if (!getUri().startsWith(FILE_URI_PREFIX)) {
			deleteBaseDirIfExists();
			Git git = cloneToBasedir();
			if (git != null) {
				git.close();
			}
			git = openGitRepository();
			if (git != null) {
				git.close();
			}
		}

	}
704678
def clone(self, repo, ref, deps=()):
        """"""

        if os.path.isdir(repo):
            repo = os.path.abspath(repo)

        def clone_strategy(directory):
            env = git.no_git_env()

            def _git_cmd(*args):
                cmd_output('git', *args, cwd=directory, env=env)

            _git_cmd('init', '.')
            _git_cmd('remote', 'add', 'origin', repo)

            try:
                self._shallow_clone(ref, _git_cmd)
            except CalledProcessError:
                self._complete_clone(ref, _git_cmd)

        return self._new_repo(repo, ref, deps, clone_strategy)
64047
public static function findGitRepository($directory)
    {
        $process = new Process('git rev-parse --show-toplevel', $directory);
        $process->run();

        if (!$process->isSuccessful()) {
            return false;
        }

        $rootPath = trim($process->getOutput());
        return new Git($rootPath);
    }
893247
public static function repository(?string $app = null): Repository
    {
        self::initialize();
        if ($app === null) {
            $app = '*';
        }

        // Autoload default "config" in project root.
        if ($app === '*' && !isset(self::$repositories[$app])) {
            $path = Path::root('config');
            if (!is_dir($path)) {
                throw new ConfigException('Path ' . $path . ' does not exist.');
            }
            self::$repositories[$app] = new Repository($path);
        }

        if (!isset(self::$repositories[$app])) {
            throw new ConfigException('Application ' . $app . ' not registered.');
        }
        return self::$repositories[$app];
    }
891390
protected static function initRepository(Binary $git, $path, $initArguments = null)
    {
        $initArguments = $initArguments ?: Array();

        /** @var $result CallResult */
        $result = $git->{'init'}($path, $initArguments);
        $result->assertSuccess(sprintf('Cannot initialize a Git repository in "%s"', $path));
    }
585820
def create_git_ref(self, ref, sha):
        
        assert isinstance(ref, (str, unicode)), ref
        assert isinstance(sha, (str, unicode)), sha
        post_parameters = {
            "ref": ref,
            "sha": sha,
        }
        headers, data = self._requester.requestJsonAndCheck(
            "POST",
            self.url + "/git/refs",
            input=post_parameters
        )
        return github.GitRef.GitRef(self._requester, headers, data, completed=True)
788404
public static function create($path = 'Staq\Core\Ground', $baseUri = NULL, $platform = NULL)
    {
        return (new \Staq\Server)->createApplication($path, $baseUri, $platform);
    }
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));
    }
209894
public static function init($directory, array $params = NULL){
		if(is_dir("$directory/.git")){
			throw new GitException("Repo already exists in $directory.");
		}
		
		if(!is_dir($directory) && !@mkdir($directory, 0777, TRUE)){
			throw new GitException("Unable to create directory '$directory'.");
		}
		
		$cwd = getcwd();
		chdir($directory);
		exec(self::processCommand(array(
				'git init',
				$params,
				$directory,
		)), $output, $returnCode);
		
		if($returnCode !== 0){
			throw new GitException(implode("<br>", $output));
		}
		
		$repo = getcwd();
		chdir($cwd);
		return new static($repo);
	}
1204982
protected function createResource($path, $reference)
    {
        if (null === $reference) {
            $resource = new GenericResource();
        } elseif (isset($reference[0]) && '@' === $reference[0]) {
            $resource = new LinkResource(substr($reference, 1));
        } elseif (is_dir($reference)) {
            $resource = new DirectoryResource($reference);
        } elseif (is_file($reference)) {
            $resource = new FileResource($reference);
        } else {
            throw new RuntimeException(sprintf(
                'Trying to create a FilesystemResource on a non-existing file or directory "%s"',
                $reference
            ));
        }

        $resource->attachTo($this, $path);

        return $resource;
    }
1212635
public function import(GitRepositoryEntity $gitRepository)
    {
        $importer = $this->app->make(TranslatableImporter::class);
        $fetcher = $this->app->make(Fetcher::class, ['gitRepository' => $gitRepository]);
        $packagesRepo = $this->app->make(PackageRepository::class);
        $package = $packagesRepo->findOneBy(['handle' => $gitRepository->getPackageHandle()]);
        if ($package === null) {
            if ($this->logger !== null) {
                $this->logger->notice(t('Creating new package with handle %s', $gitRepository->getPackageHandle()));
            }
            $package = PackageEntity::create($gitRepository->getPackageHandle());
            $this->em->persist($package);
            $this->em->flush($package);
        }
        if ($this->logger !== null) {
            $this->logger->debug(t('Cloning/fetching repository'));
        }
        $fetcher->update();
        if ($this->logger !== null) {
            $this->logger->debug(t('Listing tags'));
        }
        $taggedVersions = $fetcher->getTaggedVersions();
        foreach ($taggedVersions as $tag => $version) {
            if ($gitRepository->getDetectedVersion($version) === null) {
                $gitRepository->addDetectedVersion($version, 'tag', $tag);
                $this->em->persist($gitRepository);
                $this->em->flush($gitRepository);
            }
            $packageVersion = null;
            foreach ($package->getVersions() as $pv) {
                if ($pv->getVersion() === $version) {
                    $packageVersion = $pv;
                    break;
                }
            }
            if ($packageVersion === null) {
                if ($this->logger !== null) {
                    $this->logger->debug(t('Checking out tag %s', $tag, $version));
                }
                $fetcher->switchToTag($tag);
                if ($this->logger !== null) {
                    $this->logger->info(t('Extracting strings from tag %1$s for version %2$s', $tag, $version));
                }
                $importer->importDirectory($fetcher->getRootDirectory(), $package->getHandle(), $version, '');
            } else {
                if ($this->logger !== null) {
                    $this->logger->debug(t('Tag already imported: %1$s (version: %2$s)', $tag, $version));
                }
            }
        }
        foreach ($gitRepository->getDevBranches() as $branch => $version) {
            if ($gitRepository->getDetectedVersion($version) === null) {
                $gitRepository->addDetectedVersion($version, 'branch', $branch);
                $this->em->persist($gitRepository);
                $this->em->flush($gitRepository);
            }
            if ($this->logger !== null) {
                $this->logger->debug(t('Checking out development branch %s', $branch));
            }
            $fetcher->switchToBranch($branch);
            if ($this->logger !== null) {
                $this->logger->info(t('Extracting strings from development branch %1$s for version %2$s', $branch, $version));
            }
            $importer->importDirectory($fetcher->getRootDirectory(), $package->getHandle(), $version, '');
        }
    }
1119709
public static function createByFilePath($filepath) : Repository
    {
        $filename = basename($filepath);
        list($domain, $language, $extension) = explode('.', $filename, 3);

        $yamlParser = new YamlParser();
        $data = $yamlParser->parse(file_get_contents($filepath));

        $emptyArray = [];
        $translations = [];
        self::createPlainRepresentationByArray(
            $translations,
            $language,
            ($data) ?: [],
            $emptyArray,
            ''
        );

        $translationCollection = TranslationCollection::create($translations);

        return new self(
            $translationCollection,
            $filepath,
            $language,
            $domain
        );
    }