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

[PATCH] filter-branch: consider refs/replace can refer to an object other than commit

From
Yuki Kokubun <orga.chem.job@gmail.com>
Date
Mar 21, 2018, 10:35 UTC
Message-ID
<20180321103504.9483-1-orga.chem.job@gmail.com>

"git filter-branch -- --all" can be confused when refs that refer to objects other than commits exists. Because "git rev-parse --all" that is internally used can return refs that refer to an object other than commit. But it is not considered in the phase of updating refs. Such refs can be created by "git replace" with objects other than commits.

Signed-off-by: Yuki Kokubun <orga.chem.job@gmail.com>
---
 git-filter-branch.sh     |  3 +++
 t/t7003-filter-branch.sh | 13 +++++++++++++
 2 files changed, 16 insertions(+)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 1b7e4b2cd..a9fafe64f 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -479,6 +479,9 @@ do
 	# avoid rewriting a ref twice
 	test -f "$orig_namespace$ref" && continue
 
+	# refs/replace can point to a non commit object
+	test $(git cat-file -t "$ref") = commit || continue
+
 	sha1=$(git rev-parse "$ref"^0)
 	rewritten=$(map $sha1)
 
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index 7cb60799b..efeaf5887 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -470,4 +470,17 @@ test_expect_success 'tree-filter deals with object name vs pathname ambiguity' '
 	git show HEAD:$ambiguous
 '
 
+test_expect_success 'rewrite repository including refs/replace that point to non commit object' '
+	test_when_finished "git reset --hard original" &&
+	tree=$(git rev-parse HEAD^{tree}) &&
+	test_when_finished "git replace -d $tree" &&
+	echo A >new &&
+	git add new &&
+	new_tree=$(git write-tree) &&
+	git replace $tree $new_tree &&
+	git reset --hard HEAD &&
+	git filter-branch -f -- --all >filter-output 2>&1 &&
+	! fgrep fatal filter-output
+'
+
 test_done
-- 
2.16.2.18.g09cb46d
Next: Yuki Kokubun
Message 1 of 20 in “filter-branch: consider refs/replace can refer to an object other than commit”
  1. filter-branch: consider refs/replace can refer to an object other than commitYuki Kokubun, Mar 21, 2018
  2. filter-branch: consider refs can refer to an object other than commit or tagYuki Kokubun, Mar 21, 2018
  3. Junio C HamanoMar 21, 2018
  4. Yuki KokubunMar 21, 2018
  5. Junio C HamanoMar 21, 2018
  6. Yuki KokubunMar 22, 2018
  7. Junio C HamanoMar 22, 2018
  8. Yuki KokubunMar 23, 2018
  9. filter-branch: fix errors caused by refs that cannot be used with ^0Yuki Kokubun, Mar 23, 2018
  10. Junio C HamanoMar 23, 2018
  11. Yuki KokubunMar 24, 2018
  12. filter-branch: fix errors caused by refs that point at non-committishYuki Kokubun, Mar 24, 2018
  13. Junio C HamanoMar 25, 2018
  14. Yuki KokubunMar 25, 2018
  15. Junio C HamanoMar 25, 2018
  16. filter-branch: fix errors caused by refs that point at non-committishYuki Kokubun, Mar 25, 2018
  17. Yuki KokubunMar 25, 2018
  18. Junio C HamanoApr 8, 2018
  19. filter-branch: fix errors caused by refs that point at non-committishYuki Kokubun, Mar 25, 2018
  20. Junio C HamanoMar 25, 2018

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.