mirror of
https://github.com/mnauw/git-remote-hg.git
synced 2025-11-01 17:15:49 +01:00
Only report success after successful push
Otherwise git core will update the namespaced refs, and show success to the user, even in the case of a crash. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
This commit is contained in:
@@ -1198,6 +1198,7 @@ def bookmark_is_fake(bmark, real_bmarks):
|
||||
def do_export(parser):
|
||||
p_bmarks = []
|
||||
p_revs = {}
|
||||
ok_refs = []
|
||||
|
||||
parser.next()
|
||||
|
||||
@@ -1236,7 +1237,7 @@ def do_export(parser):
|
||||
continue
|
||||
|
||||
p_revs[bnode] = ref
|
||||
print("ok %s" % ref)
|
||||
ok_refs.append(ref)
|
||||
elif ref.startswith('refs/heads/'):
|
||||
g_bmark = ref[len('refs/heads/'):]
|
||||
bmark = g_bmark.encode()
|
||||
@@ -1246,8 +1247,9 @@ def do_export(parser):
|
||||
if old == new:
|
||||
continue
|
||||
|
||||
print("ok %s" % ref)
|
||||
if not bookmark_is_fake(bmark, parser.repo._bookmarks):
|
||||
if bookmark_is_fake(bmark, parser.repo._bookmarks):
|
||||
ok_refs.append(ref)
|
||||
else:
|
||||
p_bmarks.append((ref, bmark, old, new))
|
||||
|
||||
if peer:
|
||||
@@ -1261,7 +1263,7 @@ def do_export(parser):
|
||||
p_revs[bnode] = ref
|
||||
elif ref.startswith('refs/tags/'):
|
||||
if dry_run:
|
||||
print("ok %s" % ref)
|
||||
ok_refs.append(ref)
|
||||
continue
|
||||
tag = ref[len('refs/tags/'):]
|
||||
tag = hgref(tag)
|
||||
@@ -1280,7 +1282,7 @@ def do_export(parser):
|
||||
fp.write(b'%s %s\n' % (node, tag))
|
||||
fp.close()
|
||||
p_revs[bnode] = ref
|
||||
print("ok %s" % ref)
|
||||
ok_refs.append(ref)
|
||||
else:
|
||||
# transport-helper/fast-export bugs
|
||||
continue
|
||||
@@ -1290,8 +1292,11 @@ def do_export(parser):
|
||||
return
|
||||
|
||||
if dry_run:
|
||||
if peer:
|
||||
checkheads(parser.repo, peer, p_revs)
|
||||
if not peer or checkheads(parser.repo, peer, p_revs):
|
||||
for ref, bmark, old, new in p_bmarks:
|
||||
print("ok %s" % ref)
|
||||
for ref in ok_refs:
|
||||
print("ok %s" % ref)
|
||||
print("")
|
||||
return
|
||||
|
||||
@@ -1306,14 +1311,22 @@ def do_export(parser):
|
||||
for ref, bmark, old, new in p_bmarks:
|
||||
if force_push:
|
||||
old = remote_bmarks.get(bmark, b'')
|
||||
if not peer.pushkey(b'bookmarks', bmark, old, new):
|
||||
if peer.pushkey(b'bookmarks', bmark, old, new):
|
||||
print("ok %s" % ref)
|
||||
else:
|
||||
print("error %s" % ref)
|
||||
else:
|
||||
# update local bookmarks
|
||||
for ref, bmark, old, new in p_bmarks:
|
||||
if not bookmarks.pushbookmark(parser.repo, bmark, old, new):
|
||||
if bookmarks.pushbookmark(parser.repo, bmark, old, new):
|
||||
print("ok %s" % ref)
|
||||
else:
|
||||
print("error %s" % ref)
|
||||
|
||||
# update rest of the refs
|
||||
for ref in ok_refs:
|
||||
print("ok %s" % ref)
|
||||
|
||||
print("")
|
||||
|
||||
def do_option(parser):
|
||||
|
||||
27
test/main.t
27
test/main.t
@@ -607,17 +607,14 @@ test_expect_success 'remote big push' '
|
||||
cd gitrepo &&
|
||||
|
||||
check_push 1 --all <<-\EOF
|
||||
master
|
||||
good_bmark
|
||||
branches/good_branch
|
||||
new_bmark:new
|
||||
branches/new_branch:new
|
||||
bad_bmark1:non-fast-forward
|
||||
bad_bmark2:non-fast-forward
|
||||
branches/bad_branch:non-fast-forward
|
||||
EOF
|
||||
) &&
|
||||
|
||||
check gitrepo origin/master one &&
|
||||
check gitrepo hg/origin/bookmarks/master one &&
|
||||
check_branch hgrepo default one &&
|
||||
check_branch hgrepo good_branch "good branch" &&
|
||||
check_branch hgrepo bad_branch "bad branch" &&
|
||||
@@ -645,8 +642,6 @@ test_expect_success 'remote big push fetch first' '
|
||||
cd gitrepo &&
|
||||
|
||||
check_push 1 --all <<-\EOF &&
|
||||
master
|
||||
good_bmark
|
||||
bad_bmark1:fetch-first
|
||||
branches/bad_branch:fetch-first
|
||||
EOF
|
||||
@@ -654,12 +649,13 @@ test_expect_success 'remote big push fetch first' '
|
||||
git fetch &&
|
||||
|
||||
check_push 1 --all <<-\EOF
|
||||
master
|
||||
good_bmark
|
||||
bad_bmark1:non-fast-forward
|
||||
branches/bad_branch:non-fast-forward
|
||||
EOF
|
||||
)
|
||||
) &&
|
||||
|
||||
check gitrepo origin/master one &&
|
||||
check gitrepo hg/origin/bookmarks/master one
|
||||
'
|
||||
|
||||
test_expect_success 'remote big push force' '
|
||||
@@ -682,6 +678,8 @@ test_expect_success 'remote big push force' '
|
||||
EOF
|
||||
) &&
|
||||
|
||||
check gitrepo origin/master two &&
|
||||
check gitrepo hg/origin/bookmarks/master two &&
|
||||
check_branch hgrepo default four &&
|
||||
check_branch hgrepo good_branch eight &&
|
||||
check_branch hgrepo bad_branch nine &&
|
||||
@@ -701,11 +699,6 @@ test_expect_success 'remote big push dry-run' '
|
||||
cd gitrepo &&
|
||||
|
||||
check_push 1 --dry-run --all <<-\EOF &&
|
||||
master
|
||||
good_bmark
|
||||
branches/good_branch
|
||||
new_bmark:new
|
||||
branches/new_branch:new
|
||||
bad_bmark1:non-fast-forward
|
||||
bad_bmark2:non-fast-forward
|
||||
branches/bad_branch:non-fast-forward
|
||||
@@ -720,6 +713,8 @@ test_expect_success 'remote big push dry-run' '
|
||||
EOF
|
||||
) &&
|
||||
|
||||
check gitrepo origin/master one &&
|
||||
check gitrepo hg/origin/bookmarks/master one &&
|
||||
check_branch hgrepo default one &&
|
||||
check_branch hgrepo good_branch "good branch" &&
|
||||
check_branch hgrepo bad_branch "bad branch" &&
|
||||
@@ -750,6 +745,8 @@ test_expect_success 'remote big push force dry-run' '
|
||||
EOF
|
||||
) &&
|
||||
|
||||
check gitrepo origin/master one &&
|
||||
check gitrepo hg/origin/bookmarks/master one &&
|
||||
check_branch hgrepo default one &&
|
||||
check_branch hgrepo good_branch "good branch" &&
|
||||
check_branch hgrepo bad_branch "bad branch" &&
|
||||
|
||||
Reference in New Issue
Block a user