Skip to content

Commit

Permalink
Always pass POSIX paths to pygit2 index (#2185) (#2192)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgorny authored Dec 18, 2024
1 parent b2075e6 commit f6b93ef
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
19 changes: 15 additions & 4 deletions conda_smithy/feedstock_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
import stat
from contextlib import contextmanager
from pathlib import Path


def get_repo(path, search_parent_directories=True):
Expand Down Expand Up @@ -38,7 +39,10 @@ def set_exe_file(filename, set_exe=True):

repo = get_repo(filename)
if repo:
index_entry = repo.index[os.path.relpath(filename, repo.workdir)]
index_path = (
Path(filename).resolve().relative_to(repo.workdir).as_posix()
)
index_entry = repo.index[index_path]
if set_exe:
index_entry.mode |= all_execute_permissions
else:
Expand All @@ -65,7 +69,10 @@ def write_file(filename):

repo = get_repo(filename)
if repo:
repo.index.add(os.path.relpath(filename, repo.workdir))
index_path = (
Path(filename).resolve().relative_to(repo.workdir).as_posix()
)
repo.index.add(index_path)
repo.index.write()


Expand All @@ -91,7 +98,10 @@ def remove_file(filename):
repo = get_repo(filename)
if repo:
try:
repo.index.remove(os.path.relpath(filename, repo.workdir))
index_path = (
Path(filename).resolve().relative_to(repo.workdir).as_posix()
)
repo.index.remove(index_path)
repo.index.write()
except OSError: # this is specifically "file not in index"
pass
Expand Down Expand Up @@ -123,5 +133,6 @@ def copy_file(src, dst):

repo = get_repo(dst)
if repo:
repo.index.add(os.path.relpath(dst, repo.workdir))
index_path = Path(dst).resolve().relative_to(repo.workdir).as_posix()
repo.index.add(index_path)
repo.index.write()
6 changes: 5 additions & 1 deletion conda_smithy/feedstock_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import tempfile
import time
from contextlib import contextmanager, redirect_stderr, redirect_stdout
from pathlib import Path

import pygit2
import requests
Expand Down Expand Up @@ -425,7 +426,10 @@ def register_feedstock_token(
json.dump(token_data, fp)

# push
repo.index.add(os.path.relpath(token_file, tmpdir))
index_path = (
Path(token_file).resolve().relative_to(tmpdir).as_posix()
)
repo.index.add(index_path)
repo.index.write()
subprocess.run(
[
Expand Down
23 changes: 23 additions & 0 deletions news/2185-fix-pygit2-windows.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fix passing paths to ``pygit2`` on Windows. (#2192)

**Security:**

* <news item>

0 comments on commit f6b93ef

Please sign in to comment.