@matheusbsbs / matheus-bagliano / commits / 0b294c0abf
Fork 0

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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 8, 2008 at 00:08 UTC 0b294c0abf00a9cf7468e0ea62722ae23b0816cc
3 files changed +9 -3
builtin-send-pack.c
+1 -2
@@ -226,8 +226,7 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
226 if (args.verbose)
227 fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
228 if (ref->deletion) {
229 - if (delete_ref(rs.dst, NULL))
230 - error("Failed to delete");
229 + delete_ref(rs.dst, NULL);
230 } else
231 update_ref("update by push", rs.dst,
232 ref->new_sha1, NULL, 0, 0);
refs.c
+1 -1
@@ -925,7 +925,7 @@ int delete_ref(const char *refname, const unsigned char *sha1)
925 i = strlen(lock->lk->filename) - 5; /* .lock */
926 lock->lk->filename[i] = 0;
927 err = unlink(lock->lk->filename);
928 - if (err) {
928 + if (err && errno != ENOENT) {
929 ret = 1;
930 error("unlink(%s) failed: %s",
931 lock->lk->filename, strerror(errno));
t/t5404-tracking-branches.sh
+7
@@ -10,6 +10,7 @@ test_expect_success 'setup' '
10 git commit -m 1 &&
11 git branch b1 &&
12 git branch b2 &&
13 + git branch b3 &&
14 git clone . aa &&
15 git checkout b1 &&
16 echo b1 >>file &&
@@ -50,4 +51,10 @@ test_expect_success 'deleted branches have their tracking branches removed' '
51 test "$(git rev-parse origin/b1)" = "origin/b1"
52 '
53
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 +
60 test_done