From: Junio C Hamano Date: Wed, 20 Jan 2010 22:41:48 +0000 (-0800) Subject: Merge branch 'mh/rebase-fixup' (early part) X-Git-Tag: v1.7.0-rc0~70 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/cc6b41cc7d38c1b2de9809c0995087a2378d27ec?hp=-c Merge branch 'mh/rebase-fixup' (early part) * 'mh/rebase-fixup' (early part): rebase-i: Ignore comments and blank lines in peek_next_command lib-rebase: Allow comments and blank lines to be added to the rebase script lib-rebase: Provide clearer debugging info about what the editor did Add a command "fixup" to rebase --interactive t3404: Use test_commit to set up test repository --- cc6b41cc7d38c1b2de9809c0995087a2378d27ec diff --combined git-rebase--interactive.sh index 1560e84bd5,55c451ade4..d0b59c96c4 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@@ -302,7 -302,10 +302,10 @@@ nth_string () make_squash_message () { if test -f "$SQUASH_MSG"; then - COUNT=$(($(sed -n "s/^# This is [^0-9]*\([1-9][0-9]*\).*/\1/p" \ + # We want to be careful about matching only the commit + # message comment lines generated by this function. + # "[snrt][tdh]" matches the nth_string endings. + COUNT=$(($(sed -n "s/^# Th[^0-9]*\([1-9][0-9]*\)[snrt][tdh] commit message.*:/\1/p" \ < "$SQUASH_MSG" | sed -ne '$p')+1)) echo "# This is a combination of $COUNT commits." sed -e 1d -e '2,/^./{ @@@ -315,10 -318,23 +318,23 @@@ echo git cat-file commit HEAD | sed -e '1,/^$/d' fi - echo - echo "# This is the $(nth_string $COUNT) commit message:" - echo - git cat-file commit $1 | sed -e '1,/^$/d' + case $1 in + squash) + echo + echo "# This is the $(nth_string $COUNT) commit message:" + echo + git cat-file commit $2 | sed -e '1,/^$/d' + ;; + fixup) + echo + echo "# The $(nth_string $COUNT) commit message will be skipped:" + echo + # Comment the lines of the commit message out using + # "# " rather than "# " to make them less likely to + # confuse the sed regexp above. + git cat-file commit $2 | sed -e '1,/^$/d' -e 's/^/# /' + ;; + esac } peek_next_command () { @@@ -367,20 -383,28 +383,28 @@@ do_next () warn exit 0 ;; - squash|s) - comment_for_reflog squash + squash|s|fixup|f) + case "$command" in + squash|s) + squash_style=squash + ;; + fixup|f) + squash_style=fixup + ;; + esac + comment_for_reflog $squash_style test -f "$DONE" && has_action "$DONE" || - die "Cannot 'squash' without a previous commit" + die "Cannot '$squash_style' without a previous commit" mark_action_done - make_squash_message $sha1 > "$MSG" + make_squash_message $squash_style $sha1 > "$MSG" failed=f author_script=$(get_author_ident_from_commit HEAD) output git reset --soft HEAD^ pick_one -n $sha1 || failed=t case "$(peek_next_command)" in - squash|s) + squash|s|fixup|f) USE_OUTPUT=output MSG_OPT=-F EDIT_OR_FILE="$MSG" @@@ -495,25 -519,6 +519,25 @@@ get_saved_options () test -f "$DOTEST"/rebase-root && REBASE_ROOT=t } +LF=' +' +parse_onto () { + case "$1" in + *...*) + if left=${1%...*} right=${1#*...} && + onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD}) + then + case "$onto" in + ?*"$LF"?* | '') + exit 1 ;; + esac + echo "$onto" + exit 0 + fi + esac + git rev-parse --verify "$1^0" +} + while test $# != 0 do case "$1" in @@@ -621,7 -626,7 +645,7 @@@ first and then run 'git rebase --contin ;; --onto) shift - ONTO=$(git rev-parse --verify "$1") || + ONTO=$(parse_onto "$1") || die "Does not point to a valid commit: $1" ;; --) @@@ -787,6 -792,7 +811,7 @@@ # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit + # f, fixup = like "squash", but discard this commit's log message # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. @@@ -798,7 -804,7 +823,7 @@@ EO cp "$TODO" "$TODO".backup git_editor "$TODO" || - die "Could not execute editor" + die_abort "Could not execute editor" has_action "$TODO" || die_abort "Nothing to do"