Skip to content

Commit

Permalink
Merge pull request #302 from minrk/debug-delete_locally
Browse files Browse the repository at this point in the history
fix handling of deleted-but-not-staged files with git 2.40
  • Loading branch information
consideRatio authored Apr 11, 2023
2 parents 728b78b + dab62e9 commit 8827509
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
33 changes: 29 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,42 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
node-version: ["16"]
include:
- python-version: "3.7"
- python-version: "3.8"
# 2.17 is in ubuntu 18.04
git-version: "2.17"
- python-version: "3.9"
# 2.25 is in ubuntu 20.04
git-version: "2.25"
- python-version: "3.10"
# 2.34 is in ubuntu 22.04
git-version: "2.34"
- python-version: "3.11"

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"

- uses: actions/setup-node@v3
with:
node-version: "${{ matrix.node-version }}"
node-version: "${{ matrix.node-version || '16'}}"

- name: install git ${{ matrix.git-version }}
if: ${{ matrix.git-version }}
run: |
export MAMBA_ROOT_PREFIX=$/tmp/conda
mkdir -p $MAMBA_ROOT_PREFIX/bin
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
$MAMBA_ROOT_PREFIX/bin/micromamba install -c conda-forge -p $MAMBA_ROOT_PREFIX "git=${{ matrix.git-version }}"
echo "PATH=$MAMBA_ROOT_PREFIX/bin:$PATH" >> $GITHUB_ENV
- name: git version
run: |
which git
git --version
- name: Run webpack to build static assets
run: |
Expand All @@ -51,4 +76,4 @@ jobs:
- name: Run tests
run: |
pytest --verbose --maxfail=2 --color=yes --cov nbgitpuller
pytest --verbose --maxfail=2 --color=yes --cov nbgitpuller tests
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jupyter-packaging>=0.10
nbclassic
packaging
pytest
pytest-cov
14 changes: 12 additions & 2 deletions nbgitpuller/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,18 @@ def reset_deleted_files(self):

upstream_deleted = self.find_upstream_changed('D')
for filename in deleted_files:
# Filter out empty lines, and files that were deleted in the remote
if filename and filename not in upstream_deleted:
if not filename:
# filter out empty lines
continue

if filename in upstream_deleted:
# deleted in _both_, avoid conflict with git 2.40 by checking it out
# even though it's just about to be deleted
yield from execute_cmd(
['git', 'checkout', 'HEAD', '--', filename], cwd=self.repo_dir
)
else:
# not deleted in upstream, restore with checkout
yield from execute_cmd(['git', 'checkout', 'origin/{}'.format(self.branch_name), '--', filename], cwd=self.repo_dir)

def repo_is_dirty(self):
Expand Down
10 changes: 9 additions & 1 deletion tests/repohelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess as sp
from uuid import uuid4

from packaging.version import Version as V
from nbgitpuller import GitPuller


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

def __enter__(self):
os.makedirs(self.path, exist_ok=True)
self.git('init', '--bare', '--initial-branch=master')

# --initial-branch added in git 2.28
git_version = self.git("--version").split()[-1]
if V(git_version) >= V("2.28"):
extra_args = ('--initial-branch=master',)
else:
extra_args = ()
self.git('init', '--bare', *extra_args)
return self

def __exit__(self, *args):
Expand Down

0 comments on commit 8827509

Please sign in to comment.