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

[PATCH] filter-branch: always export GIT_DIR if it is set

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Jun 5, 2007, 16:49 UTC
Message-ID
<20070605164957.GA12358@moooo.ath.cx>
In-Reply-To
<7vodjudei2.fsf@assigned-by-dhcp.cox.net>

Currently filter-branch exports GIT_DIR only if it is a relative path but git-sh-setup might also set GIT_DIR to an absolute path that is not exported yet. Additionally we need to export GIT_WORK_TREE with GIT_DIR to ensure that the current working directory is used as working tree even for bare repositories.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
> Hmph.
> 
> When this series is applied on top of 'next' (or whatever
> contains t7003-filter-branch.sh), this seems to break it quite
> badly.
With the GIT_WORK_TREE patch series a relative path in GIT_DIR is
expanded to an absolute path.  Therefore
    GIT_DIR=$(GIT_DIR=.git git rev-parse --git-dir)
in git-sh-setup will give the full path to the repository.
git-filter-branch exports GIT_DIR only if the path is relative.  In
consequence GIT_DIR was not set at all and the following git commands
failed.  Additionally GIT_WORK_TREE has to be exported because to make
sure that the current directory is used as working tree even for bare
repositories.

I merged the worktree branch to next and applied the patch, all tests passed.

This problem reveals a small change which might cause trouble with other
scripts.  I looked at the git repository and found no other script which
should have problems with this series.  With
    $ git grep -e export --and -e GIT_DIR
I found:
    Documentation/install-doc-quick.sh
    git-clone.sh
    git-instaweb.sh
        These do not need a working tree.
    git-cvsexportcommit.perl
        git apply is used with GIT_DIR='', this forces git-apply not to
        use the git repository.
I'm not sure if any other script out there tries to do this.  Perhaps we
should just keep the old behaviour and use the current directory as
working tree when the repository name ends in /.git even though
core.bare is true?
---
 git-filter-branch.sh |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 0c8a7df..f4cfbea 100644
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -313,9 +313,12 @@ workdir="$(pwd)"
 
 case "$GIT_DIR" in
 /*)
+	export GIT_DIR
+	export GIT_WORK_TREE=.
 	;;
 *)
 	export GIT_DIR="$(pwd)/../../$GIT_DIR"
+	export GIT_WORK_TREE=.
 	;;
 esac
 
-- 
1.5.2.1.120.g3877-dirty
Previous: Junio C HamanoNext: Johannes Schindelin
Message 8 of 22 in “[RFC] GIT_WORK_TREE”
  1. Matthias LederhoferJun 3, 2007
  2. 1/7 rev-parse: document --is-inside-git-dirMatthias Lederhofer, Jun 3, 2007
  3. 2/7 rev-parse: introduce --is-bare-repositoryMatthias Lederhofer, Jun 3, 2007
  4. 3/7 test git rev-parseMatthias Lederhofer, Jun 3, 2007
  5. 3/7 test git rev-parseMatthias Lederhofer, Jun 6, 2007
  6. 4/7 introduce GIT_WORK_TREE to specify the work treeMatthias Lederhofer, Jun 3, 2007
  7. Junio C HamanoJun 5, 2007
  8. filter-branch: always export GIT_DIR if it is setMatthias Lederhofer, Jun 5, 2007
  9. Johannes SchindelinJun 5, 2007
  10. Junio C HamanoJun 5, 2007
  11. filter-branch: always export GIT_DIR if it is setMatthias Lederhofer, Jun 6, 2007
  12. 4/7 introduce GIT_WORK_TREE to specify the work treeMatthias Lederhofer, Jun 6, 2007
  13. Matthias LederhoferJun 3, 2007
  14. Matthias LederhoferJun 3, 2007
  15. 6/7 extend rev-parse test for --is-inside-work-treeMatthias Lederhofer, Jun 3, 2007
  16. 6/7 extend rev-parse test for --is-inside-work-treeMatthias Lederhofer, Jun 6, 2007
  17. 7/7 test GIT_WORK_TREEMatthias Lederhofer, Jun 3, 2007
  18. 7/7 test GIT_WORK_TREEMatthias Lederhofer, Jun 6, 2007
  19. SergioJun 3, 2007
  20. Matthias LederhoferJun 3, 2007
  21. SergioJun 3, 2007
  22. setup_git_directory: fix segfault if repository is found in cwdMatthias Lederhofer, Jun 6, 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.