From: Fabian Ruch <bafain@gmail.com>
To: git@vger.kernel.org
Subject: [RFC PATCH 4/7] rebase -i: Commit only once when rewriting picks
Date: Thu, 19 Jun 2014 05:28:38 +0200 [thread overview]
Message-ID: <53A258E6.5050301@gmail.com> (raw)
In-Reply-To: <cover.1403146774.git.bafain@gmail.com>
The options passed to `do_pick` determine whether the picked commit will
be rewritten or not. If the commit gets rewritten, because the user
requested to edit the commit message for instance, let `pick_one` merely
apply the changes introduced by the commit and do not commit the
resulting tree yet. If the commit is replayed as is, leave it to
`pick_one` to recreate the commit (possibly by fast-forwarding the
head). This makes it easier to combine git-commit options like `--edit`
and `--amend` in `do_pick` because git-cherry-pick does not support
`--amend`.
In the case of `--edit`, do not `exit_with_patch` but assign `rewrite`
to pick the changes with `-n`. If the pick conflicts, no commit is
created which we would have to amend when continuing the rebase. To
complete the pick after the conflicts are resolved the user just resumes
with `git rebase --continue`.
If `rebase--interactive` is used to rebase a complete branch onto some
head, `rebase` creates a sentinel commit that requires special treatment
by `do_pick`. Do not finalize the pick here either because its commit
message can be altered as for any other pick. Since the orphaned root
commit gets a temporary parent, it is always rewritten. Safely use the
rewrite infrastructure of `do_pick` to create the final commit.
Signed-off-by: Fabian Ruch <bafain@gmail.com>
---
git-rebase--interactive.sh | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f09eeae..f903599 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -63,7 +63,8 @@ msgnum="$state_dir"/msgnum
author_script="$state_dir"/author-script
# When an "edit" rebase command is being processed, the SHA1 of the
-# commit to be edited is recorded in this file. When "git rebase
+# commit to be edited is recorded in this file. The same happens when
+# rewriting a commit fails, for instance "reword". When "git rebase
# --continue" is executed, if there are any staged changes then they
# will be amended to the HEAD commit, but only provided the HEAD
# commit is still the commit to be edited. When any other rebase
@@ -508,12 +509,15 @@ record_in_rewritten() {
# commit message. The editor contents becomes the commit message of
# the new head.
do_pick () {
- edit=
+ rewrite=
+ rewrite_amend=
+ rewrite_edit=
while test $# -gt 0
do
case "$1" in
-e|--edit)
- edit=y
+ rewrite=y
+ rewrite_edit=y
;;
-*)
warn "do_pick: ignored option -- $1"
@@ -528,6 +532,9 @@ do_pick () {
if test "$(git rev-parse HEAD)" = "$squash_onto"
then
+ rewrite=y
+ rewrite_amend=y
+ git rev-parse --verify HEAD >"$amend"
# Set the correct commit message and author info on the
# sentinel root before cherry-picking the original changes
# without committing (-n). Finally, update the sentinel again
@@ -538,22 +545,20 @@ do_pick () {
# rebase --continue.
git commit --allow-empty --allow-empty-message --amend \
--no-post-rewrite -n -q -C $1 &&
- pick_one -n $1 &&
- git commit --allow-empty --amend \
- --no-post-rewrite -n -q \
- ${gpg_sign_opt:+"$gpg_sign_opt"} ||
+ pick_one -n $1 ||
die_with_patch $1 "Could not apply $1... $2"
else
- pick_one $1 ||
+ pick_one ${rewrite:+-n} $1 ||
die_with_patch $1 "Could not apply $1... $2"
fi
- if test -n "$edit"
+ if test -n "$rewrite"
then
- git commit --allow-empty --amend --no-post-rewrite -n -q ${gpg_sign_opt:+"$gpg_sign_opt"} || {
- warn "Could not amend commit after successfully picking $1... $2"
- exit_with_patch $1 1
- }
+ git commit --allow-empty --no-post-rewrite -n -q \
+ ${rewrite_amend:+--amend} \
+ ${rewrite_edit:+--edit} \
+ ${gpg_sign_opt:+"$gpg_sign_opt"} ||
+ die_with_patch $1 "Could not rewrite commit after successfully picking $1... $2"
fi
}
--
2.0.0
next prev parent reply other threads:[~2014-06-19 3:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1403146774.git.bafain@gmail.com>
2014-06-19 3:28 ` [RFC PATCH 1/7] rebase -i: Make option handling in pick_one more flexible Fabian Ruch
2014-06-20 13:40 ` Michael Haggerty
2014-06-20 19:53 ` Junio C Hamano
2014-06-23 0:04 ` Fabian Ruch
2014-06-21 23:21 ` Fabian Ruch
2014-06-23 16:09 ` Johannes Schindelin
2014-06-19 3:28 ` [RFC PATCH 2/7] rebase -i: Teach do_pick the option --edit Fabian Ruch
2014-06-20 13:41 ` Michael Haggerty
2014-06-22 0:09 ` Fabian Ruch
2014-06-19 3:28 ` [RFC PATCH 3/7] rebase -i: Stop on root commits with empty log messages Fabian Ruch
2014-06-21 0:33 ` Eric Sunshine
2014-06-22 0:32 ` Fabian Ruch
2014-06-19 3:28 ` Fabian Ruch [this message]
2014-06-19 3:28 ` [RFC PATCH 5/7] rebase -i: Do not die in do_pick Fabian Ruch
2014-06-19 3:28 ` [RFC PATCH 6/7] rebase -i: Prepare for squash in terms of do_pick --amend Fabian Ruch
2014-06-19 3:28 ` [RFC PATCH 7/7] rebase -i: Teach do_pick the options --amend and --file Fabian Ruch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53A258E6.5050301@gmail.com \
--to=bafain@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).