X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/ca66756b4a6db44d87296263c75802619496d1ce..683840616efea425300859fe838add2b6b559a2c:/stgit/git.py diff --git a/stgit/git.py b/stgit/git.py index 6744be0..27d2595 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -366,13 +366,20 @@ def create_branch(new_branch, tree_id = None): if branch_exists(new_branch): raise GitException, 'Branch "%s" already exists' % new_branch + current_head_file = get_head_file() current_head = get_head() set_head_file(new_branch) __set_head(current_head) # a checkout isn't needed if new branch points to the current head if tree_id: - switch(tree_id) + try: + switch(tree_id) + except GitException: + # Tree switching failed. Revert the head file + set_head_file(current_head_file) + delete_branch(new_branch) + raise if os.path.isfile(os.path.join(basedir.get(), 'MERGE_HEAD')): os.remove(os.path.join(basedir.get(), 'MERGE_HEAD')) @@ -808,13 +815,10 @@ def barefiles(rev1, rev2): return '\n'.join(result) -def pretty_commit(commit_id = 'HEAD', diff_flags = []): +def pretty_commit(commit_id = 'HEAD', flags = []): """Return a given commit (log + diff) """ - return GRun('diff-tree', - *(diff_flags - + ['--cc', '--always', '--pretty', '-r', commit_id]) - ).raw_output() + return GRun('show', *(flags + [commit_id])).raw_output() def checkout(files = None, tree_id = None, force = False): """Check out the given or all files