transport-helper: add 'force' to 'export' helpers
Otherwise they cannot know when to force the push or not (other than hacks). Tests-by: Richard Hansen <rhansen@bbn.com> Documentation-by: Richard Hansen <rhansen@bbn.com> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Nov 12, 2013 at 14:56 UTC
510fa6f5188d715050899eee221c739f1c0a8b12
4 files changed
+40
Documentation/gitremote-helpers.txt
+4
@@ -437,6 +437,10 @@ set by Git if the remote helper has the 'option' capability.
437
'option check-connectivity' \{'true'|'false'\}::
438
Request the helper to check connectivity of a clone.
439
440
+'option force' \{'true'|'false'\}::
441
+ Request the helper to perform a force update. Defaults to
442
+ 'false'.
443
+
444
SEE ALSO
445
--------
446
linkgit:git-remote[1]
git-remote-testgit.sh
+18
@@ -15,6 +15,8 @@ test -z "$refspec" && prefix="refs"
15
16
export GIT_DIR="$url/.git"
17
18
+force=
19
+
20
mkdir -p "$dir"
21
22
if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
@@ -39,6 +41,7 @@ do
41
fi
42
test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
43
test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
44
+ echo 'option'
45
echo
46
;;
47
list)
@@ -93,6 +96,7 @@ do
96
before=$(git for-each-ref --format=' %(refname) %(objectname) ')
97
98
git fast-import \
99
+ ${force:+--force} \
100
${testgitmarks:+"--import-marks=$testgitmarks"} \
101
${testgitmarks:+"--export-marks=$testgitmarks"} \
102
--quiet
@@ -115,6 +119,20 @@ do
119
120
echo
121
;;
122
+ option\ *)
123
+ read cmd opt val <<-EOF
124
+ $line
125
+ EOF
126
+ case $opt in
127
+ force)
128
+ test $val = "true" && force="true" || force=
129
+ echo "ok"
130
+ ;;
131
+ *)
132
+ echo "unsupported"
133
+ ;;
134
+ esac
135
+ ;;
136
'')
137
exit
138
;;
t/t5801-remote-helpers.sh
+13
@@ -94,6 +94,19 @@ test_expect_failure 'push new branch with old:new refspec' '
94
compare_refs local HEAD server refs/heads/new-refspec
95
'
96
97
+test_expect_success 'forced push' '
98
+ (cd local &&
99
+ git checkout -b force-test &&
100
+ echo content >> file &&
101
+ git commit -a -m eight &&
102
+ git push origin force-test &&
103
+ echo content >> file &&
104
+ git commit -a --amend -m eight-modified &&
105
+ git push --force origin force-test
106
+ ) &&
107
+ compare_refs local refs/heads/force-test server refs/heads/force-test
108
+'
109
+
110
test_expect_success 'cloning without refspec' '
111
GIT_REMOTE_TESTGIT_REFSPEC="" \
112
git clone "testgit::${PWD}/server" local2 2>error &&
transport-helper.c
+5
@@ -854,6 +854,11 @@ static int push_refs_with_export(struct transport *transport,
854
die("helper %s does not support dry-run", data->name);
855
}
856
857
+ if (flags & TRANSPORT_PUSH_FORCE) {
858
+ if (set_helper_option(transport, "force", "true") != 0)
859
+ warning("helper %s does not support 'force'", data->name);
860
+ }
861
+
862
helper = get_helper(transport);
863
864
write_constant(helper->in, "export\n");