Skip to content

Commit

Permalink
pygit: pass remove on nonexistent ref
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Mar 30, 2022
1 parent 2d643b9 commit 052b425
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 052b425

Please sign in to comment.