rebase -i: Extract function do_with_author
Call it instead of repeating similar code blocks in several places. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jan 14, 2010 at 06:54 UTC
7756ecffe7d914fdbb42629a408d6da78b9794c1
1 file changed
+15
-12
git-rebase--interactive.sh
+15
-12
@@ -203,6 +203,15 @@ has_action () {
203
sane_grep '^[^#]' "$1" >/dev/null
204
}
205
206
+# Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
207
+# GIT_AUTHOR_DATE exported from the current environment.
208
+do_with_author () {
209
+ GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
210
+ GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
211
+ GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
212
+ "$@"
213
+}
214
+
215
pick_one () {
216
no_ff=
217
case "$1" in -n) sha1=$2; no_ff=t ;; *) sha1=$1 ;; esac
@@ -324,11 +333,8 @@ pick_one_preserving_merges () {
333
msg="$(commit_message $sha1)"
334
# No point in merging the first parent, that's HEAD
335
new_parents=${new_parents# $first_parent}
327
- if ! GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
328
- GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
329
- GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
330
- output git merge $STRATEGY -m "$msg" \
331
- $new_parents
336
+ if ! do_with_author output \
337
+ git merge $STRATEGY -m "$msg" $new_parents
338
then
339
printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
340
die_with_patch $sha1 "Error redoing merge $sha1"
@@ -470,11 +476,9 @@ do_next () {
476
if test $failed = f
477
then
478
# This is like --amend, but with a different message
473
- GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
474
- GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
475
- GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
476
- $USE_OUTPUT git commit --no-verify \
477
- $MSG_OPT "$EDIT_OR_FILE" || failed=t
479
+ do_with_author $USE_OUTPUT git commit --no-verify \
480
+ $MSG_OPT "$EDIT_OR_FILE" ||
481
+ failed=t
482
fi
483
if test $failed = t
484
then
@@ -605,8 +609,7 @@ first and then run 'git rebase --continue' again."
609
git reset --soft HEAD^ ||
610
die "Cannot rewind the HEAD"
611
fi
608
- export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE &&
609
- git commit --no-verify -F "$MSG" -e || {
612
+ do_with_author git commit --no-verify -F "$MSG" -e || {
613
test -n "$amend" && git reset --soft $amend
614
die "Could not commit staged changes."
615
}