If you change a file locally, then sync, then delete the file, following sync operations will fail.
Text of the error message
```
$ git fetch
From https://github.com/jdmansour/testrepo
3024da6..a725b72 main -> origin/main
$ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller merge -Xours origin/main
error: Your local changes to the following files would be overwritten by merge:
README.md
Traceback (most recent call last):
File "/opt/tljh/user/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/opt/tljh/user/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/handlers.py", line 88, in pull
raise e
File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/handlers.py", line 82, in pull
for line in gp.pull():
File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/pull.py", line 146, in pull
yield from self.update()
File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/pull.py", line 287, in update
yield from execute_cmd([
File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/pull.py", line 45, in execute_cmd
raise subprocess.CalledProcessError(ret, cmd)
subprocess.CalledProcessError: Command '['git', '-c', 'user.email=nbgitpuller@nbgitpuller.link', '-c', 'user.name=nbgitpuller', 'merge', '-Xours', 'origin/main']' returned non-zero exit status 128.
```
Expected behaviour
I would expect the deleted file to be pulled again from the remote repository.
Actual behaviour
Sync fails with the above error message.
How to reproduce
Checkout a repository with nbgitpuller
Make a change to a file README.md, then sync. The local change will be kept.
Delete README.md locally. (Optionally sync)
Add another file new_file.txt to the remote repository, then attempt to sync.
Status of the git repository right before step 4
```
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add/rm ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
deleted: README.md
no changes added to commit (use "git add" and/or "git commit -a")
----------------
$ git log --raw
commit 1659637688293df7a351a78113a87331d46bffc7
Author: nbgitpuller
Date: Tue Mar 15 12:22:29 2022 +0100
Automatic commit by nbgitpuller
:100644 100644 b6fc4c6 3b8cc22 M README.md
commit 6a0a1590b23a484dbf8b2e315300fc4978d68bcd
Author: pusher
Date: Tue Mar 15 12:22:29 2022 +0100
Ignore the message
:000000 100644 0000000 b6fc4c6 A README.md
----------------
$ git diff
diff --git a/README.md b/README.md
deleted file mode 100644
index 3b8cc22..0000000
--- a/README.md
+++ /dev/null
@@ -1 +0,0 @@
-student changed
\ No newline at end of file
```
Output of git during the test
```
puller: $ git clone --depth 1 --branch master -- file:///Users/jason/src/nbgitpuller/remote puller
puller: Cloning into 'puller'...
puller: $ git fetch
puller: $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller commit -am Automatic commit by nbgitpuller --allow-empty
puller: [master 1659637] Automatic commit by nbgitpuller
puller: 1 file changed, 1 insertion(+), 1 deletion(-)
puller: $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller merge -Xours origin/master
puller: Already up to date.
puller: $ git fetch
puller: From file:///Users/jason/src/nbgitpuller/remote
puller: 6a0a159..7d298d5 master -> origin/master
puller: $ git checkout origin/master -- README.md
puller: $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller merge -Xours origin/master
puller: error: Your local changes to the following files would be overwritten by merge:
puller: README.md
```
If you go step by step through the commands nbgitpuller is running, what happens is that before the last git merge, there will be a staged but not committed change to README.md. This causes the merge to fail. Unfortunately I don't understand nbgitpuller's merge strategy very well, so I'm not sure how to fix it. Unstaging the change before merge gets rid of the error message, but I don't know if that is the right solution.
Your personal set up
I am using TLJH in a fairly vanilla configuration, installed via https://tljh.jupyter.org/bootstrap.py.
Unfortunately my fix to this introduced a regression :-(. A reset fails in the following case:
Modify a file locally
Sync, and it keeps your change (this creates a commit in the local branch)
Delete the file in order to reset it
The result is that it will get the file from the local branch, not the remote branch, so it is reset to an old version from the student.
Bug description
If you change a file locally, then sync, then delete the file, following sync operations will fail.
Text of the error message
``` $ git fetch From https://github.com/jdmansour/testrepo 3024da6..a725b72 main -> origin/main $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller merge -Xours origin/main error: Your local changes to the following files would be overwritten by merge: README.md Traceback (most recent call last): File "/opt/tljh/user/lib/python3.9/threading.py", line 973, in _bootstrap_inner self.run() File "/opt/tljh/user/lib/python3.9/threading.py", line 910, in run self._target(*self._args, **self._kwargs) File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/handlers.py", line 88, in pull raise e File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/handlers.py", line 82, in pull for line in gp.pull(): File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/pull.py", line 146, in pull yield from self.update() File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/pull.py", line 287, in update yield from execute_cmd([ File "/opt/tljh/user/lib/python3.9/site-packages/nbgitpuller/pull.py", line 45, in execute_cmd raise subprocess.CalledProcessError(ret, cmd) subprocess.CalledProcessError: Command '['git', '-c', 'user.email=nbgitpuller@nbgitpuller.link', '-c', 'user.name=nbgitpuller', 'merge', '-Xours', 'origin/main']' returned non-zero exit status 128. ```Expected behaviour
I would expect the deleted file to be pulled again from the remote repository.
Actual behaviour
Sync fails with the above error message.
How to reproduce
README.md
, then sync. The local change will be kept.README.md
locally. (Optionally sync)new_file.txt
to the remote repository, then attempt to sync.I have added a test to reproduce the problem here: https://github.com/jdmansour/nbgitpuller/commit/cf259693fc5834a196ac7efd6f22ccf945ff251e
Status of the git repository right before step 4
``` $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add/rmOutput of git during the test
``` puller: $ git clone --depth 1 --branch master -- file:///Users/jason/src/nbgitpuller/remote puller puller: Cloning into 'puller'... puller: $ git fetch puller: $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller commit -am Automatic commit by nbgitpuller --allow-empty puller: [master 1659637] Automatic commit by nbgitpuller puller: 1 file changed, 1 insertion(+), 1 deletion(-) puller: $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller merge -Xours origin/master puller: Already up to date. puller: $ git fetch puller: From file:///Users/jason/src/nbgitpuller/remote puller: 6a0a159..7d298d5 master -> origin/master puller: $ git checkout origin/master -- README.md puller: $ git -c user.email=nbgitpuller@nbgitpuller.link -c user.name=nbgitpuller merge -Xours origin/master puller: error: Your local changes to the following files would be overwritten by merge: puller: README.md ```If you go step by step through the commands nbgitpuller is running, what happens is that before the last
git merge
, there will be a staged but not committed change toREADME.md
. This causes the merge to fail. Unfortunately I don't understand nbgitpuller's merge strategy very well, so I'm not sure how to fix it. Unstaging the change before merge gets rid of the error message, but I don't know if that is the right solution.Your personal set up
I am using TLJH in a fairly vanilla configuration, installed via
https://tljh.jupyter.org/bootstrap.py
.