git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH] fail pull/merge early in the middle of conflicted merge

From
Junio C Hamano <junkio@cox.net>
Date
Jan 1, 2007, 07:21 UTC
Message-ID
<7vwt478b5d.fsf@assigned-by-dhcp.cox.net>

After a pull that results in a conflicted merge, a new user often tries another "git pull" in desperation. When the index is unmerged, merge backends correctly bail out without touching either index nor the working tree, so this does not make the wound any worse.

The user will however see several lines of messsages during this process, such as "filename: needs merge", "you need to resolve your current index first", "Merging...", and "Entry ... would be overwritten by merge. Cannot merge.". They are unnecessarily alarming, and makes useful conflict messages from the first pull scroll off the top of the terminal.

This changes pull and merge to run "git-ls-files -u" upfront and stop them much earlier than we currently do.

Old timers may know better and would not to try pulling again before cleaning things up; this change adds extra overhead that is unnecessary for them. But this would be worth paying for to save new people from needless confusion.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * I've seen some people on #git channel got totally confused
   after a conflicted merge at least three times, and they paste
   the diagnostics from the second and subsequent pull, assuming
   that the messages would help diagnosing the situation in any
   way (unfortunately they typically don't).  But it is not the
   user's fault not to know it.  With this what they can give us
   when asking for help will only be from the first pull.  In a
   sense, the real motivation of this patch is to make life
   easier for people who want to help these new people.
 git-merge.sh |    3 +++
 git-pull.sh  |    3 +++
 2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/git-merge.sh b/git-merge.sh
index ba42260..f43fa69 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -8,6 +8,9 @@ USAGE='[-n] [--no-commit] [--squash] [-s <strategy>] [-m=<merge-message>] <commi
 . git-sh-setup
 set_reflog_action "merge $*"
 
+test -z "$(git ls-files -u)" || 
+	die "You are in a middle of conflicted merge."
+
 LF='
 '
 
diff --git a/git-pull.sh b/git-pull.sh
index 28d0819..49130d5 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -9,6 +9,9 @@ LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEA
 . git-sh-setup
 set_reflog_action "pull $*"
 
+test -z "$(git ls-files -u)" || 
+	die "You are in a middle of conflicted merge."
+
 strategy_args= no_summary= no_commit= squash=
 while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
 do
Next: Shawn O. Pearce
Message 1 of 4 in “fail pull/merge early in the middle of conflicted merge”
  1. fail pull/merge early in the middle of conflicted mergeJunio C Hamano, Jan 1, 2007
  2. Shawn O. PearceJan 1, 2007
  3. Junio C HamanoJan 2, 2007
  4. Andreas EricssonJan 4, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.