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

Re: Bug in git-filter-branch example

From
Jeff King <peff@peff.net>
Date
Feb 1, 2010, 12:43 UTC
Message-ID
<20100201124345.GA32532@coredump.intra.peff.net>
In-Reply-To
<557ea2711002010348m57aa31fesd1047cbe3f01cb0b@mail.gmail.com>
On Mon, Feb 01, 2010 at 11:48:27AM +0000, Ivo Anjo wrote:
Show 10 quoted lines
>     To move the whole tree into a subdirectory, or remove it from there:
> 
>     git filter-branch --index-filter \
>             'git ls-files -s | sed "s-\t-&newsubdir/-" |
>                     GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
>                             git update-index --index-info &&
>              mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
> 
> 
> The problem is with filenames that use complex utf8 (non-ascii?) chars:

Yes, that is definitely the problem. update-index unquotes its input, as you would expect, but the sed munging does not take the quote into account. You can fix it by doing:

  sed "s-\t\"*-&newsubdir/-"

instead. Here is a patch to fix the documentation. I am slightly unsure of whether it should be applied. These examples are supposed to be simple and readable to help the user understand what the filters can do. And this makes it somewhat less simple for the sake of a special case. But at the same time, users are going to cut-and-paste these examples (I know I have), and the special case is not _that_ special, especially for non-English speakers. And having it in the example helps make people aware that quoted paths are a reality.

So I think on balance it is probably better to fix it.

Note also that another way of "fixing" this would be to set core.quotepath to false (which is something you probably want to do anyway if you are using utf8 characters in your filenames). And I put "fix" in quotes because you still may run across quoted paths, but they will be much less common; you will only see them if you have control characters or other insanity in your paths.

-- >8 --
Subject: [PATCH] docs: fix filter-branch example for quoted paths

If there is a quoted path, update-index will correctly unquote it. However, we must take care to put our new prefix inside the double-quote.

Signed-off-by: Jeff King <peff@peff.net>
---
 Documentation/git-filter-branch.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index cfaba2a..020028c 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -358,7 +358,7 @@ To move the whole tree into a subdirectory, or remove it from there:
 
 ---------------------------------------------------------------
 git filter-branch --index-filter \
-	'git ls-files -s | sed "s-\t-&newsubdir/-" |
+	'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
 		GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
 			git update-index --index-info &&
 	 mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
-- 
1.7.0.rc1.16.g21332.dirty
Previous: Ivo AnjoNext: Johannes Sixt
Message 2 of 3 in “Bug in git-filter-branch example”
  1. Ivo AnjoFeb 1, 2010
  2. Jeff KingFeb 1, 2010
  3. Johannes SixtFeb 1, 2010

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.