All of lore.kernel.org
 help / color / mirror / Atom feed
From: Per Cederqvist <cederp@opera.com>
To: git@vger.kernel.org
Cc: cederp@opera.com, ceder@lysator.liu.se
Subject: [PATCH] filter-branch: cd to the correct directory when -d is used
Date: Tue, 14 Feb 2012 10:49:37 +0100	[thread overview]
Message-ID: <4F3A2E31.9040006@opera.com> (raw)

git-filter-branch changes directory to $tempdir/t, which by default is
.git-rewrite/t.  Before doing the read-tree to update the working tree
it uses "cd ../.." to get back to the working tree.  This breaks if
you use something like "-d /tmp/tempdir", as the read-tree will be
executed in /tmp instead of in your working tree.

Fixed by adding a variable that holds the original value of $(pwd),
and cd back to that value.

Added tests that demonstrates some issues that can happen without this
fix.

Signed-off-by: Per Cederqvist <cederp@opera.com>
---
  git-filter-branch.sh     |    3 ++-
  t/t7003-filter-branch.sh |   38 ++++++++++++++++++++++++++++++++++++++
  2 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index add2c02..a58b50b 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -217,6 +217,7 @@ t)
  	test -d "$tempdir" &&
  		die "$tempdir already exists, please remove it"
  esac
+oldpwd="$(pwd)"
  mkdir -p "$tempdir/t" &&
  tempdir="$(cd "$tempdir"; pwd)" &&
  cd "$tempdir/t" &&
@@ -489,7 +490,7 @@ if [ "$filter_tag_name" ]; then
  	done
  fi

-cd ../..
+cd "$oldpwd"
  rm -rf "$tempdir"

  trap - 0
diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
index e022773..fa464a2 100755
--- a/t/t7003-filter-branch.sh
+++ b/t/t7003-filter-branch.sh
@@ -367,4 +367,42 @@ test_expect_success 'replace submodule revision' '
  	test $orig_head != `git show-ref --hash --head HEAD`
  '

+test_expect_success 'get a fresh tree' '
+	rm -fr ?* .git .gitmodules
+'
+
+deep_tree() {
+	test_expect_success 'setup deep tree' '
+		rm -fr drepo &&
+		mkdir drepo &&
+		( cd drepo &&
+		git init &&
+		mkdir kom++ &&
+		test_commit authors kom++/AUTHORS "Fake authors file" &&
+		test_commit changelog kom++/ChangeLog "Fake ChangeLog file"
+		)
+	'
+
+	test_expect_success '-d tempdir with --subdirectory-filter' '
+		(cd drepo &&
+		git filter-branch -d "$TRASHDIR/tmpdir" --subdirectory-filter kom++ 
--tag-name-filter cat -- --all
+		)
+	'
+
+	test_expect_success 'content after -d with --subdirectory-filter' '
+		test_path_is_missing AUTHORS "AUTHORS created in tmpdir/.."
+		test_path_is_missing ChangeLog "ChangeLog created in tmpdir/.."
+		test_path_is_missing drepo/kom++ "kom++ remains"
+		test_path_is_file drepo/AUTHORS "AUTHORS not moved to top-level"
+		test_path_is_file drepo/ChangeLog "ChangeLog not moved to top-level"
+	'
+
+	test_expect_success 'Clean workdir' '
+		cd drepo&&git diff --quiet
+	'
+}
+
+deep_tree
+deep_tree # In Git 1.7.9 and earlier filter-branch fails the second time.
+
  test_done
-- 
1.7.9

                 reply	other threads:[~2012-02-14  9:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F3A2E31.9040006@opera.com \
    --to=cederp@opera.com \
    --cc=ceder@lysator.liu.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.