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

[fixed PATCH] git-filter-branch.sh: Fix broken setting of GIT_DIR

From
David Kastrup <dak@gnu.org>
Date
Aug 10, 2007, 16:21 UTC
Message-ID
<864pj74ay9.fsf@lola.quinscape.zz>
In-Reply-To
<868x8j7aj2.fsf@lola.quinscape.zz>

If filter-branch is entered with an unset GIT_DIR, things are rather fragile. The GIT_DIR variable setting then points to something like $(pwd)/../.. which is neither guaranteed to be a git directory (depends on where filter-branch is started), nor will it continue to work once the temporary directory (for which the pwd is output) ceases to exist.

So we just call git-rev-parse in order to get the correct setting here for exporting.

Signed-off-by: David Kastrup <dak@gnu.org>
---
 git-filter-branch.sh |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index b5fa449..9e9e8bf 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -170,14 +170,11 @@ do
 	esac
 done < "$tempdir"/backup-refs
 
-case "$GIT_DIR" in
-/*)
-	;;
-*)
-	GIT_DIR="$(pwd)/../../$GIT_DIR"
-	;;
-esac
-export GIT_DIR GIT_WORK_TREE=.
+GIT_DIR=$(cd ../..;cd "./$(git-rev-parse --git-dir)";pwd)
+
+GIT_WORK_TREE=.
+
+export GIT_DIR GIT_WORK_TREE
 
 # These refs should be updated if their heads were rewritten
 
-- 
1.5.3.rc4.74.g3739cb17
Previous: David KastrupNext: Junio C Hamano
Message 2 of 15 in “git-filter-branch.sh: Fix broken setting of GIT_DIR”
  1. git-filter-branch.sh: Fix broken setting of GIT_DIRDavid Kastrup, Aug 10, 2007
  2. git-filter-branch.sh: Fix broken setting of GIT_DIRDavid Kastrup, Aug 10, 2007
  3. Junio C HamanoAug 11, 2007
  4. David KastrupAug 11, 2007
  5. David KastrupAug 11, 2007
  6. David KastrupAug 11, 2007
  7. Junio C HamanoAug 11, 2007
  8. David KastrupAug 11, 2007
  9. Add a test for git-commit being confused by relative GIT_DIRDavid Kastrup, Aug 11, 2007
  10. Junio C HamanoAug 12, 2007
  11. David KastrupAug 12, 2007
  12. Junio C HamanoAug 12, 2007
  13. David KastrupAug 12, 2007
  14. Steven GrimmAug 11, 2007
  15. Junio C HamanoAug 11, 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.