From 5b7ca5aaece48e3d05b63a393f5011df1d8ec69d Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Fri, 27 Aug 2021 15:47:26 +0200 Subject: [PATCH] Give proper error message when refusing to overwrite existing branch 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 . Closes: #269. --- hg-fast-export.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hg-fast-export.py b/hg-fast-export.py index eab315d0..16588301 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -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'' if sha1 is None else sha1, c)