remote-bzr: support the new 'force' option

Signed-off-by: Richard Hansen <rhansen@bbn.com> Acked-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Richard Hansen committed Nov 12, 2013 at 02:03 UTC a7cb1276cc263446b19b43d3a7784cbc72f84e28
2 files changed +51 -2
contrib/remote-helpers/git-remote-bzr
+30 -1
@@ -685,7 +685,8 @@ def do_export(parser):
685 peer = bzrlib.branch.Branch.open(peers[name],
686 possible_transports=transports)
687 try:
688 - peer.bzrdir.push_branch(branch, revision_id=revid)
688 + peer.bzrdir.push_branch(branch, revision_id=revid,
689 + overwrite=force)
690 except bzrlib.errors.DivergedBranches:
691 print "error %s non-fast forward" % ref
692 continue
@@ -719,8 +720,32 @@ def do_capabilities(parser):
720 print "*import-marks %s" % path
721 print "*export-marks %s" % path
722
723 + print "option"
724 print
725
726 +class InvalidOptionValue(Exception):
727 + pass
728 +
729 +def get_bool_option(val):
730 + if val == 'true':
731 + return True
732 + elif val == 'false':
733 + return False
734 + else:
735 + raise InvalidOptionValue()
736 +
737 +def do_option(parser):
738 + global force
739 + opt, val = parser[1:3]
740 + try:
741 + if opt == 'force':
742 + force = get_bool_option(val)
743 + print 'ok'
744 + else:
745 + print 'unsupported'
746 + except InvalidOptionValue:
747 + print "error '%s' is not a valid value for option '%s'" % (val, opt)
748 +
749 def ref_is_valid(name):
750 return not True in [c in name for c in '~^: \\']
751
@@ -883,6 +908,7 @@ def main(args):
908 global is_tmp
909 global branches, peers
910 global transports
911 + global force
912
913 alias = args[1]
914 url = args[2]
@@ -896,6 +922,7 @@ def main(args):
922 branches = {}
923 peers = {}
924 transports = []
925 + force = False
926
927 if alias[5:] == url:
928 is_tmp = True
@@ -931,6 +958,8 @@ def main(args):
958 do_import(parser)
959 elif parser.check('export'):
960 do_export(parser)
961 + elif parser.check('option'):
962 + do_option(parser)
963 else:
964 die('unhandled command: %s' % line)
965 sys.stdout.flush()
contrib/remote-helpers/test-bzr.sh
+21 -1
@@ -65,13 +65,33 @@ test_expect_success 'pushing' '
65 test_cmp expected actual
66 '
67
68 +test_expect_success 'forced pushing' '
69 + (
70 + cd gitrepo &&
71 + echo three-new >content &&
72 + git commit -a --amend -m three-new &&
73 + git push -f
74 + ) &&
75 +
76 + (
77 + cd bzrrepo &&
78 + # the forced update overwrites the bzr branch but not the bzr
79 + # working directory (it tries to merge instead)
80 + bzr revert
81 + ) &&
82 +
83 + echo three-new >expected &&
84 + cat bzrrepo/content >actual &&
85 + test_cmp expected actual
86 +'
87 +
88 test_expect_success 'roundtrip' '
89 (
90 cd gitrepo &&
91 git pull &&
92 git log --format="%s" -1 origin/master >actual
93 ) &&
74 - echo three >expected &&
94 + echo three-new >expected &&
95 test_cmp expected actual &&
96
97 (cd gitrepo && git push && git pull) &&