git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v1] annotate: skip checking working tree if a revision is provided

From
Edmundo Carmona Antoranz <eantoranz@gmail.com>
Date
Nov 18, 2015, 01:20 UTC
Message-ID
<1447809609-17556-1-git-send-email-eantoranz@gmail.com>

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
Next: Edmundo Carmona Antoranz
Message 1 of 3 in “annotate: skip checking working tree if a revision is provided”
  1. annotate: skip checking working tree if a revision is providedEdmundo Carmona Antoranz, Nov 18, 2015
  2. Edmundo Carmona AntoranzNov 21, 2015
  3. Edmundo Carmona AntoranzNov 21, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.