Merge branch 'fc/transport-helper-fixes'
Updates transport-helper, fast-import and fast-export to allow the ref mapping and ref deletion in a way similar to the natively supported transports. * fc/transport-helper-fixes: remote-bzr: support the new 'force' option test-hg.sh: tests are now expected to pass transport-helper.c: do not overwrite forced bit transport-helper: check for 'forced update' message transport-helper: add 'force' to 'export' helpers transport-helper: don't update refs in dry-run transport-helper: mismerge fix
This commit is contained in:
commit
90e6255a6d
@ -437,6 +437,10 @@ set by Git if the remote helper has the 'option' capability.
|
|||||||
'option check-connectivity' \{'true'|'false'\}::
|
'option check-connectivity' \{'true'|'false'\}::
|
||||||
Request the helper to check connectivity of a clone.
|
Request the helper to check connectivity of a clone.
|
||||||
|
|
||||||
|
'option force' \{'true'|'false'\}::
|
||||||
|
Request the helper to perform a force update. Defaults to
|
||||||
|
'false'.
|
||||||
|
|
||||||
'option cloning \{'true'|'false'\}::
|
'option cloning \{'true'|'false'\}::
|
||||||
Notify the helper this is a clone request (i.e. the current
|
Notify the helper this is a clone request (i.e. the current
|
||||||
repository is guaranteed empty).
|
repository is guaranteed empty).
|
||||||
|
@ -684,7 +684,8 @@ def do_export(parser):
|
|||||||
peer = bzrlib.branch.Branch.open(peers[name],
|
peer = bzrlib.branch.Branch.open(peers[name],
|
||||||
possible_transports=transports)
|
possible_transports=transports)
|
||||||
try:
|
try:
|
||||||
peer.bzrdir.push_branch(branch, revision_id=revid)
|
peer.bzrdir.push_branch(branch, revision_id=revid,
|
||||||
|
overwrite=force)
|
||||||
except bzrlib.errors.DivergedBranches:
|
except bzrlib.errors.DivergedBranches:
|
||||||
print "error %s non-fast forward" % ref
|
print "error %s non-fast forward" % ref
|
||||||
continue
|
continue
|
||||||
@ -718,8 +719,32 @@ def do_capabilities(parser):
|
|||||||
print "*import-marks %s" % path
|
print "*import-marks %s" % path
|
||||||
print "*export-marks %s" % path
|
print "*export-marks %s" % path
|
||||||
|
|
||||||
|
print "option"
|
||||||
print
|
print
|
||||||
|
|
||||||
|
class InvalidOptionValue(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_bool_option(val):
|
||||||
|
if val == 'true':
|
||||||
|
return True
|
||||||
|
elif val == 'false':
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
raise InvalidOptionValue()
|
||||||
|
|
||||||
|
def do_option(parser):
|
||||||
|
global force
|
||||||
|
opt, val = parser[1:3]
|
||||||
|
try:
|
||||||
|
if opt == 'force':
|
||||||
|
force = get_bool_option(val)
|
||||||
|
print 'ok'
|
||||||
|
else:
|
||||||
|
print 'unsupported'
|
||||||
|
except InvalidOptionValue:
|
||||||
|
print "error '%s' is not a valid value for option '%s'" % (val, opt)
|
||||||
|
|
||||||
def ref_is_valid(name):
|
def ref_is_valid(name):
|
||||||
return not True in [c in name for c in '~^: \\']
|
return not True in [c in name for c in '~^: \\']
|
||||||
|
|
||||||
@ -882,6 +907,7 @@ def main(args):
|
|||||||
global is_tmp
|
global is_tmp
|
||||||
global branches, peers
|
global branches, peers
|
||||||
global transports
|
global transports
|
||||||
|
global force
|
||||||
|
|
||||||
marks = None
|
marks = None
|
||||||
is_tmp = False
|
is_tmp = False
|
||||||
@ -904,6 +930,7 @@ def main(args):
|
|||||||
branches = {}
|
branches = {}
|
||||||
peers = {}
|
peers = {}
|
||||||
transports = []
|
transports = []
|
||||||
|
force = False
|
||||||
|
|
||||||
if alias[5:] == url:
|
if alias[5:] == url:
|
||||||
is_tmp = True
|
is_tmp = True
|
||||||
@ -936,6 +963,8 @@ def main(args):
|
|||||||
do_import(parser)
|
do_import(parser)
|
||||||
elif parser.check('export'):
|
elif parser.check('export'):
|
||||||
do_export(parser)
|
do_export(parser)
|
||||||
|
elif parser.check('option'):
|
||||||
|
do_option(parser)
|
||||||
else:
|
else:
|
||||||
die('unhandled command: %s' % line)
|
die('unhandled command: %s' % line)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
@ -66,13 +66,33 @@ test_expect_success 'pushing' '
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'forced pushing' '
|
||||||
|
(
|
||||||
|
cd gitrepo &&
|
||||||
|
echo three-new >content &&
|
||||||
|
git commit -a --amend -m three-new &&
|
||||||
|
git push -f
|
||||||
|
) &&
|
||||||
|
|
||||||
|
(
|
||||||
|
cd bzrrepo &&
|
||||||
|
# the forced update overwrites the bzr branch but not the bzr
|
||||||
|
# working directory (it tries to merge instead)
|
||||||
|
bzr revert
|
||||||
|
) &&
|
||||||
|
|
||||||
|
echo three-new >expected &&
|
||||||
|
cat bzrrepo/content >actual &&
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'roundtrip' '
|
test_expect_success 'roundtrip' '
|
||||||
(
|
(
|
||||||
cd gitrepo &&
|
cd gitrepo &&
|
||||||
git pull &&
|
git pull &&
|
||||||
git log --format="%s" -1 origin/master >actual
|
git log --format="%s" -1 origin/master >actual
|
||||||
) &&
|
) &&
|
||||||
echo three >expected &&
|
echo three-new >expected &&
|
||||||
test_cmp expected actual &&
|
test_cmp expected actual &&
|
||||||
|
|
||||||
(cd gitrepo && git push && git pull) &&
|
(cd gitrepo && git push && git pull) &&
|
||||||
|
@ -680,7 +680,7 @@ test_expect_success 'remote big push fetch first' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'remote big push force' '
|
test_expect_success 'remote big push force' '
|
||||||
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
||||||
|
|
||||||
setup_big_push
|
setup_big_push
|
||||||
@ -710,7 +710,7 @@ test_expect_failure 'remote big push force' '
|
|||||||
check_bookmark hgrepo new_bmark six
|
check_bookmark hgrepo new_bmark six
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_failure 'remote big push dry-run' '
|
test_expect_success 'remote big push dry-run' '
|
||||||
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
test_when_finished "rm -rf hgrepo gitrepo*" &&
|
||||||
|
|
||||||
setup_big_push
|
setup_big_push
|
||||||
|
@ -15,6 +15,8 @@ test -z "$refspec" && prefix="refs"
|
|||||||
|
|
||||||
export GIT_DIR="$url/.git"
|
export GIT_DIR="$url/.git"
|
||||||
|
|
||||||
|
force=
|
||||||
|
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
|
|
||||||
if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
|
if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
|
||||||
@ -39,6 +41,7 @@ do
|
|||||||
fi
|
fi
|
||||||
test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
|
test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
|
||||||
test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
|
test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
|
||||||
|
echo 'option'
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
list)
|
list)
|
||||||
@ -93,6 +96,7 @@ do
|
|||||||
before=$(git for-each-ref --format=' %(refname) %(objectname) ')
|
before=$(git for-each-ref --format=' %(refname) %(objectname) ')
|
||||||
|
|
||||||
git fast-import \
|
git fast-import \
|
||||||
|
${force:+--force} \
|
||||||
${testgitmarks:+"--import-marks=$testgitmarks"} \
|
${testgitmarks:+"--import-marks=$testgitmarks"} \
|
||||||
${testgitmarks:+"--export-marks=$testgitmarks"} \
|
${testgitmarks:+"--export-marks=$testgitmarks"} \
|
||||||
--quiet
|
--quiet
|
||||||
@ -115,6 +119,20 @@ do
|
|||||||
|
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
|
option\ *)
|
||||||
|
read cmd opt val <<-EOF
|
||||||
|
$line
|
||||||
|
EOF
|
||||||
|
case $opt in
|
||||||
|
force)
|
||||||
|
test $val = "true" && force="true" || force=
|
||||||
|
echo "ok"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "unsupported"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
'')
|
'')
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
|
@ -94,6 +94,19 @@ test_expect_failure 'push new branch with old:new refspec' '
|
|||||||
compare_refs local HEAD server refs/heads/new-refspec
|
compare_refs local HEAD server refs/heads/new-refspec
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'forced push' '
|
||||||
|
(cd local &&
|
||||||
|
git checkout -b force-test &&
|
||||||
|
echo content >> file &&
|
||||||
|
git commit -a -m eight &&
|
||||||
|
git push origin force-test &&
|
||||||
|
echo content >> file &&
|
||||||
|
git commit -a --amend -m eight-modified &&
|
||||||
|
git push --force origin force-test
|
||||||
|
) &&
|
||||||
|
compare_refs local refs/heads/force-test server refs/heads/force-test
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'cloning without refspec' '
|
test_expect_success 'cloning without refspec' '
|
||||||
GIT_REMOTE_TESTGIT_REFSPEC="" \
|
GIT_REMOTE_TESTGIT_REFSPEC="" \
|
||||||
git clone "testgit::${PWD}/server" local2 2>error &&
|
git clone "testgit::${PWD}/server" local2 2>error &&
|
||||||
|
@ -650,7 +650,7 @@ static int push_update_ref_status(struct strbuf *buf,
|
|||||||
struct ref *remote_refs)
|
struct ref *remote_refs)
|
||||||
{
|
{
|
||||||
char *refname, *msg;
|
char *refname, *msg;
|
||||||
int status;
|
int status, forced = 0;
|
||||||
|
|
||||||
if (starts_with(buf->buf, "ok ")) {
|
if (starts_with(buf->buf, "ok ")) {
|
||||||
status = REF_STATUS_OK;
|
status = REF_STATUS_OK;
|
||||||
@ -708,6 +708,11 @@ static int push_update_ref_status(struct strbuf *buf,
|
|||||||
free(msg);
|
free(msg);
|
||||||
msg = NULL;
|
msg = NULL;
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(msg, "forced update")) {
|
||||||
|
forced = 1;
|
||||||
|
free(msg);
|
||||||
|
msg = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ref)
|
if (*ref)
|
||||||
@ -729,12 +734,14 @@ static int push_update_ref_status(struct strbuf *buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
(*ref)->status = status;
|
(*ref)->status = status;
|
||||||
|
(*ref)->forced_update |= forced;
|
||||||
(*ref)->remote_status = msg;
|
(*ref)->remote_status = msg;
|
||||||
return !(status == REF_STATUS_OK);
|
return !(status == REF_STATUS_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void push_update_refs_status(struct helper_data *data,
|
static void push_update_refs_status(struct helper_data *data,
|
||||||
struct ref *remote_refs)
|
struct ref *remote_refs,
|
||||||
|
int flags)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct ref *ref = remote_refs;
|
struct ref *ref = remote_refs;
|
||||||
@ -748,7 +755,7 @@ static void push_update_refs_status(struct helper_data *data,
|
|||||||
if (push_update_ref_status(&buf, &ref, remote_refs))
|
if (push_update_ref_status(&buf, &ref, remote_refs))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!data->refspecs || data->no_private_update)
|
if (flags & TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* propagate back the update to the remote namespace */
|
/* propagate back the update to the remote namespace */
|
||||||
@ -839,7 +846,7 @@ static int push_refs_with_push(struct transport *transport,
|
|||||||
sendline(data, &buf);
|
sendline(data, &buf);
|
||||||
strbuf_release(&buf);
|
strbuf_release(&buf);
|
||||||
|
|
||||||
push_update_refs_status(data, remote_refs);
|
push_update_refs_status(data, remote_refs, flags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -860,6 +867,11 @@ static int push_refs_with_export(struct transport *transport,
|
|||||||
die("helper %s does not support dry-run", data->name);
|
die("helper %s does not support dry-run", data->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & TRANSPORT_PUSH_FORCE) {
|
||||||
|
if (set_helper_option(transport, "force", "true") != 0)
|
||||||
|
warning("helper %s does not support 'force'", data->name);
|
||||||
|
}
|
||||||
|
|
||||||
helper = get_helper(transport);
|
helper = get_helper(transport);
|
||||||
|
|
||||||
write_constant(helper->in, "export\n");
|
write_constant(helper->in, "export\n");
|
||||||
@ -881,9 +893,6 @@ static int push_refs_with_export(struct transport *transport,
|
|||||||
}
|
}
|
||||||
free(private);
|
free(private);
|
||||||
|
|
||||||
if (ref->deletion)
|
|
||||||
die("remote-helpers do not support ref deletion");
|
|
||||||
|
|
||||||
if (ref->peer_ref) {
|
if (ref->peer_ref) {
|
||||||
if (strcmp(ref->peer_ref->name, ref->name))
|
if (strcmp(ref->peer_ref->name, ref->name))
|
||||||
die("remote-helpers do not support old:new syntax");
|
die("remote-helpers do not support old:new syntax");
|
||||||
@ -896,7 +905,7 @@ static int push_refs_with_export(struct transport *transport,
|
|||||||
|
|
||||||
if (finish_command(&exporter))
|
if (finish_command(&exporter))
|
||||||
die("Error while running fast-export");
|
die("Error while running fast-export");
|
||||||
push_update_refs_status(data, remote_refs);
|
push_update_refs_status(data, remote_refs, flags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user