예제 #1
0
 def diff_index(self, treeish, name_only=False):
     """git diff-index --name-only HEAD --"""
     args = ['git', 'diff-index', treeish]
     if name_only:
         args.append('--name-only')
     proc = subprocess.Popen(args, stdout=subprocess.PIPE)
     stdout, stderr = proc.communicate()
     if proc.returncode != 0:
         raise exc.GitException((proc.returncode, stdout, stderr))
     filenames = [line.strip() for line in stdout.split('\n') if line]
     return filenames
예제 #2
0
 def log(self, cmd_arg=None, count=None, pretty=None, skip=None):
     args = ['git', 'log']
     if pretty:
         args.append("--pretty=%s" % pretty)
     if count is not None:
         args.append("-%d" % count)
     if skip is not None:
         args.append("--skip=%d" % skip)
     if cmd_arg:
         args.append(cmd_arg)
     proc = subprocess.Popen(args, stdout=subprocess.PIPE)
     stdout, stderr = proc.communicate()
     if proc.returncode != 0:
         raise exc.GitException((proc.returncode, stdout, stderr))
     return stdout
예제 #3
0
    def config(self, cmd, config_key=None, config_value=None):
        """Add/unset git configs"""
        args = ['git', 'config']

        if cmd == 'add':
            assert config_key and config_value
            args.extend(['--add', config_key, config_value])
        elif cmd == 'get':
            args.extend(['--get', config_key])
        elif cmd == 'unset':
            args.extend(['--unset', config_key])
        else:
            raise ValueError('unknown command %s' % cmd)

        proc = subprocess.Popen(args, stdout=subprocess.PIPE)
        stdout, stderr = proc.communicate()
        if proc.returncode != 0:
            raise exc.GitException((proc.returncode, stdout, stderr))
        lines = [line.strip() for line in stdout.split('\n') if line]
        return lines
예제 #4
0
    def format_patch(self, since, keep_subject=False, no_numbered=False,
                     no_stat=False):
        """Returns a list of patch files"""
        args = ['git', 'format-patch']

        if keep_subject:
            args.append('--keep-subject')

        if no_numbered:
            args.append('--no-numbered')

        if no_stat:
            args.append('--no-stat')

        args.append(since)

        proc = subprocess.Popen(args, stdout=subprocess.PIPE)
        stdout, stderr = proc.communicate()
        if proc.returncode != 0:
            raise exc.GitException((proc.returncode, stdout, stderr))
        filenames = [line.strip() for line in stdout.split('\n') if line]
        return filenames