remote-hg: add support for --force

And get rid of the remote-hg.force-push option hack. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed May 24, 2013 at 21:30 UTC c9eaef125bbecd60a8b328d58e66306d5db1357a
2 files changed +50 -13
contrib/remote-helpers/git-remote-hg
+17 -13
@@ -29,9 +29,6 @@ import urlparse, hashlib
29 # named branches:
30 # git config --global remote-hg.track-branches false
31 #
32 -# If you don't want to force pushes (and thus risk creating new remote heads):
33 -# git config --global remote-hg.force-push false
34 -#
32 # If you want the equivalent of hg's clone/pull--insecure option:
33 # git config --global remote-hg.insecure true
34 #
@@ -877,9 +874,6 @@ def write_tag(repo, tag, node, msg, author):
874 return (tagnode, branch)
875
876 def checkheads_bmark(repo, ref, ctx):
880 - if force_push:
881 - return True
882 -
877 bmark = ref[len('refs/heads/'):]
878 if not bmark in bmarks:
879 # new bmark
@@ -888,8 +882,11 @@ def checkheads_bmark(repo, ref, ctx):
882 ctx_old = bmarks[bmark]
883 ctx_new = ctx
884 if not repo.changelog.descendant(ctx_old.rev(), ctx_new.rev()):
891 - print "error %s non-fast forward" % ref
892 - return False
885 + if force_push:
886 + print "ok %s forced update" % ref
887 + else:
888 + print "error %s non-fast forward" % ref
889 + return False
890
891 return True
892
@@ -936,8 +933,12 @@ def checkheads(repo, remote, p_revs):
933 continue
934
935 node = repo.changelog.node(rev)
939 - print "error %s non-fast forward" % p_revs[node]
940 - ret = False
936 + ref = p_revs[node]
937 + if force_push:
938 + print "ok %s forced update" % ref
939 + else:
940 + print "error %s non-fast forward" % ref
941 + ret = False
942
943 return ret
944
@@ -949,7 +950,7 @@ def push_unsafe(repo, remote, parsed_refs, p_revs):
950 commoninc = fci(repo, remote, force=force)
951 common, _, remoteheads = commoninc
952
952 - if not force and not checkheads(repo, remote, p_revs):
953 + if not checkheads(repo, remote, p_revs):
954 return None
955
956 cg = repo.getbundle('push', heads=list(p_revs), common=common)
@@ -1110,11 +1111,14 @@ def do_export(parser):
1111 print
1112
1113 def do_option(parser):
1113 - global dry_run
1114 + global dry_run, force_push
1115 _, key, value = parser.line.split(' ')
1116 if key == 'dry-run':
1117 dry_run = (value == 'true')
1118 print 'ok'
1119 + elif key == 'force':
1120 + force_push = (value == 'true')
1121 + print 'ok'
1122 else:
1123 print 'unsupported'
1124
@@ -1142,7 +1146,7 @@ def main(args):
1146
1147 hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
1148 track_branches = get_config_bool('remote-hg.track-branches', True)
1145 - force_push = get_config_bool('remote-hg.force-push')
1149 + force_push = False
1150
1151 if hg_git_compat:
1152 mode = 'hg'
contrib/remote-helpers/test-hg.sh
+33
@@ -68,6 +68,9 @@ check_push () {
68 'fetch-first')
69 grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
70 ;;
71 + 'forced-update')
72 + grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
73 + ;;
74 '')
75 grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
76 ;;
@@ -594,6 +597,36 @@ test_expect_success 'remote big push fetch first' '
597 )
598 '
599
600 +test_expect_failure 'remote big push force' '
601 + test_when_finished "rm -rf hgrepo gitrepo*" &&
602 +
603 + setup_big_push
604 +
605 + (
606 + cd gitrepo &&
607 +
608 + check_push 0 --force --all <<-EOF
609 + master
610 + good_bmark
611 + branches/good_branch
612 + new_bmark:new
613 + branches/new_branch:new
614 + bad_bmark1:forced-update
615 + bad_bmark2:forced-update
616 + branches/bad_branch:forced-update
617 + EOF
618 + ) &&
619 +
620 + check_branch hgrepo default six &&
621 + check_branch hgrepo good_branch eight &&
622 + check_branch hgrepo bad_branch nine &&
623 + check_branch hgrepo new_branch ten &&
624 + check_bookmark hgrepo good_bmark three &&
625 + check_bookmark hgrepo bad_bmark1 four &&
626 + check_bookmark hgrepo bad_bmark2 five &&
627 + check_bookmark hgrepo new_bmark six
628 +'
629 +
630 test_expect_failure 'remote big push dry-run' '
631 test_when_finished "rm -rf hgrepo gitrepo*" &&
632