Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message (and fix bugs) when 'git pull [--rebase] [--autostash]' brings new files that conflict with untracked files #759

Open
phil-blain opened this issue Oct 16, 2020 · 4 comments

Comments

@phil-blain
Copy link

phil-blain commented Oct 16, 2020

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.

@phil-blain
Copy link
Author

As of Git version git/git@d486ca60a5 (The third batch, 2021-07-08), the last case fails to apply the autostash, just like with merge.

@phil-blain
Copy link
Author

This regression was reported here: https://lore.kernel.org/git/[email protected]/T/#u

@phil-blain
Copy link
Author

Patch series created here #1002

@phil-blain
Copy link
Author

Patch series sent: https://lore.kernel.org/git/[email protected]/T/#t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant