Skip to content

Commit 0b294c0

Browse files
peffgitster
authored andcommitted
make deleting a missing ref more quiet
If git attempts to delete a ref, but the unlink of the ref file fails, we print a message to stderr. This is usually a good thing, but if the error is ENOENT, then it indicates that the ref has _already_ been deleted. And since that's our goal, it doesn't make sense to complain to the user. This harmonizes the error reporting behavior for the unpacked and packed cases; the packed case already printed nothing on ENOENT, but the unpacked printed unconditionally. Additionally, send-pack would, when deleting the tracking ref corresponding to a remote delete, print "Failed to delete" on any failure. This can be a misleading message, since we actually _did_ delete at the remote side, but we failed to delete locally. Rather than make the message more precise, let's just eliminate it entirely; the delete_ref routine already takes care of printing out a much more specific message about what went wrong. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30161e7 commit 0b294c0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

builtin-send-pack.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
226226
if (args.verbose)
227227
fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
228228
if (ref->deletion) {
229-
if (delete_ref(rs.dst, NULL))
230-
error("Failed to delete");
229+
delete_ref(rs.dst, NULL);
231230
} else
232231
update_ref("update by push", rs.dst,
233232
ref->new_sha1, NULL, 0, 0);

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ int delete_ref(const char *refname, const unsigned char *sha1)
925925
i = strlen(lock->lk->filename) - 5; /* .lock */
926926
lock->lk->filename[i] = 0;
927927
err = unlink(lock->lk->filename);
928-
if (err) {
928+
if (err && errno != ENOENT) {
929929
ret = 1;
930930
error("unlink(%s) failed: %s",
931931
lock->lk->filename, strerror(errno));

t/t5404-tracking-branches.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ test_expect_success 'setup' '
1010
git commit -m 1 &&
1111
git branch b1 &&
1212
git branch b2 &&
13+
git branch b3 &&
1314
git clone . aa &&
1415
git checkout b1 &&
1516
echo b1 >>file &&
@@ -50,4 +51,10 @@ test_expect_success 'deleted branches have their tracking branches removed' '
5051
test "$(git rev-parse origin/b1)" = "origin/b1"
5152
'
5253

54+
test_expect_success 'already deleted tracking branches ignored' '
55+
git branch -d -r origin/b3 &&
56+
git push origin :b3 >output 2>&1 &&
57+
! grep error output
58+
'
59+
5360
test_done

0 commit comments

Comments
 (0)