Convenience method for setting the git executable path.
173340
def refresh(path=None):
    """"""
    global GIT_OK
    GIT_OK = False

    if not Git.refresh(path=path):
        return
    if not FetchInfo.refresh():
        return

    GIT_OK = True
314495
public function set_repo_path($repo_path, $create_new = false, $_init = true) {
		if (is_string($repo_path)) {
			if ($new_path = realpath($repo_path)) {
				$repo_path = $new_path;
				if (is_dir($repo_path)) {
					// Is this a work tree?
					if (file_exists($repo_path."/.git") && is_dir($repo_path."/.git")) {
						$this->repo_path = $repo_path;
						$this->bare = false;
					// Is this a bare repo?
					} else if (is_file($repo_path."/config")) {
					  $parse_ini = parse_ini_file($repo_path."/config");
						if ($parse_ini['bare']) {
							$this->repo_path = $repo_path;
							$this->bare = true;
						}
					} else {
						if ($create_new) {
							$this->repo_path = $repo_path;
							if ($_init) {
								$this->run('init');
							}
						} else {
							throw new \Exception('"'.$repo_path.'" is not a git repository');
						}
					}
				} else {
					throw new \Exception('"'.$repo_path.'" is not a directory');
				}
			} else {
				if ($create_new) {
					if ($parent = realpath(dirname($repo_path))) {
						mkdir($repo_path);
						$this->repo_path = $repo_path;
						if ($_init) $this->run('init');
					} else {
						throw new \Exception('cannot create repository in non-existent directory');
					}
				} else {
					throw new \Exception('"'.$repo_path.'" does not exist');
				}
			}
		}
	}
93037
def _to_relative_path(self, path):
        """"""
        if not osp.isabs(path):
            return path
        if self.repo.bare:
            raise InvalidGitRepositoryError("require non-bare repository")
        if not path.startswith(self.repo.working_tree_dir):
            raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))
        return os.path.relpath(path, self.repo.working_tree_dir)
1070428
def makefile(dir = Dir.pwd, options = {})
      path = normalized_path(dir)
      path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
      info "=> Setup a root repository makefile in '#{dir}'"
      # Preparing submodule
      submodules = {}
      submodules['Makefiles'] = {
        :url    => 'https://github.com/Falkor/Makefiles.git',
        :branch => 'devel'
      }
      FalkorLib::Git.submodule_init(path, submodules)
      makefile = File.join(path, "Makefile")
      if File.exist?( makefile )
        puts "  ... not overwriting the root Makefile which already exists"
      else
        src_makefile = File.join(path, FalkorLib.config.git[:submodulesdir],
                                 'Makefiles', 'repo', 'Makefile')
        FileUtils.cp src_makefile, makefile
        gitflow_branches = FalkorLib::Config::GitFlow::DEFAULTS[:branches]
        if FalkorLib::GitFlow.init?(path)
          [ :master, :develop ].each do |b|
            gitflow_branches[b.to_sym] = FalkorLib::GitFlow.branches(b.to_sym)
          end
        end
        unless options.nil?
          [ :master, :develop ].each do |b|
            gitflow_branches[b.to_sym] = options[b.to_sym] if options[b.to_sym]
          end
        end
        info "adapting Makefile to the gitflow branches"
        Dir.chdir( path ) do
          run %(
   sed -i '' \
        -e \"s/^GITFLOW_BR_MASTER=production/GITFLOW_BR_MASTER=#{gitflow_branches[:master]}/\" \
        -e \"s/^GITFLOW_BR_DEVELOP=devel/GITFLOW_BR_DEVELOP=#{gitflow_branches[:develop]}/\" \
        Makefile
                        )
        end
        FalkorLib::Git.add(makefile, 'Initialize root Makefile for the repo')
      end
    end
238660
def path(cls, ref):
        
        return osp.join(ref.repo.git_dir, "logs", to_native_path(ref.path))
561478
def set_root_path(self, root_path):
        """"""
        if self.name is None:
            self.name = osp.basename(root_path)
        self.root_path = to_text_string(root_path)
        config_path = self.__get_project_config_path()
        if osp.exists(config_path):
            self.load()
        else:
            if not osp.isdir(self.root_path):
                os.mkdir(self.root_path)
            self.save()
1258095
def get_git_file_path(filename):
    
    git_root = get_git_root(filename)
    return relpath(filename, git_root).replace("\\", "/") if git_root else ''
1331159
def absolute_git_root_dir(fpath=""):
    
    if len(fpath) == 0:
        dirname_str = os.getcwd()
    else:
        dirname_str = os.path.dirname(fpath)
    dirname_str = os.path.abspath(dirname_str)
    dirnames = dirname_str.split(os.sep)
    n = len(dirnames)
    for i in xrange(n):
        # is there a .git directory at this level?
        # FIXME hack
        basedir = "/" + os.path.join(*dirnames[0:n - i])
        gitdir = os.path.join(basedir, ".git")
        if os.path.exists(gitdir):
            return basedir
1255254
def path(self, root_dir):
    """"""
    path = os.path.realpath(root_dir)
    if not os.path.exists(path):
      raise ValueError('Build root does not exist: {}'.format(root_dir))
    self._root_dir = path
774108
def is_git(path):
    """"""
    try:
        repo_dir = run_cmd(path, 'git', 'rev-parse', '--git-dir')
        return True if repo_dir else False
    except (OSError, RuntimeError):
        return False
370410
def repo_context(url, branch=None, quiet=True, dest_ctx=temp_dir):
	
	exe = 'git' if 'git' in url else 'hg'
	with dest_ctx() as repo_dir:
		cmd = [exe, 'clone', url, repo_dir]
		if branch:
			cmd.extend(['--branch', branch])
		devnull = open(os.path.devnull, 'w')
		stdout = devnull if quiet else None
		subprocess.check_call(cmd, stdout=stdout)
		yield repo_dir
169725
def exec_path(self, baseVersion=None):
    """"""
    if not os.path.isdir(self.data_dir):
        raise sc_process.SC2LaunchError("Install Starcraft II at %s or set the SC2PATH environment variable"%(self.data_dir))
    if baseVersion==None: # then select most recent version's baseVersion
        mostRecent = versions.handle.mostRecent
        if mostRecent:  return mostRecent["base-version"]
        raise sc_process.SC2LaunchError(
            "When requesting a versioned executable path without specifying base-version, expected "
            "to find StarCraft II versions installed at %s."%(self.versionsDir))
    elif isinstance(baseVersion, versions.Version):
        baseVersion = baseVersion.baseVersion
    elif str(baseVersion).count(".") > 0:
        baseVersion = versions.Version(baseVersion).baseVersion
    #else: # otherwise expect that the baseVersion specified is correct
    baseVersExec = os.path.join(self.versionsDir, "Base%s"%baseVersion, self._exec_name)
    if os.path.isfile(baseVersExec):
        return baseVersExec # if baseVersion in Versions subdir is valid, it is the correct executable
    raise sc_process.SC2LaunchError("Specified baseVersion %s does not exist at %s.%s    available: %s"%(\
        baseVersion, baseVersExec, os.linesep, " ".join(
            str(val) for val in sorted(self.versionMap().keys())) ))
77492
def run_git(self, args, git_env=None):
        '''
        
        '''

        popen_kwargs = {
            'stdout': subprocess.PIPE,
            'stderr': subprocess.PIPE,
        }

        if git_env:
            popen_kwargs['env'] = git_env

        if self._git_toplevel:
            popen_kwargs['cwd'] = self._git_toplevel

        git_process = subprocess.Popen(
            [GitRunner._git_executable] + args,
            **popen_kwargs
        )

        try:
            out, err = git_process.communicate()
            git_process.wait()
        except Exception as e:
            raise GitError("Couldn't run 'git {args}':{newline}{ex}".format(
                args=' '.join(args),
                newline=os.linesep,
                ex=str(e)
            ))

        if (0 != git_process.returncode) or err:
            if err:
                err = err.decode('utf_8')
            raise GitError("'git {args}' failed with:{newline}{err}".format(
                args=' '.join(args),
                newline=os.linesep,
                err=err
            ))

        if not out:
            raise ValueError("No output")

        return out.decode('utf_8').splitlines()
1295146
def get_or_create_environment(self, repo: str, branch: str, git_repo: Repo, repo_path: Path) -> str:
        
        return sys.executable
742
def find_git_repository(self, path):
        
        while path is not None:
            git_path = os.path.join(path,'.git')
            if os.path.exists(git_path) and os.path.isdir(git_path):
                return path
            path = os.path.dirname(path)
        return None
738589
def main(argv=None):
    """"""
    if argv is None:
        argv = sys.argv[1:]
    usage = '\n\n\n'.join(__doc__.split('\n\n\n')[1:])
    version = 'Gitpress ' + __version__

    # Parse options
    args = docopt(usage, argv=argv, version=version)

    # Execute command
    try:
        return execute(args)
    except RepositoryNotFoundError as ex:
        error('No Gitpress repository found at', ex.directory)
950816
def _set_relative_pythonpath(self, value):
        """"""
        self.pythonpath = [osp.abspath(osp.join(self.root_path, path))
                           for path in value]