Skip to content

Commit

Permalink
Merge branch 'jk/filter-branch-come-back-to-original'
Browse files Browse the repository at this point in the history
When used with "-d temporary-directory" option, "git filter-branch"
failed to come back to the original working tree to perform the
final clean-up procedure.

* jk/filter-branch-come-back-to-original:
  filter-branch: return to original dir after filtering
  • Loading branch information
Junio C Hamano committed Apr 7, 2013
2 parents 9e7673e + 9727601 commit 9a11f13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions git-filter-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,15 @@ t)
test -d "$tempdir" &&
die "$tempdir already exists, please remove it"
esac
orig_dir=$(pwd)
mkdir -p "$tempdir/t" &&
tempdir="$(cd "$tempdir"; pwd)" &&
cd "$tempdir/t" &&
workdir="$(pwd)" ||
die ""

# Remove tempdir on exit
trap 'cd ../..; rm -rf "$tempdir"' 0
trap 'cd "$orig_dir"; rm -rf "$tempdir"' 0

ORIG_GIT_DIR="$GIT_DIR"
ORIG_GIT_WORK_TREE="$GIT_WORK_TREE"
Expand Down Expand Up @@ -469,7 +470,7 @@ if [ "$filter_tag_name" ]; then
done
fi

cd ../..
cd "$orig_dir"
rm -rf "$tempdir"

trap - 0
Expand Down
14 changes: 14 additions & 0 deletions t/t7003-filter-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ test_expect_success 'correct GIT_DIR while using -d' '
grep drepo "$TRASHDIR/backup-refs"
'

test_expect_success 'tree-filter works with -d' '
git init drepo-tree &&
(
cd drepo-tree &&
test_commit one &&
git filter-branch -d "$TRASHDIR/dfoo" \
--tree-filter "echo changed >one.t" &&
echo changed >expect &&
git cat-file blob HEAD:one.t >actual &&
test_cmp expect actual &&
test_cmp one.t actual
)
'

test_expect_success 'Fail if commit filter fails' '
test_must_fail git filter-branch -f --commit-filter "exit 1" HEAD
'
Expand Down

0 comments on commit 9a11f13

Please sign in to comment.