{"thread":{"id":"29622","subject":"[PATCH] filter-branch: cd to the correct directory when -d is used","startedAt":"2012-02-14T09:49:37Z","lastAt":"2012-02-14T09:49:37Z","messageCount":1,"participants":["Per Cederqvist"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"184648","messageId":"4F3A2E31.9040006@opera.com","threadId":"29622","inReplyTo":null,"subject":"[PATCH] filter-branch: cd to the correct directory when -d is used","fromName":"Per Cederqvist","fromEmail":"cederp@opera.com","sentAt":"2012-02-14T09:49:37Z","receivedAt":"2012-02-14T09:49:37Z","isPatch":true,"sender":{"key":"cederp@opera.com","avatar":"https://gravatar.com/avatar/008fe28caedea0ba34042cd5157705267934f4ba7a9b29fb248ae18ec5b3055e?d=mp&s=160"},"body":"git-filter-branch changes directory to $tempdir/t, which by default is\n.git-rewrite/t.  Before doing the read-tree to update the working tree\nit uses \"cd ../..\" to get back to the working tree.  This breaks if\nyou use something like \"-d /tmp/tempdir\", as the read-tree will be\nexecuted in /tmp instead of in your working tree.\n\nFixed by adding a variable that holds the original value of $(pwd),\nand cd back to that value.\n\nAdded tests that demonstrates some issues that can happen without this\nfix.\n\nSigned-off-by: Per Cederqvist <cederp@opera.com>\n---\n  git-filter-branch.sh     |    3 ++-\n  t/t7003-filter-branch.sh |   38 ++++++++++++++++++++++++++++++++++++++\n  2 files changed, 40 insertions(+), 1 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex add2c02..a58b50b 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -217,6 +217,7 @@ t)\n  \ttest -d \"$tempdir\" &&\n  \t\tdie \"$tempdir already exists, please remove it\"\n  esac\n+oldpwd=\"$(pwd)\"\n  mkdir -p \"$tempdir/t\" &&\n  tempdir=\"$(cd \"$tempdir\"; pwd)\" &&\n  cd \"$tempdir/t\" &&\n@@ -489,7 +490,7 @@ if [ \"$filter_tag_name\" ]; then\n  \tdone\n  fi\n\n-cd ../..\n+cd \"$oldpwd\"\n  rm -rf \"$tempdir\"\n\n  trap - 0\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex e022773..fa464a2 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -367,4 +367,42 @@ test_expect_success 'replace submodule revision' '\n  \ttest $orig_head != `git show-ref --hash --head HEAD`\n  '\n\n+test_expect_success 'get a fresh tree' '\n+\trm -fr ?* .git .gitmodules\n+'\n+\n+deep_tree() {\n+\ttest_expect_success 'setup deep tree' '\n+\t\trm -fr drepo &&\n+\t\tmkdir drepo &&\n+\t\t( cd drepo &&\n+\t\tgit init &&\n+\t\tmkdir kom++ &&\n+\t\ttest_commit authors kom++/AUTHORS \"Fake authors file\" &&\n+\t\ttest_commit changelog kom++/ChangeLog \"Fake ChangeLog file\"\n+\t\t)\n+\t'\n+\n+\ttest_expect_success '-d tempdir with --subdirectory-filter' '\n+\t\t(cd drepo &&\n+\t\tgit filter-branch -d \"$TRASHDIR/tmpdir\" --subdirectory-filter kom++ \n--tag-name-filter cat -- --all\n+\t\t)\n+\t'\n+\n+\ttest_expect_success 'content after -d with --subdirectory-filter' '\n+\t\ttest_path_is_missing AUTHORS \"AUTHORS created in tmpdir/..\"\n+\t\ttest_path_is_missing ChangeLog \"ChangeLog created in tmpdir/..\"\n+\t\ttest_path_is_missing drepo/kom++ \"kom++ remains\"\n+\t\ttest_path_is_file drepo/AUTHORS \"AUTHORS not moved to top-level\"\n+\t\ttest_path_is_file drepo/ChangeLog \"ChangeLog not moved to top-level\"\n+\t'\n+\n+\ttest_expect_success 'Clean workdir' '\n+\t\tcd drepo&&git diff --quiet\n+\t'\n+}\n+\n+deep_tree\n+deep_tree # In Git 1.7.9 and earlier filter-branch fails the second time.\n+\n  test_done\n-- \n1.7.9\n"}]}