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

Re: [PATCH 0/2] Reinstate the helpful message when `git pull --rebase` fails

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 9, 2015, 10:11 UTC
Message-ID
<d89d595a223508896db9303c901e7c30@dscho.org>
In-Reply-To
<4a99ca8724b3604cbbec48d559e134fd@dscho.org>
Me again,
On 2015-10-09 11:50, Johannes Schindelin wrote:
Show 25 quoted lines
> 
> On 2015-10-09 03:40, Paul Tan wrote:
>> On Fri, Oct 9, 2015 at 8:52 AM, Junio C Hamano <gitster@pobox.com> wrote:
>>> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>>>
>>>> Brendan Forster noticed that we no longer see the helpful message after
>>>> a failed `git pull --rebase`. It turns out that the builtin `am` calls
>>>> the recursive merge function directly, not via a separate process.
>>>>
>>>> But that function was not really safe to be called that way, as it
>>>> die()s pretty liberally.
>>
>> I'm not too familiar with the merge-recursive.c code, but I was under
>> the impression that it only called die() under fatal conditions. In
>> common use cases, such as merge conflicts, it just errors out and the
>> helpful error message does get printed. Is there a reproduction recipe
>> for this?
> 
> Yes. Sorry, I should have added that as part of the patch series.
> Actually, I should have written it *before* making those patches.
> Because it revealed that the underlying problem is completely
> different: *Normally* you are correct, if `pull --rebase` fails with a
> merge conflict, the advice is shown.
> 
> The problem occurs with CR/LF.
I finally have that test case working, took way longer than I wanted to:
-- snip --
Subject: [PATCH 3/2] Verify that `git pull --rebase` shows the helpful advice when failing
Author: Johannes Schindelin <johannes.schindelin@gmx.de>
Date:   Fri Oct 9 11:15:30 2015 +0200
    
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a0013ee..bce332f 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -237,6 +237,18 @@ test_expect_success '--rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
+test_expect_success 'failed --rebase shows advice' '
+	git checkout -b diverging &&
+	test_commit attributes .gitattributes "* text=auto" attrs &&
+	sha1="$(printf "1\\r\\n" | git hash-object -w --stdin)" &&
+	git update-index --cacheinfo 0644 $sha1 file &&
+	git commit -m v1-with-cr &&
+	git checkout -f -b fails-to-rebase HEAD^ &&
+	test_commit v2-without-cr file "2" file2-lf &&
+	test_must_fail git pull --rebase . diverging 2>err >out &&
+	grep "When you have resolved this problem" out
+'
+
 test_expect_success '--rebase fails with multiple branches' '
 	git reset --hard before-rebase &&
 	test_must_fail git pull --rebase . copy master 2>err &&
--

So the reason is that `unpack_trees()` fails with

    error: Your local changes to the following files would be overwritten by merge:
	file
    Please, commit your changes or stash them before you can merge.

then returns -1 to its caller, `git_merge_trees()`, which still returns -1 in turn to *its* caller, `merge_trees()`, which then gives up by die()ing:

    Aborting

I think there is more than one fix necessary to truly address the issue: the underlying problem is that Git handles *committed* CR/LF really badly when the corresponding `.gitattributes` label the file as `text=auto`. In fact, those files are labeled as modified in `git status`. If you change the line endings of them, they are labeled as modified in `git status`. And after a `git reset --hard`, they are *still* labeled as modified in `git status`.

I will try to make some time to continue to work on this later today, but in the meantime I would be relatively happy if we could introduce that gentle flag. It is really a very gentle patch, after all, much gentler than reverting to the heavy-handed spawning of `merge-recursive`.

Ciao,
Dscho
Previous: Johannes SchindelinNext: Junio C Hamano
Message 10 of 22 in “Reinstate the helpful message when `git pull --rebase` fails”
  1. 0/2 Reinstate the helpful message when `git pull --rebase` failsJohannes Schindelin, Oct 8, 2015
  2. 1/2 merge_recursive_options: introduce the "gentle" flagJohannes Schindelin, Oct 8, 2015
  3. 2/2 pull --rebase: reinstate helpful message on abortJohannes Schindelin, Oct 8, 2015
  4. Junio C HamanoOct 9, 2015
  5. Johannes SchindelinOct 12, 2015
  6. Junio C HamanoOct 12, 2015
  7. Junio C HamanoOct 9, 2015
  8. Paul TanOct 9, 2015
  9. Johannes SchindelinOct 9, 2015
  10. Johannes SchindelinOct 9, 2015
  11. Junio C HamanoOct 9, 2015
  12. Torsten BögershausenOct 10, 2015
  13. Torsten BögershausenOct 10, 2015
  14. Johannes SchindelinOct 12, 2015
  15. Junio C HamanoOct 9, 2015
  16. Junio C HamanoOct 9, 2015
  17. Junio C HamanoOct 9, 2015
  18. Johannes SchindelinOct 12, 2015
  19. Junio C HamanoOct 9, 2015
  20. Johannes SchindelinOct 12, 2015
  21. Junio C HamanoOct 12, 2015
  22. Johannes SchindelinOct 13, 2015

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.