Skip to content

Commit

Permalink
Add: Allow to pass a refspec to Git.fetch
Browse files Browse the repository at this point in the history
When fetching from git remotes allow to specify refs that should be
fetched explicitly.
  • Loading branch information
bjoernricks committed Feb 6, 2023
1 parent abeb90d commit bb08bd7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pontos/git/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,31 @@ def tag(

exec_git(*args, cwd=self._cwd)

def fetch(self, remote: Optional[str] = None) -> None:
def fetch(
self,
remote: Optional[str] = None,
refspec: Optional[str] = None,
*,
verbose: bool = False,
) -> None:
"""
Fetch from changes from remote
Args:
remote: Remote to fetch changes from
refspec: Specifies which refs to fetch and which local refs to
update.
verbose: Print verbose output.
"""
args = ["fetch"]

if remote:
args.append(remote)
if refspec:
args.append(refspec)

if verbose:
args.append("-v")

exec_git(*args, cwd=self._cwd)

Expand Down
16 changes: 16 additions & 0 deletions tests/git/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,22 @@ def test_fetch_with_remote(self, exec_git_mock):

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

@patch("pontos.git.git.exec_git")
def test_fetch_with_remote_and_refspec(self, exec_git_mock):
git = Git()
git.fetch("foo", "my-branch")

exec_git_mock.assert_called_once_with(
"fetch", "foo", "my-branch", cwd=None
)

@patch("pontos.git.git.exec_git")
def test_fetch_with_verbose(self, exec_git_mock):
git = Git()
git.fetch(verbose=True)

exec_git_mock.assert_called_once_with("fetch", "-v", cwd=None)

@patch("pontos.git.git.exec_git")
def test_add_remote(self, exec_git_mock):
git = Git()
Expand Down

0 comments on commit bb08bd7

Please sign in to comment.