Skip to content

Commit c73d46b

Browse files
committed
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
2 parents 9210a00 + c9e04d9 commit c73d46b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

builtin/fetch.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,12 +1610,14 @@ static int do_fetch(struct transport *transport,
16101610
* don't care whether --tags was specified.
16111611
*/
16121612
if (rs->nr) {
1613-
prune_refs(rs, ref_map, transport->url);
1613+
retcode = prune_refs(rs, ref_map, transport->url);
16141614
} else {
1615-
prune_refs(&transport->remote->fetch,
1616-
ref_map,
1617-
transport->url);
1615+
retcode = prune_refs(&transport->remote->fetch,
1616+
ref_map,
1617+
transport->url);
16181618
}
1619+
if (retcode != 0)
1620+
retcode = 1;
16191621
}
16201622
if (fetch_and_consume_refs(transport, ref_map, worktrees)) {
16211623
free_refs(ref_map);

t/t5510-fetch.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ test_expect_success 'fetch --prune --tags with refspec prunes based on refspec'
164164
git rev-parse sometag
165165
'
166166

167+
test_expect_success REFFILES 'fetch --prune fails to delete branches' '
168+
cd "$D" &&
169+
git clone . prune-fail &&
170+
cd prune-fail &&
171+
git update-ref refs/remotes/origin/extrabranch main &&
172+
: this will prevent --prune from locking packed-refs for deleting refs, but adding loose refs still succeeds &&
173+
>.git/packed-refs.new &&
174+
175+
test_must_fail git fetch --prune origin
176+
'
177+
167178
test_expect_success 'fetch --atomic works with a single branch' '
168179
test_when_finished "rm -rf \"$D\"/atomic" &&
169180

0 commit comments

Comments
 (0)