From: Phillip Wood <phillip.w...@dunelm.org.uk>

If rebase --interactive is unable to commit staged changes because
HEAD has changed since rebase stopped the user gets different messages
depending on whether they specified --autostage or not. Update the
messages in the other code paths to match the --autostage one.

Signed-off-by: Phillip Wood <phillip.w...@dunelm.org.uk>
---

The change from error() to fprintf() is to keep the messages consistent,
maybe the messages in the shell script should be prefixed with
'error:' instead.

 git-rebase--interactive.sh | 10 ++++++----
 sequencer.c                | 22 +++++++++++++++++-----
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 
8140c88839b4f3a86f53faaaa2ba4433ecc7f58b..e1845e940b8de05b10b011d8167917a60a7c00b9
 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -1164,10 +1164,12 @@ $(unstaged_advice)"
                        die "$(gettext "Error trying to find the author 
identity to amend commit")"
                if test -n "$amend_head"
                then
-                       test -n "$amend_ok" ||
-                       die "$(gettext "\
-You have uncommitted changes in your working tree. Please commit them
-first and then run 'git rebase --continue' again.")"
+                       test -n "$amend_ok" || {
+                               gpg_sign_opt_quoted=${gpg_sign_opt:+$(git 
rev-parse --sq-quote "$gpg_sign_opt")}
+                               die "$(gettext "\
+Unable to commit changes as HEAD has changed since git rebase stopped.")
+$(staged_advice)"
+                       }
                        do_with_author git commit --amend --no-verify -F "$msg" 
-e \
                                ${gpg_sign_opt:+"$gpg_sign_opt"} ||
                                die "$(gettext "Could not commit staged 
changes.")"
diff --git a/sequencer.c b/sequencer.c
index 
3010faf86398697469e903318a35421d911acb23..2722d36781e5c47ee81eb3359aa6178042430e68
 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2214,12 +2214,24 @@ static int commit_staged_changes(struct replay_opts 
*opts)
                if (get_sha1_hex(rev.buf, to_amend))
                        return error(_("invalid contents: '%s'"),
                                rebase_path_amend());
-               if (hashcmp(head, to_amend))
-                       return error(_("\nYou have uncommitted changes in your "
-                                      "working tree. Please, commit them\n"
-                                      "first and then run 'git rebase "
-                                      "--continue' again."));
+               if (hashcmp(head, to_amend)) {
+                       const char *gpg_opt = gpg_sign_opt_quoted(opts);
 
+                       fprintf(stderr, _(
+"Unable to commit changes as HEAD has changed since git rebase stopped.\n"
+"If you wish to squash the changes into the last commit, run:\n"
+"\n"
+"  git commit --amend %s\n"
+"\n"
+"If they are meant to go into a new commit, run:\n"
+"\n"
+"  git commit %s\n"
+"\n"
+"In both cases, once you're done, continue with:\n"
+"\n"
+"  git rebase --continue\n"), gpg_opt, gpg_opt);
+                       return -1;
+               }
                strbuf_release(&rev);
                flags |= AMEND_MSG;
        }
-- 
2.13.3

Reply via email to