Description
When a pull brings new files that conflict with untracked files, the error message differs if using --rebase
or not, and if using --autostash
or not, and they are is a little bit confusing with --rebase
or --autostash
. Also, there is a bug with git pull --autostash
:
Reproducer (save as script
):
#!/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"
cd ../
# Clone
git clone test clone
# Create new file in origin
cd test
date>>other
git add other
git commit -m "add other"
cd ../
# Create the same file in clone
cd clone
date>>other
# If testing '--autostash', add some modifications to 'file'
if [[ "$@" =~ "--autostash" ]]; then
date>>file
fi
# Try to pull
git pull "$@"
./script --no-rebase
From /Users/Philippe/Code/GIT-devel/BUGS/pull-rebase-autostash-untracked-conflict/test
d2f84b4..8d5caf1 master -> origin/master
Updating d2f84b4..8d5caf1
error: The following untracked working tree files would be overwritten by merge:
other
Please move or remove them before you merge.
Aborting
This message is correct.
./script --no-rebase --autostash
From /Users/Philippe/Code/GIT-devel/BUGS/pull-rebase-autostash-untracked-conflict/test
46dc1c6..bb224e1 master -> origin/master
Updating 46dc1c6..bb224e1
Created autostash: 7b79a0b
error: The following untracked working tree files would be overwritten by merge:
other
Please move or remove them before you merge.
Aborting
This message is correct.
NOTE: the autostash is not applied after the failed merge, and git stash list
is empty so the stash is deleted ! This is a bug.
NOTE 2: it's not completely lost since it's accessible via it's hash 7b79a0b
and the semi-documented special ref MERGE_AUTOSTASH
.
./script --rebase
From /Users/Philippe/Code/GIT-devel/BUGS/pull-rebase-autostash-untracked-conflict/test
ad731d7..b535925 master -> origin/master
Updating ad731d7..b535925
error: The following untracked working tree files would be overwritten by merge:
other
Please move or remove them before you merge.
Aborting
This message could be improved: "by merge" is misleading, since the user asked to rebase and so will be confused if Git is mentioning "merge".
./script --rebase --autostash
From /Users/Philippe/Code/GIT-devel/BUGS/pull-rebase-autostash-untracked-conflict/test
2129f90..5fed87a master -> origin/master
Created autostash: 4b34944
error: The following untracked working tree files would be overwritten by checkout:
other
Please move or remove them before you switch branches.
Aborting
Applied autostash.
error: could not detach HEAD
Here the message mentions "checkout" and "switch branches", which again is not the operation the user was asking Git to perform, so it might also cause mild confusion.
Also, "error: could not detach HEAD" appears, but this looks like a bug: which HEAD are we trying to detach here ?....
Pinging @Denton-L since I remember you worked on merge --autostash
.