Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion scmrepo/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def __init__(

@property
def dir(self):
return first(self.backends.values()).dir
for backend in self.backends.values():
try:
return backend.dir
except NotImplementedError:
pass
raise NotImplementedError

@cached_property
def hooks_dir(self):
Expand Down
4 changes: 2 additions & 2 deletions scmrepo/git/backend/pygit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ def get_ref(self, name, follow: bool = True) -> Optional[str]:

def remove_ref(self, name: str, old_ref: Optional[str] = None):
ref = self.repo.references.get(name)
if not ref:
raise SCMError(f"Ref '{name}' does not exist")
if not ref and not old_ref:
return
if old_ref and old_ref != str(ref.target):
raise SCMError(f"Failed to remove '{name}'")
ref.delete()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ def test_remove_ref(tmp_dir: TmpDir, scm: Git, git: Git):
scm.add_commit("file", message="init")
init_rev = scm.get_rev()

# remove nonexistent ref should silently pass when old_ref is None)
git.remove_ref("refs/foo/bar", old_ref=None)

tmp_dir.gen(os.path.join(".git", "refs", "foo", "bar"), init_rev)
tmp_dir.gen({"file": "1"})
scm.add_commit("file", message="commit")
Expand Down