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>
This commit is contained in:
parent
e3751a1763
commit
c9eaef125b
@ -29,9 +29,6 @@ import urlparse, hashlib
|
|||||||
# named branches:
|
# named branches:
|
||||||
# git config --global remote-hg.track-branches false
|
# git config --global remote-hg.track-branches false
|
||||||
#
|
#
|
||||||
# If you don't want to force pushes (and thus risk creating new remote heads):
|
|
||||||
# git config --global remote-hg.force-push false
|
|
||||||
#
|
|
||||||
# If you want the equivalent of hg's clone/pull--insecure option:
|
# If you want the equivalent of hg's clone/pull--insecure option:
|
||||||
# git config --global remote-hg.insecure true
|
# git config --global remote-hg.insecure true
|
||||||
#
|
#
|
||||||
@ -877,9 +874,6 @@ def write_tag(repo, tag, node, msg, author):
|
|||||||
return (tagnode, branch)
|
return (tagnode, branch)
|
||||||
|
|
||||||
def checkheads_bmark(repo, ref, ctx):
|
def checkheads_bmark(repo, ref, ctx):
|
||||||
if force_push:
|
|
||||||
return True
|
|
||||||
|
|
||||||
bmark = ref[len('refs/heads/'):]
|
bmark = ref[len('refs/heads/'):]
|
||||||
if not bmark in bmarks:
|
if not bmark in bmarks:
|
||||||
# new bmark
|
# new bmark
|
||||||
@ -888,8 +882,11 @@ def checkheads_bmark(repo, ref, ctx):
|
|||||||
ctx_old = bmarks[bmark]
|
ctx_old = bmarks[bmark]
|
||||||
ctx_new = ctx
|
ctx_new = ctx
|
||||||
if not repo.changelog.descendant(ctx_old.rev(), ctx_new.rev()):
|
if not repo.changelog.descendant(ctx_old.rev(), ctx_new.rev()):
|
||||||
print "error %s non-fast forward" % ref
|
if force_push:
|
||||||
return False
|
print "ok %s forced update" % ref
|
||||||
|
else:
|
||||||
|
print "error %s non-fast forward" % ref
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -936,8 +933,12 @@ def checkheads(repo, remote, p_revs):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
node = repo.changelog.node(rev)
|
node = repo.changelog.node(rev)
|
||||||
print "error %s non-fast forward" % p_revs[node]
|
ref = p_revs[node]
|
||||||
ret = False
|
if force_push:
|
||||||
|
print "ok %s forced update" % ref
|
||||||
|
else:
|
||||||
|
print "error %s non-fast forward" % ref
|
||||||
|
ret = False
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@ -949,7 +950,7 @@ def push_unsafe(repo, remote, parsed_refs, p_revs):
|
|||||||
commoninc = fci(repo, remote, force=force)
|
commoninc = fci(repo, remote, force=force)
|
||||||
common, _, remoteheads = commoninc
|
common, _, remoteheads = commoninc
|
||||||
|
|
||||||
if not force and not checkheads(repo, remote, p_revs):
|
if not checkheads(repo, remote, p_revs):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
cg = repo.getbundle('push', heads=list(p_revs), common=common)
|
cg = repo.getbundle('push', heads=list(p_revs), common=common)
|
||||||
@ -1110,11 +1111,14 @@ def do_export(parser):
|
|||||||
print
|
print
|
||||||
|
|
||||||
def do_option(parser):
|
def do_option(parser):
|
||||||
global dry_run
|
global dry_run, force_push
|
||||||
_, key, value = parser.line.split(' ')
|
_, key, value = parser.line.split(' ')
|
||||||
if key == 'dry-run':
|
if key == 'dry-run':
|
||||||
dry_run = (value == 'true')
|
dry_run = (value == 'true')
|
||||||
print 'ok'
|
print 'ok'
|
||||||
|
elif key == 'force':
|
||||||
|
force_push = (value == 'true')
|
||||||
|
print 'ok'
|
||||||
else:
|
else:
|
||||||
print 'unsupported'
|
print 'unsupported'
|
||||||
|
|
||||||
@ -1142,7 +1146,7 @@ def main(args):
|
|||||||
|
|
||||||
hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
|
hg_git_compat = get_config_bool('remote-hg.hg-git-compat')
|
||||||
track_branches = get_config_bool('remote-hg.track-branches', True)
|
track_branches = get_config_bool('remote-hg.track-branches', True)
|
||||||
force_push = get_config_bool('remote-hg.force-push')
|
force_push = False
|
||||||
|
|
||||||
if hg_git_compat:
|
if hg_git_compat:
|
||||||
mode = 'hg'
|
mode = 'hg'
|
||||||
|
@ -68,6 +68,9 @@ check_push () {
|
|||||||
'fetch-first')
|
'fetch-first')
|
||||||
grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
|
grep "^ ! \[rejected\] *${branch} -> ${branch} (fetch first)$" error || ref_ret=1
|
||||||
;;
|
;;
|
||||||
|
'forced-update')
|
||||||
|
grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *${branch} -> ${branch} (forced update)$" error || ref_ret=1
|
||||||
|
;;
|
||||||
'')
|
'')
|
||||||
grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
|
grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1
|
||||||
;;
|
;;
|
||||||
@ -594,6 +597,36 @@ test_expect_success 'remote big push fetch first' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'remote big push force' '
|
||||||
|
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
||||||
|
|
||||||
|
setup_big_push
|
||||||
|
|
||||||
|
(
|
||||||
|
cd gitrepo &&
|
||||||
|
|
||||||
|
check_push 0 --force --all <<-EOF
|
||||||
|
master
|
||||||
|
good_bmark
|
||||||
|
branches/good_branch
|
||||||
|
new_bmark:new
|
||||||
|
branches/new_branch:new
|
||||||
|
bad_bmark1:forced-update
|
||||||
|
bad_bmark2:forced-update
|
||||||
|
branches/bad_branch:forced-update
|
||||||
|
EOF
|
||||||
|
) &&
|
||||||
|
|
||||||
|
check_branch hgrepo default six &&
|
||||||
|
check_branch hgrepo good_branch eight &&
|
||||||
|
check_branch hgrepo bad_branch nine &&
|
||||||
|
check_branch hgrepo new_branch ten &&
|
||||||
|
check_bookmark hgrepo good_bmark three &&
|
||||||
|
check_bookmark hgrepo bad_bmark1 four &&
|
||||||
|
check_bookmark hgrepo bad_bmark2 five &&
|
||||||
|
check_bookmark hgrepo new_bmark six
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_failure 'remote big push dry-run' '
|
test_expect_failure 'remote big push dry-run' '
|
||||||
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user