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

[PATCH] filter-branch: when dwim'ing a ref, only allow heads and tags

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 24, 2007, 11:27 UTC
Message-ID
<Pine.LNX.4.64.0707241227140.14781@racer.site>
In-Reply-To
<Pine.LNX.4.64.0707241218270.14781@racer.site>

Previously, we matched all refs that had /$ref in them. And tried to verify the result as a ref. If more than one match was found, the result was not a ref, though.

So only allow tags and heads to be dwim'ed. If both a tag and a head with that name exist, it will be ignored again.

Caught by Johannes Sixt.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	Heh.  I just realised that I managed to fsck up a one-line patch.  
	D'oh!  Thanks for fixing it, Hannes.
 git-filter-branch.sh     |    2 +-
 t/t7003-filter-branch.sh |    5 +++++
 2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 0ff3475..4fb3abe 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -193,7 +193,7 @@ do
 	;;
 	*)
 		ref="$(git for-each-ref --format='%(refname)' |
-			grep /"$ref")"
+			grep -e "^refs/heads/$ref$" -e "^refs/tags/$ref$")"
 	esac
 
 	git check-ref-format "$ref" && echo "$ref"
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index bc6e2dd..c9a820d 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -159,4 +159,9 @@ test_expect_success 'barf on invalid name' '
 	! git filter-branch -f HEAD^
 '
 
+test_expect_success 'only dwim refs/heads/$ref or refs/tags/$ref' '
+	git update-ref refs/remotes/origin/master HEAD &&
+	git filter-branch -f master
+'
+
 test_done
-- 
1.5.3.rc2.32.g35c5b-dirty
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 8 of 20 in “filter-branch: Big syntax change; support rewriting multiple refs”
  1. filter-branch: Big syntax change; support rewriting multiple refsJohannes Schindelin, Jul 23, 2007
  2. Junio C HamanoJul 24, 2007
  3. Johannes SchindelinJul 24, 2007
  4. Johannes SixtJul 24, 2007
  5. filter-branch: when dwim'ing a ref, only allow heads and tagsJohannes Schindelin, Jul 24, 2007
  6. Johannes SixtJul 24, 2007
  7. Johannes SchindelinJul 24, 2007
  8. filter-branch: when dwim'ing a ref, only allow heads and tagsJohannes Schindelin, Jul 24, 2007
  9. filter-branch: rewrite only refs which were not excluded by the optionsJohannes Schindelin, Jul 24, 2007
  10. Johannes SixtJul 24, 2007
  11. Johannes SchindelinJul 24, 2007
  12. Johannes SixtJul 24, 2007
  13. Johannes SchindelinJul 24, 2007
  14. Johannes SixtJul 24, 2007
  15. Johannes SchindelinJul 24, 2007
  16. Johannes SixtJul 24, 2007
  17. Johannes SchindelinJul 24, 2007
  18. filter-branch: rewrite only unexcluded refsJohannes Schindelin, Jul 24, 2007
  19. Johannes SixtJul 24, 2007
  20. Johannes SchindelinJul 24, 2007

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.