X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/d92a3fd72956ed39ace26699aaf0d6d1ab84e5ed..0f92637c75d03080d43a9b8a95527660d61d67a5:/stgit/git.py diff --git a/stgit/git.py b/stgit/git.py index f6d6b43..86630ce 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -298,14 +298,18 @@ def set_head_file(ref): [os.path.join('refs', 'heads', ref)]) != 0: raise GitException, 'Could not set head to "%s"' % ref +def set_branch(branch, val): + """Point branch at a new commit object.""" + if __run('git-update-ref', [branch, val]) != 0: + raise GitException, 'Could not update %s to "%s".' % (branch, val) + def __set_head(val): """Sets the HEAD value """ global __head if not __head or __head != val: - if __run('git-update-ref HEAD', [val]) != 0: - raise GitException, 'Could not update HEAD to "%s".' % val + set_branch('HEAD', val) __head = val # only allow SHA1 hashes @@ -672,13 +676,15 @@ def merge(base, head1, head2, recursive = False): """ refresh_index() + err_output = None if recursive: # this operation tracks renames but it is slower (used in # general when pushing or picking patches) try: # use _output() to mask the verbose prints of the tool _output('git-merge-recursive %s -- %s %s' % (base, head1, head2)) - except GitException: + except GitException, ex: + err_output = str(ex) pass else: # the fast case where we don't track renames (used when the @@ -706,6 +712,11 @@ def merge(base, head1, head2, recursive = False): files[path][stage] = (mode, hash) + if err_output and not files: + # if no unmerged files, there was probably a different type of + # error and we have to abort the merge + raise GitException, err_output + # merge the unmerged files errors = False for path in files: @@ -760,20 +771,28 @@ def status(files = None, modified = False, new = False, deleted = False, else: print '%s' % fs[1] -def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None): +def diff(files = None, rev1 = 'HEAD', rev2 = None, out_fd = None, + binary = False): """Show the diff between rev1 and rev2 """ if not files: files = [] + args = [] + if binary: + args.append('--binary') + if rev1 and rev2: - diff_str = _output(['git-diff-tree', '-p', rev1, rev2, '--'] + files) + diff_str = _output(['git-diff-tree', '-p'] + args + + [rev1, rev2, '--'] + files) elif rev1 or rev2: refresh_index() if rev2: - diff_str = _output(['git-diff-index', '-p', '-R', rev2, '--'] + files) + diff_str = _output(['git-diff-index', '-p', '-R'] + + args + [rev2, '--'] + files) else: - diff_str = _output(['git-diff-index', '-p', rev1, '--'] + files) + diff_str = _output(['git-diff-index', '-p'] + + args + [rev1, '--'] + files) else: diff_str = ''