Skip to content

Commit 7756ecf

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 5c5d059 commit 7756ecf

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

git-rebase--interactive.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ has_action () {
203203
sane_grep '^[^#]' "$1" >/dev/null
204204
}
205205

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+
206215
pick_one () {
207216
no_ff=
208217
case "$1" in -n) sha1=$2; no_ff=t ;; *) sha1=$1 ;; esac
@@ -324,11 +333,8 @@ pick_one_preserving_merges () {
324333
msg="$(commit_message $sha1)"
325334
# No point in merging the first parent, that's HEAD
326335
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
332338
then
333339
printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
334340
die_with_patch $sha1 "Error redoing merge $sha1"
@@ -470,11 +476,9 @@ do_next () {
470476
if test $failed = f
471477
then
472478
# 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
478482
fi
479483
if test $failed = t
480484
then
@@ -605,8 +609,7 @@ first and then run 'git rebase --continue' again."
605609
git reset --soft HEAD^ ||
606610
die "Cannot rewind the HEAD"
607611
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 || {
610613
test -n "$amend" && git reset --soft $amend
611614
die "Could not commit staged changes."
612615
}

0 commit comments

Comments
 (0)