{"thread":{"id":"17821","subject":"[PATCH] filter-branch -d: Export GIT_DIR earlier","startedAt":"2009-02-16T13:09:51Z","lastAt":"2009-02-17T08:17:28Z","messageCount":5,"participants":["Lars Noschinski","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"104942","messageId":"20090216130951.GA3769@lars.home.noschinski.de","threadId":"17821","inReplyTo":null,"subject":"[PATCH] filter-branch -d: Export GIT_DIR earlier","fromName":"Lars Noschinski","fromEmail":"lars@public.noschinski.de","sentAt":"2009-02-16T13:09:51Z","receivedAt":"2009-02-16T13:09:51Z","isPatch":true,"sender":{"key":"lars@public.noschinski.de","avatar":"https://gravatar.com/avatar/ca62bd8b265f2e26c89d39a4bfe7e390bfa6b16d6400e186e222d1c2382c66f2?d=mp&s=160"},"body":"The improved error handling catches a bug in filter-branch when using\n-d pointing to a path outside any git repository:\n\n$ mkdir foo\n$ cd foo\n$ git init\n$ touch bar\n$ git add bar\n$ git commit -m bar\n$ cd ..\n$ git clone --bare foo\n$ cd foo.git\n$ git filter-branch -d /tmp/filter master\nfatal: Not a git repository (or any of the parent directories): .git\n\nThis error message comes from git for-each-ref in line 224. GIT_DIR is\nset correctly by git-sh-setup (to the foo.git repository), but not\nexported (yet).\n---\n\nThis fix is not yet ready for commit, as it lacks a test case.\n\nWriting a test case for this bug, I wonder about the preferred way to use a\ndirectory outside any git repository in a test: Using some directory below\ngit/t/ will not work, as (in most cases) git is a git repository.\n\nUsing the system's temp directory via mktemp() or so directory would work most\nof the time - but not always. Any ideas?\n\n  - Lars.\n\n  git-filter-branch.sh |   12 ++++++------\n  1 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 27b57b8..9a09ba1 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -220,6 +220,12 @@ die \"\"\n  # Remove tempdir on exit\n  trap 'cd ../..; rm -rf \"$tempdir\"' 0\n  \n+ORIG_GIT_DIR=\"$GIT_DIR\"\n+ORIG_GIT_WORK_TREE=\"$GIT_WORK_TREE\"\n+ORIG_GIT_INDEX_FILE=\"$GIT_INDEX_FILE\"\n+GIT_WORK_TREE=.\n+export GIT_DIR GIT_WORK_TREE\n+\n  # Make sure refs/original is empty\n  git for-each-ref > \"$tempdir\"/backup-refs || exit\n  while read sha1 type name\n@@ -234,12 +240,6 @@ do\n  \tesac\n  done < \"$tempdir\"/backup-refs\n  \n-ORIG_GIT_DIR=\"$GIT_DIR\"\n-ORIG_GIT_WORK_TREE=\"$GIT_WORK_TREE\"\n-ORIG_GIT_INDEX_FILE=\"$GIT_INDEX_FILE\"\n-GIT_WORK_TREE=.\n-export GIT_DIR GIT_WORK_TREE\n-\n  # The refs should be updated if their heads were rewritten\n  git rev-parse --no-flags --revs-only --symbolic-full-name \\\n  \t--default HEAD \"$@\" > \"$tempdir\"/raw-heads || exit\n-- \n1.6.2.rc0.90.g0753.dirty\n"},{"id":"104943","messageId":"alpine.DEB.1.00.0902161441190.6289@intel-tinevez-2-302","threadId":"17821","inReplyTo":"20090216130951.GA3769@lars.home.noschinski.de","subject":"Re: [PATCH] filter-branch -d: Export GIT_DIR earlier","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-16T13:42:23Z","receivedAt":"2009-02-16T13:42:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 16 Feb 2009, Lars Noschinski wrote:\n\n> The improved error handling catches a bug in filter-branch when using\n> -d pointing to a path outside any git repository:\n> \n> $ mkdir foo\n> $ cd foo\n> $ git init\n> $ touch bar\n> $ git add bar\n> $ git commit -m bar\n> $ cd ..\n> $ git clone --bare foo\n> $ cd foo.git\n> $ git filter-branch -d /tmp/filter master\n> fatal: Not a git repository (or any of the parent directories): .git\n> \n> This error message comes from git for-each-ref in line 224. GIT_DIR is\n> set correctly by git-sh-setup (to the foo.git repository), but not\n> exported (yet).\n\nThanks.\n\n> ---\n> \n> This fix is not yet ready for commit, as it lacks a test case.\n> \n> Writing a test case for this bug, I wonder about the preferred way to use a\n> directory outside any git repository in a test: Using some directory below\n> git/t/ will not work, as (in most cases) git is a git repository.\n\nHow about using a filter-branch call with a filter that echoes GIT_DIR \ninto a file, then fails, and then checking the exact contents of GIT_DIR?\n\nCiao,\nDscho\n"},{"id":"104953","messageId":"20090216145137.GA4431@lars.home.noschinski.de","threadId":"17821","inReplyTo":"alpine.DEB.1.00.0902161441190.6289@intel-tinevez-2-302","subject":"Re: [PATCH] filter-branch -d: Export GIT_DIR earlier","fromName":"Lars Noschinski","fromEmail":"lars@public.noschinski.de","sentAt":"2009-02-16T14:51:37Z","receivedAt":"2009-02-16T14:51:37Z","isPatch":true,"sender":{"key":"lars@public.noschinski.de","avatar":"https://gravatar.com/avatar/ca62bd8b265f2e26c89d39a4bfe7e390bfa6b16d6400e186e222d1c2382c66f2?d=mp&s=160"},"body":"Hello,\n\n* Johannes Schindelin <Johannes.Schindelin@gmx.de> [09-02-16 15:42]:\n>> This fix is not yet ready for commit, as it lacks a test case.\n>> \n>> Writing a test case for this bug, I wonder about the preferred way to use a\n>> directory outside any git repository in a test: Using some directory below\n>> git/t/ will not work, as (in most cases) git is a git repository.\n>\n>How about using a filter-branch call with a filter that echoes GIT_DIR \n>into a file, then fails, and then checking the exact contents of GIT_DIR?\n\nThis would not catch this bug: for-each-ref is the only git command\ncalled after changing to the temporary directory and before exporting\nGIT_DIR.\n\nIt would help only if GIT_DIR would never be exported.\n\n - Lars.\n"},{"id":"104958","messageId":"alpine.DEB.1.00.0902161636040.6289@intel-tinevez-2-302","threadId":"17821","inReplyTo":"20090216145137.GA4431@lars.home.noschinski.de","subject":"Re: [PATCH] filter-branch -d: Export GIT_DIR earlier","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-02-16T15:39:13Z","receivedAt":"2009-02-16T15:39:13Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 16 Feb 2009, Lars Noschinski wrote:\n\n> * Johannes Schindelin <Johannes.Schindelin@gmx.de> [09-02-16 15:42]:\n> > > This fix is not yet ready for commit, as it lacks a test case.\n> > > \n> > > Writing a test case for this bug, I wonder about the preferred way to use\n> > > a\n> > > directory outside any git repository in a test: Using some directory below\n> > > git/t/ will not work, as (in most cases) git is a git repository.\n> >\n> >How about using a filter-branch call with a filter that echoes GIT_DIR into a\n> >file, then fails, and then checking the exact contents of GIT_DIR?\n> \n> This would not catch this bug: for-each-ref is the only git command\n> called after changing to the temporary directory and before exporting\n> GIT_DIR.\n\nRight.\n\nNext try: is it not true that we can check that \"$tempdir/backup-refs\" \nis correct, i.e. identical to what 'for-each-ref' outputs for the desired \ndirectory?\n\nSo we could make a subdirectory, set up a dummy branch with one commit, \ncall filter-branch with a tmpdir that is in _another_ subdirectory, with a \nfilter that just returns false, so that the tmpdir is not deleted, and \nverify the contents of $tmpdir/backup-refs, no?\n\nCiao,\nDscho\n"},{"id":"105093","messageId":"20090217081728.GA3893@lars.home.noschinski.de","threadId":"17821","inReplyTo":"alpine.DEB.1.00.0902161636040.6289@intel-tinevez-2-302","subject":"Re: [PATCH] filter-branch -d: Export GIT_DIR earlier","fromName":"Lars Noschinski","fromEmail":"lars@public.noschinski.de","sentAt":"2009-02-17T08:17:28Z","receivedAt":"2009-02-17T08:17:28Z","isPatch":true,"sender":{"key":"lars@public.noschinski.de","avatar":"https://gravatar.com/avatar/ca62bd8b265f2e26c89d39a4bfe7e390bfa6b16d6400e186e222d1c2382c66f2?d=mp&s=160"},"body":"* Johannes Schindelin <Johannes.Schindelin@gmx.de> [09-02-16 18:52]:\n>Hi,\n>\n>On Mon, 16 Feb 2009, Lars Noschinski wrote:\n>\n>> * Johannes Schindelin <Johannes.Schindelin@gmx.de> [09-02-16 15:42]:\n>> > > This fix is not yet ready for commit, as it lacks a test case.\n>> > > \n>> > > Writing a test case for this bug, I wonder about the preferred way to use\n>> > > a\n>> > > directory outside any git repository in a test: Using some directory below\n>> > > git/t/ will not work, as (in most cases) git is a git repository.\n[...]\n>Next try: is it not true that we can check that \"$tempdir/backup-refs\" \n>is correct, i.e. identical to what 'for-each-ref' outputs for the desired \n>directory?\n\nTrue.\n\n>So we could make a subdirectory, set up a dummy branch with one commit, \n>call filter-branch with a tmpdir that is in _another_ subdirectory, with a \n>filter that just returns false, so that the tmpdir is not deleted, and \n>verify the contents of $tmpdir/backup-refs, no?\n\nAFAICS $tmpdir is always deleted, filter-branch sets a trap to ensure\nthis. But using a filter to copy backup-refs elsewhere works. Patch\nfollows.\n\n  - Lars.\n"}]}