{"thread":{"id":"17537","subject":"[PATCH] filter-branch: Fix fatal error on bare repositories","startedAt":"2009-02-03T18:27:03Z","lastAt":"2009-02-04T07:47:24Z","messageCount":2,"participants":["Eric Kidd","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"103011","messageId":"1233685623-39501-1-git-send-email-git@randomhacks.net","threadId":"17537","inReplyTo":null,"subject":"[PATCH] filter-branch: Fix fatal error on bare repositories","fromName":"Eric Kidd","fromEmail":"git@randomhacks.net","sentAt":"2009-02-03T18:27:03Z","receivedAt":"2009-02-03T18:27:03Z","isPatch":true,"sender":{"key":"git@randomhacks.net","avatar":null},"body":"When git filter-branch is run on a bare repository, it prints out a fatal\nerror message:\n\n  $ git filter-branch branch\n  Rewrite 476c4839280c219c2317376b661d9d95c1727fc3 (9/9)\n  WARNING: Ref 'refs/heads/branch' is unchanged\n  fatal: This operation must be run in a work tree\n\nNote that this fatal error message doesn't prevent git filter-branch from\nexiting successfully. (Why doesn't git filter-branch actually exit with an\nerror when a shell command fails? I'm not sure why it was designed this\nway.)\n\nThis error message is caused by the following section of code at the end of\ngit-filter-branch.sh:\n\n  if [ \"$(is_bare_repository)\" = false ]; then\n          unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE\n          test -z \"$ORIG_GIT_DIR\" || {\n                  GIT_DIR=\"$ORIG_GIT_DIR\" && export GIT_DIR\n          }\n          ... elided ...\n          git read-tree -u -m HEAD\n  fi\n\nThe problem is the call to $(is_bare_repository), which is made before\nGIT_DIR and GIT_WORK_TREE are restored.  This call always returns \"false\",\neven when we're running in a bare repository.  But this means that we will\nattempt to call 'git read-tree' even in a bare repository, which will fail\nand print an error.\n\nThis patch modifies git-filter-branch.sh to restore the original\nenvironment variables before trying to call is_bare_repository.\n---\n git-filter-branch.sh     |   25 +++++++++++++------------\n t/t7003-filter-branch.sh |    4 +++-\n 2 files changed, 16 insertions(+), 13 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex eb62f71..b75d0ba 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -469,19 +469,20 @@ rm -rf \"$tempdir\"\n \n trap - 0\n \n+unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE\n+test -z \"$ORIG_GIT_DIR\" || {\n+\tGIT_DIR=\"$ORIG_GIT_DIR\" && export GIT_DIR\n+}\n+test -z \"$ORIG_GIT_WORK_TREE\" || {\n+\tGIT_WORK_TREE=\"$ORIG_GIT_WORK_TREE\" &&\n+\texport GIT_WORK_TREE\n+}\n+test -z \"$ORIG_GIT_INDEX_FILE\" || {\n+\tGIT_INDEX_FILE=\"$ORIG_GIT_INDEX_FILE\" &&\n+\texport GIT_INDEX_FILE\n+}\n+\n if [ \"$(is_bare_repository)\" = false ]; then\n-\tunset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE\n-\ttest -z \"$ORIG_GIT_DIR\" || {\n-\t\tGIT_DIR=\"$ORIG_GIT_DIR\" && export GIT_DIR\n-\t}\n-\ttest -z \"$ORIG_GIT_WORK_TREE\" || {\n-\t\tGIT_WORK_TREE=\"$ORIG_GIT_WORK_TREE\" &&\n-\t\texport GIT_WORK_TREE\n-\t}\n-\ttest -z \"$ORIG_GIT_INDEX_FILE\" || {\n-\t\tGIT_INDEX_FILE=\"$ORIG_GIT_INDEX_FILE\" &&\n-\t\texport GIT_INDEX_FILE\n-\t}\n \tgit read-tree -u -m HEAD\n fi\n \ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 8537bf9..cb04743 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -39,7 +39,9 @@ test_expect_success 'result is really identical' '\n '\n \n test_expect_success 'rewrite bare repository identically' '\n-\t(git config core.bare true && cd .git && git filter-branch branch)\n+\t(git config core.bare true && cd .git &&\n+\t git filter-branch branch > filter-output 2>&1 &&\n+\t! fgrep fatal filter-output)\n '\n git config core.bare false\n test_expect_success 'result is really identical' '\n-- \n1.6.1.2.253.ga34a.dirty\n"},{"id":"103077","messageId":"7vzlh23apf.fsf@gitster.siamese.dyndns.org","threadId":"17537","inReplyTo":"1233685623-39501-1-git-send-email-git@randomhacks.net","subject":"Re: [PATCH] filter-branch: Fix fatal error on bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-04T07:47:24Z","receivedAt":"2009-02-04T07:47:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, will apply.\n"}]}