Skip to content

Commit

Permalink
Give proper error message when refusing to overwrite existing branch
Browse files Browse the repository at this point in the history
If fast-export was asked to export a Mercurial branch to Git and a
branch of the same name already existed in the Git repo but it was not
created by fast export, fast-export would crash while trying to format
an error message claiming that the destination branch was modified
behind its back.

This patch extends fast-export to detect the situation above and give
a proper error message which hopefully is less confusing to the user.

Credits for discovering the original crash goes to Shun-ichi Goto
<[email protected]>.

Closes: #269.
  • Loading branch information
frej committed Aug 27, 2021
1 parent 4227621 commit 5b7ca5a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hg-fast-export.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ def verify_heads(ui,repo,cache,force,ignore_unnamed_heads,branchesmap):
sanitized_name=sanitize_name(b,"branch",branchesmap)
sha1=get_git_sha1(sanitized_name)
c=cache.get(sanitized_name)
if sha1!=c:
if not c and sha1:
stderr_buffer.write(
b'Error: Branch [%s] already exists and was not created by hg-fast-export, '
b'export would overwrite unrelated branch\n' % b)
if not force: return False
elif sha1!=c:
stderr_buffer.write(
b'Error: Branch [%s] modified outside hg-fast-export:'
b'\n%s (repo) != %s (cache)\n' % (b, b'<None>' if sha1 is None else sha1, c)
Expand Down

0 comments on commit 5b7ca5a

Please sign in to comment.