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

Regression in 'git pull --rebase --autostash' since v2.32.0

From
Philippe Blain <levraiphilippeblain@gmail.com>
Date
Jul 17, 2021, 15:29 UTC
Message-ID
<a0071549-73f6-9636-9279-3f01143a05de@gmail.com>
Hi Felipe,

Your recent clean-up of 'git pull --autostash' seems to unfortunately have made things worse if the pull brings new files that conflict with existing untracked files, which makes the pull abort, and there are tracked files with modifications (so --autostash comes into play).

Before your change, 'git pull --no-rebase --autostash' did *not* apply the autostash after the pull failed, thus loosing modifications to tracked files (and it did not save the stash entry !). 'git pull --rebase --autostash' correctly applied the autostash, but ended with a strange "error: could not detach HEAD".

After your change, both 'git pull --no-rebase --autostash' and 'git pull --rebase --autostash' have the same buggy behaviour: they do not apply the autostash and do not save it in the stash list.

I had already documented the old behaviour at [1]. Here, I copy my reproducer script (save it as "script"):

~~~bash #!/bin/sh

# usage: ./script <'git pull' arguments>
set -x

rm -rf test rm -rf clone

# Create origin repo
git init test
(
cd test
date>>file
git add file
git commit -m "add file"
)
# Clone
git clone test clone
# Create new file in origin
(
cd test
date>>other
git add other
git commit -m "add other"
)
# Create the same file in clone (untracked)
(
cd clone
date>>other
# If testing '--autostash', add some modifications to 'file'
if [[ "$@" =~ "--autostash" ]]; then
   date>>file
fi
# status before pull
git status
# Try to pull
git pull "$@"
# status after pull
git status
# see if the stash was saved
git stash list
)
~~~
Here are the buggy results :
** ./script --no-rebase --autostash **
~~~
+ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
   (use "git add <file>..." to update what will be committed)
   (use "git restore <file>..." to discard changes in working directory)
	modified:   file
Untracked files:
   (use "git add <file>..." to include in what will be committed)
	other
no changes added to commit (use "git add" and/or "git commit -a")
+ git pull --no-rebase --autostash
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 283 bytes | 94.00 KiB/s, done.
 From /Users/Philippe/Code/GIT-devel/BUGS/ggg-759-pull-autotash-untracked/test
    4ebab2f..fc7a169  master     -> origin/master
Updating 4ebab2f..fc7a169
Created autostash: cfd51b5
error: The following untracked working tree files would be overwritten by merge:
	other
Please move or remove them before you merge.
Aborting
+ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
   (use "git pull" to update your local branch)
Untracked files:
   (use "git add <file>..." to include in what will be committed)
	other
nothing added to commit but untracked files present (use "git add" to track)
+ git stash list
# empty!
~~~
** ./script --rebase --autostash **
~~~
+ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
   (use "git add <file>..." to update what will be committed)
   (use "git restore <file>..." to discard changes in working directory)
	modified:   file
Untracked files:
   (use "git add <file>..." to include in what will be committed)
	other
no changes added to commit (use "git add" and/or "git commit -a")
+ git pull --rebase --autostash
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), 223 bytes | 13.00 KiB/s, done.
 From /Users/Philippe/Code/GIT-devel/BUGS/ggg-759-pull-autotash-untracked/test
    1aa91d4..4f8c34c  master     -> origin/master
Updating 1aa91d4..4f8c34c
Created autostash: d5dffd9
error: The following untracked working tree files would be overwritten by merge:
	other
Please move or remove them before you merge.
Aborting
+ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
   (use "git pull" to update your local branch)
Untracked files:
   (use "git add <file>..." to include in what will be committed)
	other
nothing added to commit but untracked files present (use "git add" to track)
+ git stash list
# empty!
~~~

Reverting 221ec24e9b (Merge branch 'fc/pull-cleanups', 2021-07-08) brings back the old behaviour (which is still buggy for --no-rebase).

I noticed (by reading the code and checking) that the autostash is not completely lost, it's still pointed to by the MERGE_AUTOSTASH special ref, but this is ref is not documented (it's just mentioned without a clear definition).

Cheers, Philippe.

[1] https://github.com/gitgitgadget/git/issues/759
Next: Philippe Blain
Message 1 of 7 in “Regression in 'git pull --rebase --autostash' since v2.32.0”
  1. Philippe BlainJul 17, 2021
  2. Philippe BlainJul 17, 2021
  3. Felipe ContrerasJul 17, 2021
  4. Philippe BlainJul 17, 2021
  5. Felipe ContrerasJul 18, 2021
  6. Philippe BlainJul 23, 2021
  7. Felipe ContrerasJul 23, 2021

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.