Skip to content

Commit def16e7

Browse files
drafnelgitster
authored andcommitted
filter-branch.sh: remove temporary directory on failure
One of the first things filter-branch does is to create a temporary directory. This directory is eventually removed by the script during normal operation, but is not removed if the script encounters an error. Set a trap to remove it when the script terminates for any reason. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0eab8ca commit def16e7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

git-filter-branch.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ cd "$tempdir/t" &&
189189
workdir="$(pwd)" ||
190190
die ""
191191

192+
# Remove tempdir on exit
193+
trap 'cd ../..; rm -rf "$tempdir"' 0
194+
192195
# Make sure refs/original is empty
193196
git for-each-ref > "$tempdir"/backup-refs
194197
while read sha1 type name
@@ -406,6 +409,8 @@ fi
406409
cd ../..
407410
rm -rf "$tempdir"
408411

412+
trap - 0
413+
409414
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
410415
test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
411416
test -z "$ORIG_GIT_WORK_TREE" || GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&

0 commit comments

Comments
 (0)