p.tochild.write(line)
p.tochild.close()
if p.wait():
- raise GitException, '%s failed (%s)' % (str(cmd),
+ raise GitException, '%s failed (%s)' % (' '.join(cmd),
p.childerr.read().strip())
def _input_str(cmd, string):
p.tochild.write(string)
p.tochild.close()
if p.wait():
- raise GitException, '%s failed (%s)' % (str(cmd),
+ raise GitException, '%s failed (%s)' % (' '.join(cmd),
p.childerr.read().strip())
def _output(cmd):
p=popen2.Popen3(cmd, True)
output = p.fromchild.read()
if p.wait():
- raise GitException, '%s failed (%s)' % (str(cmd),
+ raise GitException, '%s failed (%s)' % (' '.join(cmd),
p.childerr.read().strip())
return output
p.tochild.close()
output = p.fromchild.readline().strip()
if p.wait():
- raise GitException, '%s failed (%s)' % (str(cmd),
+ raise GitException, '%s failed (%s)' % (' '.join(cmd),
p.childerr.read().strip())
return output
p=popen2.Popen3(cmd, True)
lines = p.fromchild.readlines()
if p.wait():
- raise GitException, '%s failed (%s)' % (str(cmd),
+ raise GitException, '%s failed (%s)' % (' '.join(cmd),
p.childerr.read().strip())
return lines
return r
return 0
-def __tree_status(files = None, tree_id = 'HEAD', unknown = False,
- noexclude = True, verbose = False):
+def tree_status(files = None, tree_id = 'HEAD', unknown = False,
+ noexclude = True, verbose = False, diff_flags = []):
"""Returns a list of pairs - [status, filename]
"""
if verbose:
cache_files += [('C', filename) for filename in conflicts]
# the rest
- for line in _output_lines(['git-diff-index', tree_id, '--'] + files):
+ for line in _output_lines(['git-diff-index'] + diff_flags +
+ [ tree_id, '--'] + files):
fs = tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
if fs[1] not in conflicts:
cache_files.append(fs)
def local_changes(verbose = True):
"""Return true if there are local changes in the tree
"""
- return len(__tree_status(verbose = verbose)) != 0
+ return len(tree_status(verbose = verbose)) != 0
# HEAD value cached
__head = None
if not files:
files = []
- cache_files = __tree_status(files, verbose = False)
+ cache_files = tree_status(files, verbose = False)
# everything is up-to-date
if len(cache_files) == 0:
raise GitException, 'GIT index merging failed (possible conflicts)'
def status(files = None, modified = False, new = False, deleted = False,
- conflict = False, unknown = False, noexclude = False):
+ conflict = False, unknown = False, noexclude = False,
+ diff_flags = []):
"""Show the tree status
"""
if not files:
files = []
- cache_files = __tree_status(files, unknown = True, noexclude = noexclude)
+ cache_files = tree_status(files, unknown = True, noexclude = noexclude,
+ diff_flags = diff_flags)
all = not (modified or new or deleted or conflict or unknown)
if not all:
raise GitException, 'git.diffstat failed'
return diff_str
-def files(rev1, rev2):
+def files(rev1, rev2, diff_flags = []):
"""Return the files modified between rev1 and rev2
"""
result = ''
- for line in _output_lines(['git-diff-tree', '-r', rev1, rev2]):
+ for line in _output_lines(['git-diff-tree'] + diff_flags + ['-r', rev1, rev2]):
result += '%s %s\n' % tuple(line.rstrip().split(' ',4)[-1].split('\t',1))
return result.rstrip()
return result.rstrip()
-def pretty_commit(commit_id = 'HEAD'):
+def pretty_commit(commit_id = 'HEAD', diff_flags = []):
"""Return a given commit (log + diff)
"""
- return _output(['git-diff-tree', '--cc', '--always', '--pretty', '-r',
- commit_id])
+ return _output(['git-diff-tree'] + diff_flags +
+ ['--cc', '--always', '--pretty', '-r', commit_id])
def checkout(files = None, tree_id = None, force = False):
"""Check out the given or all files
tree_id = get_head()
if check_out:
- cache_files = __tree_status(files, tree_id)
+ cache_files = tree_status(files, tree_id)
# files which were added but need to be removed
rm_files = [x[1] for x in cache_files if x[0] in ['A']]
# here we are sure to have a single fetch_head
return fetch_head
+
+def all_refs():
+ """Return a list of all refs in the current repository.
+ """
+
+ return [line.split()[1] for line in _output_lines(['git-show-ref'])]