Skip to content

Commit 8827509

Browse files
authored
Merge pull request #302 from minrk/debug-delete_locally
fix handling of deleted-but-not-staged files with git 2.40
2 parents 728b78b + dab62e9 commit 8827509

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,42 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
30-
node-version: ["16"]
29+
include:
30+
- python-version: "3.7"
31+
- python-version: "3.8"
32+
# 2.17 is in ubuntu 18.04
33+
git-version: "2.17"
34+
- python-version: "3.9"
35+
# 2.25 is in ubuntu 20.04
36+
git-version: "2.25"
37+
- python-version: "3.10"
38+
# 2.34 is in ubuntu 22.04
39+
git-version: "2.34"
40+
- python-version: "3.11"
3141

3242
steps:
3343
- uses: actions/checkout@v3
3444
- uses: actions/setup-python@v4
3545
with:
3646
python-version: "${{ matrix.python-version }}"
47+
3748
- uses: actions/setup-node@v3
3849
with:
39-
node-version: "${{ matrix.node-version }}"
50+
node-version: "${{ matrix.node-version || '16'}}"
51+
52+
- name: install git ${{ matrix.git-version }}
53+
if: ${{ matrix.git-version }}
54+
run: |
55+
export MAMBA_ROOT_PREFIX=$/tmp/conda
56+
mkdir -p $MAMBA_ROOT_PREFIX/bin
57+
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/1.4.2 | tar -xvj -C $MAMBA_ROOT_PREFIX/bin/ --strip-components=1 bin/micromamba
58+
$MAMBA_ROOT_PREFIX/bin/micromamba install -c conda-forge -p $MAMBA_ROOT_PREFIX "git=${{ matrix.git-version }}"
59+
echo "PATH=$MAMBA_ROOT_PREFIX/bin:$PATH" >> $GITHUB_ENV
60+
61+
- name: git version
62+
run: |
63+
which git
64+
git --version
4065
4166
- name: Run webpack to build static assets
4267
run: |
@@ -51,4 +76,4 @@ jobs:
5176
5277
- name: Run tests
5378
run: |
54-
pytest --verbose --maxfail=2 --color=yes --cov nbgitpuller
79+
pytest --verbose --maxfail=2 --color=yes --cov nbgitpuller tests

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
jupyter-packaging>=0.10
22
nbclassic
3+
packaging
34
pytest
45
pytest-cov

nbgitpuller/pull.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,18 @@ def reset_deleted_files(self):
170170

171171
upstream_deleted = self.find_upstream_changed('D')
172172
for filename in deleted_files:
173-
# Filter out empty lines, and files that were deleted in the remote
174-
if filename and filename not in upstream_deleted:
173+
if not filename:
174+
# filter out empty lines
175+
continue
176+
177+
if filename in upstream_deleted:
178+
# deleted in _both_, avoid conflict with git 2.40 by checking it out
179+
# even though it's just about to be deleted
180+
yield from execute_cmd(
181+
['git', 'checkout', 'HEAD', '--', filename], cwd=self.repo_dir
182+
)
183+
else:
184+
# not deleted in upstream, restore with checkout
175185
yield from execute_cmd(['git', 'checkout', 'origin/{}'.format(self.branch_name), '--', filename], cwd=self.repo_dir)
176186

177187
def repo_is_dirty(self):

tests/repohelpers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import subprocess as sp
88
from uuid import uuid4
99

10+
from packaging.version import Version as V
1011
from nbgitpuller import GitPuller
1112

1213

@@ -18,7 +19,14 @@ def __init__(self, path=None):
1819

1920
def __enter__(self):
2021
os.makedirs(self.path, exist_ok=True)
21-
self.git('init', '--bare', '--initial-branch=master')
22+
23+
# --initial-branch added in git 2.28
24+
git_version = self.git("--version").split()[-1]
25+
if V(git_version) >= V("2.28"):
26+
extra_args = ('--initial-branch=master',)
27+
else:
28+
extra_args = ()
29+
self.git('init', '--bare', *extra_args)
2230
return self
2331

2432
def __exit__(self, *args):

0 commit comments

Comments
 (0)