Skip to content

Commit

Permalink
Merge pull request #7236 from p12tic/buildstep-git-tags
Browse files Browse the repository at this point in the history
git: Add tags option to download tags when updating repository
  • Loading branch information
p12tic committed Dec 4, 2023
2 parents 694f76c + 8a431dc commit 7805a92
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
38 changes: 30 additions & 8 deletions master/buildbot/steps/source/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,29 @@ class Git(Source, GitStepMixin):
renderables = ["repourl", "reference", "branch",
"codebase", "mode", "method", "origin"]

def __init__(self, repourl=None, branch='HEAD', mode='incremental', method=None,
reference=None, submodules=False, remoteSubmodules=False, shallow=False,
filters=None, progress=True, retryFetch=False, clobberOnFailure=False,
getDescription=False, config=None, origin=None, sshPrivateKey=None,
sshHostKey=None, sshKnownHosts=None, **kwargs):

def __init__(
self,
repourl=None,
branch='HEAD',
mode='incremental',
method=None,
reference=None,
submodules=False,
remoteSubmodules=False,
tags=False,
shallow=False,
filters=None,
progress=True,
retryFetch=False,
clobberOnFailure=False,
getDescription=False,
config=None,
origin=None,
sshPrivateKey=None,
sshHostKey=None,
sshKnownHosts=None,
**kwargs
):
if not getDescription and not isinstance(getDescription, dict):
getDescription = False

Expand All @@ -87,6 +104,7 @@ def __init__(self, repourl=None, branch='HEAD', mode='incremental', method=None,
self.retryFetch = retryFetch
self.submodules = submodules
self.remoteSubmodules = remoteSubmodules
self.tags = tags
self.shallow = shallow
self.filters = filters
self.clobberOnFailure = clobberOnFailure
Expand Down Expand Up @@ -306,15 +324,19 @@ def _getSshDataWorkDir(self):
def _fetch(self, _, abandonOnFailure=True):
fetch_required = True

# If the revision already exists in the repo, we don't need to fetch.
if self.revision:
# If the revision already exists in the repo, we don't need to fetch. However, if tags
# were requested, then fetch still needs to be performed for the tags.
if not self.tags and self.revision:
rc = yield self._dovccmd(['cat-file', '-e', self.revision],
abandonOnFailure=False)
if rc == RC_SUCCESS:
fetch_required = False

if fetch_required:
command = ['fetch', '-f', '-t', self.repourl, self.branch]
if self.tags:
command.append("--tags")

# If the 'progress' option is set, tell git fetch to output
# progress information to the log. This can solve issues with
# long fetches killed due to lack of output, but only works
Expand Down
35 changes: 35 additions & 0 deletions master/buildbot/test/unit/steps/test_source_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,41 @@ def test_mode_full_clean_branch(self):
'got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', self.sourceName)
return self.run_step()

def test_mode_full_clean_tags(self):
self.setup_step(
self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean', tags=True))
self.expect_commands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
.stdout('git version 1.7.5')
.exit(0),
ExpectStat(file='wkdir/.buildbot-patched', log_environ=True)
.exit(1),
ExpectListdir(dir='wkdir')
.files(['.git'])
.exit(0),
ExpectShell(workdir='wkdir',
command=['git', 'clean', '-f', '-f', '-d'])
.exit(0),
ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-f', '-t',
'http://github.com/buildbot/buildbot.git',
'HEAD', '--tags', "--progress"])
.exit(0),
ExpectShell(workdir='wkdir',
command=['git', 'checkout', '-f', 'FETCH_HEAD'])
.exit(0),
ExpectShell(workdir='wkdir',
command=['git', 'rev-parse', 'HEAD'])
.stdout('f6ad368298bd941e934a41f3babc827b2aa95a1d')
.exit(0)
)
self.expect_outcome(result=SUCCESS)
self.expect_property(
'got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', self.sourceName)
return self.run_step()

def test_mode_full_clean_non_empty_builddir(self):
self.setup_step(
self.stepClass(repourl='http://github.com/buildbot/buildbot.git',
Expand Down
3 changes: 3 additions & 0 deletions master/docs/manual/configuration/steps/source_git.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ The Git step takes the following arguments:
When initializing/updating a Git repository, this tells Buildbot whether to handle Git submodules.
If ``remoteSubmodules`` is ``True``, then this tells Buildbot to use remote submodules: `Git Remote Submodules <https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt---remote>`_

``tags`` (optional, default: ``False``)
Download tags in addition to the requested revision when updating repository.

``shallow`` (optional)
Instructs Git to attempt shallow clones (``--depth 1``).
The depth defaults to 1 and can be changed by passing an integer instead of ``True``.
Expand Down
1 change: 1 addition & 0 deletions newsfragments/steps-source-git-tags.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ``tags`` option to the ``Git`` source step to download tags when updating repository.

0 comments on commit 7805a92

Please sign in to comment.