Code

make deleting a missing ref more quiet
authorJeff King <peff@peff.net>
Tue, 8 Jul 2008 04:08:02 +0000 (00:08 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Jul 2008 20:05:11 +0000 (13:05 -0700)
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>
builtin-send-pack.c
refs.c
t/t5404-tracking-branches.sh

index d76260c09eef064d8a2862b5d6f0e826d968d643..a708d0af48e210fd4439c336c2faa3e7400b5fa4 100644 (file)
@@ -226,8 +226,7 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref)
                if (args.verbose)
                        fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
                if (ref->deletion) {
-                       if (delete_ref(rs.dst, NULL))
-                               error("Failed to delete");
+                       delete_ref(rs.dst, NULL);
                } else
                        update_ref("update by push", rs.dst,
                                        ref->new_sha1, NULL, 0, 0);
diff --git a/refs.c b/refs.c
index 9e8e8581ba981ca88366b614f1e8749cfe8a6ae5..c9bcf148b0e1cd659e645e0f793fc07ebc133426 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -925,7 +925,7 @@ int delete_ref(const char *refname, const unsigned char *sha1)
                i = strlen(lock->lk->filename) - 5; /* .lock */
                lock->lk->filename[i] = 0;
                err = unlink(lock->lk->filename);
-               if (err) {
+               if (err && errno != ENOENT) {
                        ret = 1;
                        error("unlink(%s) failed: %s",
                              lock->lk->filename, strerror(errno));
index 1493a92c06d041e502bcc08a1cee95e6758f1775..64fe2615acbd3368536b8a79c0b707561b3e16bd 100755 (executable)
@@ -10,6 +10,7 @@ test_expect_success 'setup' '
        git commit -m 1 &&
        git branch b1 &&
        git branch b2 &&
+       git branch b3 &&
        git clone . aa &&
        git checkout b1 &&
        echo b1 >>file &&
@@ -50,4 +51,10 @@ test_expect_success 'deleted branches have their tracking branches removed' '
        test "$(git rev-parse origin/b1)" = "origin/b1"
 '
 
+test_expect_success 'already deleted tracking branches ignored' '
+       git branch -d -r origin/b3 &&
+       git push origin :b3 >output 2>&1 &&
+       ! grep error output
+'
+
 test_done