Asserts that a given target directory is a git repository
14405
def _assert_git_repo(target):
        
        hooks_dir = os.path.abspath(os.path.join(target, HOOKS_DIR_PATH))
        if not os.path.isdir(hooks_dir):
            raise GitHookInstallerError(u"{0} is not a git repository.".format(target))
1128946
def is_git_directory_clean(path_to_repo: Path,
                           search_parent_dirs: bool = True,
                           check_untracked: bool = False) -> None:
    
    repo = Repo(str(path_to_repo), search_parent_directories=search_parent_dirs)
    logger.debug("is_git_directory_clean check for repo in path={} from "\
                  "cwd={} with search_parent_directories={}".format(
                        path_to_repo, os.getcwd(), search_parent_dirs))

    # If there are changes to already tracked files
    if repo.is_dirty():
        raise DirtyRepoException("Changes to the index or working tree."
                                 "Commit them first .")
    if check_untracked:
        if repo.untracked_files:
            raise DirtyRepoException("Untracked files. Commit them first.")
1029974
def require_repo(directory=None):
    """"""
    if directory and not os.path.isdir(directory):
        raise ValueError('Directory not found: ' + repr(directory))
    repo = repo_path(directory)
    if not os.path.isdir(repo):
        raise RepositoryNotFoundError(directory)
    return repo
936922
def reuse_dist_file(filename):
    
    # if target file doesn't exist, we must generate it
    if not os.path.isfile(filename):
        return False

    # if we can interact with git, we can regenerate it, so we may as well
    try:
        import git
    except ImportError:
        return True
    else:
        try:
            git.Repo().tags
        except (TypeError, git.GitError):
            return True
        else:
            return False
960433
def copy_to(version, directory)
      # Delete the directory to make sure no pervious version remains if
      # we are using a branch or symlink if using Dir.
      FileUtils.rm_rf(directory) if directory.exist?

      # Create directory if not exists
      FileUtils.mkdir_p directory

      # Copy hole repository
      FileUtils.cp_r("#{fetch(version).path}/.", directory)

      # Remove .git directory
      FileUtils.rm_rf(File.join(directory, '.git'))

      nil
    end
266980
def repository(namespace, name, branch='master'):
    ''''''
    with TemporaryDirectory() as download_path:
        old_directory = str(pwd()).strip()
        try:
            git.clone('https://github.com/{0}/{1}.git'.format(namespace, name), download_path)
            cd(download_path)
            git.fetch('origin', branch)
            git.checkout(branch)
            yield (download_path, git('rev-parse', 'HEAD'), redis.Dict(key="{0}.{1}".format(namespace, name)))
        except ErrorReturnCode_128:
            mkdir(download_path)
            yield (None, None, None)
        cd(old_directory)
1327183
def validate_commits(repo_dir, commits):
    """"""
    log.debug("Validating {c} exist in {r}".format(c=commits, r=repo_dir))
    repo = Repo(repo_dir)
    for commit in commits:
        try:
            commit = repo.commit(commit)
        except Exception:
            msg = ("Commit {commit} could not be found in repo {repo}. "
                   "You may need to pass --update to fetch the latest "
                   "updates to the git repositories stored on "
                   "your local computer.".format(repo=repo_dir, commit=commit))
            raise exceptions.InvalidCommitException(msg)

    return True
798411
def clone(self, folder, git_repository):
        
        os.makedirs(folder)
        git.Git().clone(git_repository, folder)
404839
def workdir=(dir)
      workdir = GitLib.find_workdir(dir)
      if workdir.nil?
        @workdir = dir
        logger.info { "Initializing new repository at #{dir}" }
        return command(:init)
      else
        @workdir = workdir
        logger.debug { "Opening existing repository at #{dir}" }
      end
    end
757454
def ensure():
        
        LOGGER.debug('checking repository')
        if not os.path.exists('.git'):
            LOGGER.error('This command is meant to be ran in a Git repository.')
            sys.exit(-1)
        LOGGER.debug('repository OK')
285049
def init(directory=None):
    """"""
    repo = repo_path(directory)
    if os.path.isdir(repo):
        raise RepositoryAlreadyExistsError(directory, repo)

    # Initialize repository with default template
    shutil.copytree(default_template_path, repo)

    message = '"Default presentation content."'
    subprocess.call(['git', 'init', '-q', repo])
    subprocess.call(['git', 'add', '.'], cwd=repo)
    subprocess.call(['git', 'commit', '-q', '-m', message], cwd=repo)

    return repo
460258
function clone(url, target, ref, key, log, fn) {
  var urlObj = parseurl(url);
  urlObj.auth = key + ':x-oauth-basic';
  var authurl = formaturl(urlObj) + '.git';

  var dir = target + '/.git';

  log('creating dir ' + dir);
  mkdirp(dir, function(err) {
    if (err) return fn(err);

    var remote = git.remote(authurl);
    var repo = git.repo(dir);
    var opts = {};
    opts.want = ref;
    log('fetching ' + url);
    repo.fetch(remote, opts, function(err) {
      if (err) return fn(err);
      log('checking out ' + ref);
      repo.resolveHashish(ref, function(err, hash) {
        if (err) return fn(err);
        log('updating head to ' + hash);
        repo.updateHead(hash, function(err) {
          if (err) return fn(err);
          exec('git checkout ' + hash, {cwd: target}, function(err, stdout, stderr) {
            fn(err);
          });
        });
      });
    });
  });
}
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)
1101107
function assertIsDirectory(path) {
  try {
    if (!fs.lstatSync(path).isDirectory()) {
      console.log('Path "' + path + '" is not a directory.');
      process.exit();
    }
  } catch (e) {
    console.log('Directory "' + path + '" could not be found.');
    process.exit();
  }
}
168868
def gitdir(path = Dir.pwd)
      g = MiniGit.new
      g.find_git_dir(path)[0]
    end
1027066
def do_install(ctx, verbose, fake):
    """"""
    click.echo('The following git aliases will be installed:\n')
    aliases = cli.list_commands(ctx)
    output_aliases(aliases)

    if click.confirm('\n{}Install aliases above?'.format('FAKE ' if fake else ''), default=fake):
        for alias in aliases:
            cmd = '!legit ' + alias
            system_command = 'git config --global --replace-all alias.{0} "{1}"'.format(alias, cmd)
            verbose_echo(system_command, verbose, fake)
            if not fake:
                os.system(system_command)
        if not fake:
            click.echo("\nAliases installed.")
    else:
        click.echo("\nAliases will not be installed.")
442712
def update_git_repository(self, folder, git_repository):
        

        # load repo object from path
        repo = git.Repo(folder)

        # keep local_head_name for to reset folder remote head later
        local_head_name = repo.head.ref.name

        # test if git repository url has changed
        remote = repo.remote('origin')
        if remote.url == git_repository:
            return

        # remove/add new remote repository origin
        remote.remove(repo, 'origin')
        origin = remote.add(repo, 'origin', git_repository)

        # fetch available branches
        origin.fetch()

        # get remote head according previously store local head name
        remote_head = getattr(origin.refs, local_head_name)
        # reset repository tracking branch according deduced remote head
        repo.create_head(local_head_name, remote_head)\
            .set_tracking_branch(remote_head)