git-send-pack: fix --all option when used with directory

When using git send-pack with --all option and a target repository specification ([<host>:]<directory>), usage message is being displayed instead of performing the actual transmission. The reason for this issue is that destination and refspecs are being set in the same conditional and are populated from argv. When a target repository is passed, refspecs is being populated as well with its value. This makes the check for refspecs not being NULL to always return true, which, in conjunction with the check for --all or --mirror options, is always true as well and returns usage message instead of proceeding. This ensures that send-pack will stop execution only when --all or --mirror switch is used in conjunction with any refspecs passed. Signed-off-by: Stanislav Kolotinskiy <stanislav@assembla.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stanislav Kolotinskiy committed Mar 31, 2016 at 16:55 UTC c6777563cd2b3e1d1989732c3daf05a72fddb068
2 files changed +13 -1
builtin/send-pack.c
+1 -1
@@ -225,7 +225,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
225 * --all and --mirror are incompatible; neither makes sense
226 * with any refspecs.
227 */
228 - if ((refspecs && (send_all || args.send_mirror)) ||
228 + if ((nr_refspecs > 0 && (send_all || args.send_mirror)) ||
229 (send_all && args.send_mirror))
230 usage_with_options(send_pack_usage, options);
231
t/t5400-send-pack.sh
+12
@@ -128,6 +128,18 @@ test_expect_success 'denyNonFastforwards trumps --force' '
128 test "$victim_orig" = "$victim_head"
129 '
130
131 +test_expect_success 'send-pack --all sends all branches' '
132 + # make sure we have at least 2 branches with different
133 + # values, just to be thorough
134 + git branch other-branch HEAD^ &&
135 +
136 + git init --bare all.git &&
137 + git send-pack --all all.git &&
138 + git for-each-ref refs/heads >expect &&
139 + git -C all.git for-each-ref refs/heads >actual &&
140 + test_cmp expect actual
141 +'
142 +
143 test_expect_success 'push --all excludes remote-tracking hierarchy' '
144 mkdir parent &&
145 (