获取可被 subprogress 执行的 git 参数 list。

    :param str path: git 仓库文件夹路径。
    :param \*args: git 的附加参数。
    :param bare: 是否视为 bare 库
10662
def get_args(path, *args, work_tree=True, bare=False):
    
    base = [ 'git' ]
    if path:
        base.append('-C')
        base.append(path)
        if bare:
            base.append('--bare')
            base.append("--git-dir="+path)
        else:
            base.append("--git-dir="+os.path.join(path, ".git"))
        if work_tree:
            base.append("--work-tree="+path)
    for arg in args:
        base.append(arg)
    return base
620853
def from_path(cls, path):
        """"""
        f = GitFile(path, 'rb')
        try:
            ret = cls.from_file(f)
            ret.path = path
            return ret
        finally:
            f.close()
148833
def git_log_iterator(path):
    
    N = 10
    count = 0
    while True:
        lines = _run_git_command_lines(['log', '--oneline',
                                        '-n', str(N),
                                        '--skip', str(count),
                                        '--', '.'], cwd=path)
        for line in lines:
            sha = line.split(' ', 1)[0]
            count += 1
            yield sha
        if len(lines) < N:
            break
1022825
def subtree_up(path = Dir.pwd)
      error "Unable to pull subtree(s): Dirty Git repository" if FalkorLib::Git.dirty?( path )
      exit_status = 0
      git_root_dir = rootdir(path)
      Dir.chdir(git_root_dir) do
        FalkorLib.config.git[:subtrees].each do |dir, conf|
          next if conf[:url].nil?
          #url    = conf[:url]
          remote = dir.gsub(/\//, '-')
          branch = (conf[:branch].nil?) ? 'master' : conf[:branch]
          remotes = FalkorLib::Git.remotes
          info "Pulling changes into subtree '#{dir}' using remote '#{remote}/#{branch}'"
          raise IOError, "The git remote '#{remote}' is not configured" unless remotes.include?( remote )
          info "\t\\__ fetching remote '#{remotes.join(',')}'"
          FalkorLib::Git.fetch( git_root_dir )
          raise IOError, "The git subtree directory '#{dir}' does not exists" unless File.directory?( File.join(git_root_dir, dir) )
          info "\t\\__ pulling changes"
          exit_status = execute "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
          #exit_status = puts "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
        end
      end
      exit_status
    end
723950
def _AddPathSegments(self, path, ignore_list):
    
    path_segments = path.split(self._path_segment_separator)
    for path_segment_index, path_segment in enumerate(path_segments):
      if path_segment_index not in self.path_segments_per_index:
        self.path_segments_per_index[path_segment_index] = {}

      if path_segment_index not in ignore_list:
        path_segments = self.path_segments_per_index[path_segment_index]

        if path_segment not in path_segments:
          path_segments[path_segment] = []

        paths_per_segment_list = path_segments[path_segment]
        paths_per_segment_list.append(path)
1075628
def list_files(paths = [], options = {})
      ref = options[:ref] || 'HEAD'
      path_list = paths.empty? ? '' : "\"#{paths.join('" "')}\""
      `git ls-tree --name-only #{ref} #{path_list}`.
        split(/\n/).
        map { |relative_file| File.expand_path(relative_file) }.
        reject { |file| File.directory?(file) } # Exclude submodule directories
    end
31461
def apply_change(self, path, *args):
        # type: (List[str], Any) -> None
        """"""
        if len(path) > 1:
            # This is for a child
            self[path[0]].apply_change(path[1:], *args)
        else:
            # This is for us
            assert len(path) == 1 and len(args) == 1, \
                "Cannot process change %s" % ([self.path + path] + list(args))
            getattr(self, "set_%s" % path[0])(args[0])
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()
467214
def relpath(path, start=posixpath.curdir):
    """"""
    if not path:
        raise ValueError("no path specified")

    start_list = posixpath.abspath(start).split(posixpath.sep)
    path_list = posixpath.abspath(path).split(posixpath.sep)

    # Work out how much of the filepath is shared by start and path.
    i = len(posixpath.commonprefix([start_list, path_list]))

    rel_list = [posixpath.pardir] * (len(start_list) - i) + path_list[i:]
    if not rel_list:
        return posixpath.curdir
    return posixpath.join(*rel_list)
1056306
def pull(self):
        
        git.Repo(self.path).remote().pull(self.branch)
176467
def _walk_to_root(path):
    
    if not os.path.exists(path):
        raise IOError('Starting path not found')

    if os.path.isfile(path):
        path = os.path.dirname(path)

    last_dir = None
    current_dir = os.path.abspath(path)
    while last_dir != current_dir:
        yield current_dir
        parent_dir = os.path.abspath(os.path.join(current_dir, os.path.pardir))
        last_dir, current_dir = current_dir, parent_dir
1185908
def add(path, msg = "", options = {})
      exit_status = 0
      dir  = File.realpath(File.dirname(path))
      root = rootdir(path)
      relative_path_to_root = Pathname.new( File.realpath(path) ).relative_path_from Pathname.new(root)
      real_msg = ((msg.empty?) ? "add '#{relative_path_to_root}'" : msg)
      opts = '-f' if options[:force]
      Dir.chdir( dir ) do
        exit_status = run %(
                  git add #{opts} #{path}
                  git commit -s -m "#{real_msg}" #{path}
                )
      end
      exit_status.to_i
    end
502921
def walklevel(path, depth = -1, **kwargs):
        
        # if depth is negative, just walk
        if depth < 0:
            for root, dirs, files in os.walk(path, **kwargs):
                yield root, dirs, files

        # path.count works because is a file has a "/" it will show up in the list
        # as a ":"
        path    = path.rstrip(os.path.sep)
        num_sep = path.count(os.path.sep)
        for root, dirs, files in os.walk(path, **kwargs):
            yield root, dirs, files
            num_sep_this = root.count(os.path.sep)
            if num_sep + depth <= num_sep_this:
                del dirs[:]
793866
def with_path(self, path):
        
        new_command = copy.deepcopy(self)
        new_command._paths.append(str(path))
        return new_command
40388
def walk(self, top, topdown=True, ignore_file_handler=None):
        

        tree = self.git_object_by_path(top)
        if tree is None:
            raise IOError(errno.ENOENT, "No such file")

        for x in self._walk(tree, topdown):
            yield x
458540
def itemByPath( self, path, includeRoot = False ):
        
        sep     = self.separator()
        path    = nativestring(path).strip(sep)
        if ( not path ):
            if ( includeRoot ):
                return self.invisibleRootItem()
            else:
                return None
            
        splt    = path.split(sep)
        item    = self.invisibleRootItem()
        for part in splt:
            next_item = None
            for row in range(item.rowCount()):
                child = item.child(row)
                if ( child.text() == part ):
                    next_item = child
                    break
            
            if ( not next_item ):
                item = None
                break
                
            item = next_item
            item.initialize()
        
        return item
981777
def subst_path(self, env, target, source):
        
        result = []
        for type, value in self.pathlist:
            if type == TYPE_STRING_SUBST:
                value = env.subst(value, target=target, source=source,
                                  conv=node_conv)
                if SCons.Util.is_Sequence(value):
                    result.extend(SCons.Util.flatten(value))
                elif value:
                    result.append(value)
            elif type == TYPE_OBJECT:
                value = node_conv(value)
                if value:
                    result.append(value)
            elif value:
                result.append(value)
        return tuple(result)