Skip to content

Commit

Permalink
Add: Allow to rename and move files in a git repository
Browse files Browse the repository at this point in the history
Implement git mv and git rm in the Git class
  • Loading branch information
bjoernricks committed Apr 6, 2023
1 parent 25ea5ab commit 0a11705
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,15 @@ def rev_list(

args.extend(commit)
return self.exec(*args).splitlines()

def move(self, old: PathLike, new: PathLike) -> None:
"""
Move a file from old to new
"""
return self.exec("mv", fspath(old), fspath(new))

def remove(self, to_remove: PathLike) -> None:
"""
Remove a file from git
"""
return self.exec("rm", fspath(to_remove))
23 changes: 23 additions & 0 deletions tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,29 @@ def test_rev_list(self, exec_git_mock):
cwd=None,
)

@patch("pontos.git.git.exec_git")
def test_move(self, exec_git_mock):
git = Git()
git.move("foo", "bar")

exec_git_mock.assert_called_once_with(
"mv",
"foo",
"bar",
cwd=None,
)

@patch("pontos.git.git.exec_git")
def test_remove(self, exec_git_mock):
git = Git()
git.remove("foo")

exec_git_mock.assert_called_once_with(
"rm",
"foo",
cwd=None,
)


class GitExtendedTestCase(unittest.TestCase):
def test_semantic_list_tags(self):
Expand Down

0 comments on commit 0a11705

Please sign in to comment.