@matheusbsbs / matheus-bagliano / commits / af580e9c5a
Fork 0

filter-branch: get rid of "set -e"

It was reported by Alex Riesen that "set -e" can break something as trivial as "unset CDPATH" in bash. So get rid of "set -e". Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 18, 2007 at 14:17 UTC af580e9c5afcffe7020e6f955f5136ee4220834f
1 file changed +17 -14
git-filter-branch.sh
+17 -14
@@ -8,8 +8,6 @@
8 # a new branch. You can specify a number of filters to modify the commits,
9 # files and trees.
10
11 -set -e
12 -
11 USAGE="git-filter-branch [-d TEMPDIR] [FILTERS] DESTBRANCH [REV-RANGE]"
12 . git-sh-setup
13
@@ -141,9 +139,10 @@ git show-ref "refs/heads/$dstbranch" 2> /dev/null &&
139 die "branch $dstbranch already exists"
140
141 test ! -e "$tempdir" || die "$tempdir already exists, please remove it"
144 -mkdir -p "$tempdir/t"
145 -cd "$tempdir/t"
146 -workdir="$(pwd)"
142 +mkdir -p "$tempdir/t" &&
143 +cd "$tempdir/t" &&
144 +workdir="$(pwd)" ||
145 +die ""
146
147 case "$GIT_DIR" in
148 /*)
@@ -155,12 +154,12 @@ esac
154 export GIT_DIR GIT_WORK_TREE=.
155
156 export GIT_INDEX_FILE="$(pwd)/../index"
158 -git read-tree # seed the index file
157 +git read-tree || die "Could not seed the index"
158
159 ret=0
160
162 -
163 -mkdir ../map # map old->new commit ids for rewriting parents
161 +# map old->new commit ids for rewriting parents
162 +mkdir ../map || die "Could not create map/ directory"
163
164 case "$filter_subdir" in
165 "")
@@ -170,7 +169,7 @@ case "$filter_subdir" in
169 *)
170 git rev-list --reverse --topo-order --default HEAD \
171 --parents --full-history "$@" -- "$filter_subdir"
173 -esac > ../revs
172 +esac > ../revs || die "Could not get the commits"
173 commits=$(wc -l <../revs | tr -d " ")
174
175 test $commits -eq 0 && die "Found nothing to rewrite"
@@ -186,10 +185,11 @@ while read commit parents; do
185 ;;
186 *)
187 git read-tree -i -m $commit:"$filter_subdir"
189 - esac
188 + esac || die "Could not initialize the index"
189
190 export GIT_COMMIT=$commit
192 - git cat-file commit "$commit" >../commit
191 + git cat-file commit "$commit" >../commit ||
192 + die "Cannot read commit $commit"
193
194 eval "$(set_ident AUTHOR <../commit)" ||
195 die "setting author failed for commit $commit"
@@ -199,7 +199,8 @@ while read commit parents; do
199 die "env filter failed: $filter_env"
200
201 if [ "$filter_tree" ]; then
202 - git checkout-index -f -u -a
202 + git checkout-index -f -u -a ||
203 + die "Could not checkout the index"
204 # files that $commit removed are now still in the working tree;
205 # remove them, else they would be added again
206 git ls-files -z --others | xargs -0 rm -f
@@ -240,7 +241,8 @@ case "$target_head" in
241 echo Nothing rewritten
242 ;;
243 *)
243 - git update-ref refs/heads/"$dstbranch" $target_head
244 + git update-ref refs/heads/"$dstbranch" $target_head ||
245 + die "Could not update $dstbranch with $target_head"
246 if [ $(wc -l <../map/$src_head) -gt 1 ]; then
247 echo "WARNING: Your commit filter caused the head commit to expand to several rewritten commits. Only the first such commit was recorded as the current $dstbranch head but you will need to resolve the situation now (probably by manually merging the other commits). These are all the commits:" >&2
248 sed 's/^/ /' ../map/$src_head >&2
@@ -277,7 +279,8 @@ if [ "$filter_tag_name" ]; then
279 warn "unreferencing tag object $sha1t"
280 fi
281
280 - git update-ref "refs/tags/$new_ref" "$new_sha1"
282 + git update-ref "refs/tags/$new_ref" "$new_sha1" ||
283 + die "Could not write tag $new_ref"
284 done
285 fi
286