git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Edmundo Carmona Antoranz <eantoranz@gmail.com>
To: git@vger.kernel.org
Cc: sunshine@sunshineco.com, peff@peff.net,
	Edmundo Carmona Antoranz <eantoranz@gmail.com>
Subject: [PATCH v1] annotate: skip checking working tree if a revision is provided
Date: Tue, 17 Nov 2015 19:20:09 -0600	[thread overview]
Message-ID: <1447809609-17556-1-git-send-email-eantoranz@gmail.com> (raw)

If a file has been deleted/renamed, annotate refuses to work
because the file does not exist on the working tree anymore
(even if the path provided does match a blob on said revision).

Signed-off-by: Edmundo Carmona Antoranz <eantoranz@gmail.com>
---
 builtin/blame.c     |  5 +++--
 t/annotate-tests.sh | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 83612f5..856971a 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2683,12 +2683,13 @@ parse_done:
 		argv[argc - 1] = "--";
 
 		setup_work_tree();
-		if (!file_exists(path))
-			die_errno("cannot stat path '%s'", path);
 	}
 
 	revs.disable_stdin = 1;
 	setup_revisions(argc, argv, &revs, NULL);
+	if (!revs.pending.nr && !file_exists(path))
+		die_errno("cannot stat path '%s'", path);
+
 	memset(&sb, 0, sizeof(sb));
 
 	sb.revs = &revs;
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index b1673b3..c99ec41 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -567,3 +567,23 @@ test_expect_success 'blame -L X,-N (non-numeric N)' '
 test_expect_success 'blame -L ,^/RE/' '
 	test_must_fail $PROG -L1,^/99/ file
 '
+
+test_expect_success 'annotate deleted file' '
+	echo hello world > hello_world.txt &&
+	git add hello_world.txt &&
+	git commit -m "step 1" &&
+	git rm hello_world.txt &&
+	git commit -m "step 2" &&
+	git annotate hello_world.txt HEAD~1 &&
+	test_must_fail git annotate hello_world.txt
+'
+
+test_expect_success 'annotate moved file' '
+	echo hello world > hello_world.txt &&
+	git add hello_world.txt &&
+	git commit -m "step 1" &&
+	git mv hello_world.txt not_there_anymore.txt &&
+	git commit -m "step 2" &&
+	git annotate hello_world.txt HEAD~1 &&
+	test_must_fail git annotate hello_world.txt
+'
-- 
2.6.2

             reply	other threads:[~2015-11-18  1:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-18  1:20 Edmundo Carmona Antoranz [this message]
2015-11-21  1:25 ` [PATCH v1] annotate: skip checking working tree if a revision is provided Edmundo Carmona Antoranz
2015-11-21  1:40   ` Edmundo Carmona Antoranz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447809609-17556-1-git-send-email-eantoranz@gmail.com \
    --to=eantoranz@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).