Skip to contentSkip to conversation

filter-branch.sh: remove temporary directory on failure

PATCH In review Brandon Casey 3 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 filter-branch.sh: remove temporary directory on failure

From: Brandon Casey <[email protected]>

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.

---

Even though this directory may be useful for debugging when you encounter a problem, I wonder if the normal "error" will be _user_ error. In which case the user will adjust the command line parameters and try to rerun. Currently the user would then receive the message

"$tempdir already exists, please remove it"

Then, rm -rf the tempdir, then rerun.

Is this necessary? Maybe anyone with the know-how to debug would also have the know-how to comment out the 'trap' in the script (or direct someone asking for help on the mailing list to do so).

If we really want to leave this temporary directory around on failure, maybe we can at least remove it for some simple errors like:

line 198: die "Namespace $orig_namespace not empty" line 217: die "Which ref do you want to rewrite?" etc.

by moving the 'trap - 0' higher up.

-brandon

 git-filter-branch.sh |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
git-filter-branch.sh +5 -0
index ebf05ca..75970a9 100755
@@ -189,6 +189,9 @@ cd "$tempdir/t" &&
 workdir="$(pwd)" ||
 die ""
 
+# Remove tempdir on exit
+trap 'cd ../..; rm -rf "$tempdir"' 0
+
 # Make sure refs/original is empty
 git for-each-ref > "$tempdir"/backup-refs
 while read sha1 type name
@@ -406,6 +409,8 @@ fi
 cd ../..
 rm -rf "$tempdir"
 
+trap - 0
+
 unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
 test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
 test -z "$ORIG_GIT_WORK_TREE" || GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
Signature · 1 line
1.5.4.rc5.2.g9a6d-dirty
#1 lore raw
Quoted 5 lines · Brandon Casey

Even though this directory may be useful for debugging when you encounter a problem, I wonder if the normal "error" will be _user_ error. In which case the user will adjust the command line parameters and try to rerun. Currently the user would then receive the message

Quoted 7 lines

"$tempdir already exists, please remove it"

Then, rm -rf the tempdir, then rerun.

Is this necessary? Maybe anyone with the know-how to debug would also have the know-how to comment out the 'trap' in the script (or direct someone asking for help on the mailing list to do so).

Makes sense to me. Dscho?

#2 lore raw

Hi,

Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Brandon Casey

Even though this directory may be useful for debugging when you encounter a problem, I wonder if the normal "error" will be _user_ error. In which case the user will adjust the command line parameters and try to rerun. Currently the user would then receive the message

"$tempdir already exists, please remove it"

Quoted 7 lines
Quoted 5 lines

Then, rm -rf the tempdir, then rerun.

Is this necessary? Maybe anyone with the know-how to debug would also have the know-how to comment out the 'trap' in the script (or direct someone asking for help on the mailing list to do so).

Makes sense to me. Dscho?

To me, too.

Thanks,
Dscho