diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-02-11 16:56:01 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-02-11 16:56:01 -0800 |
commit | c73d46b3a8450f499df84682be73a13b6578d82c (patch) | |
tree | dec704de951fc0d37cb5e4a5cea2cf41050766fa | |
parent | Merge branch 'en/sparse-checkout-leakfix' (diff) | |
parent | fetch --prune: exit with error if pruning fails (diff) | |
download | tgif-c73d46b3a8450f499df84682be73a13b6578d82c.tar.xz |
Merge branch 'tg/fetch-prune-exit-code-fix'
When "git fetch --prune" failed to prune the refs it wanted to
prune, the command issued error messages but exited with exit
status 0, which has been corrected.
* tg/fetch-prune-exit-code-fix:
fetch --prune: exit with error if pruning fails
-rw-r--r-- | builtin/fetch.c | 10 | ||||
-rwxr-xr-x | t/t5510-fetch.sh | 11 |
2 files changed, 17 insertions, 4 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index 55d2568b18..6f5e157863 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1610,12 +1610,14 @@ static int do_fetch(struct transport *transport, * don't care whether --tags was specified. */ if (rs->nr) { - prune_refs(rs, ref_map, transport->url); + retcode = prune_refs(rs, ref_map, transport->url); } else { - prune_refs(&transport->remote->fetch, - ref_map, - transport->url); + retcode = prune_refs(&transport->remote->fetch, + ref_map, + transport->url); } + if (retcode != 0) + retcode = 1; } if (fetch_and_consume_refs(transport, ref_map, worktrees)) { free_refs(ref_map); diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 20f7110ec1..ef0da0a63b 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -164,6 +164,17 @@ test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' git rev-parse sometag ' +test_expect_success REFFILES 'fetch --prune fails to delete branches' ' + cd "$D" && + git clone . prune-fail && + cd prune-fail && + git update-ref refs/remotes/origin/extrabranch main && + : this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds && + >.git/packed-refs.new && + + test_must_fail git fetch --prune origin +' + test_expect_success 'fetch --atomic works with a single branch' ' test_when_finished "rm -rf \"$D\"/atomic" && |