Skip to content

Commit

Permalink
Merge pull request #1735 from jaredgrubb/jgrubb-git-no-refetch
Browse files Browse the repository at this point in the history
git: skip fetch if the revision already exists
  • Loading branch information
Mikhail Sobolev committed Jun 28, 2015
2 parents f3c5cad + 04f3005 commit 6295d9f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 25 deletions.
45 changes: 20 additions & 25 deletions master/buildbot/steps/source/git.py
Expand Up @@ -216,23 +216,7 @@ def mode_incremental(self, _):
yield self._fullCloneOrFallback()
return

# test for existence of the revision; rc=1 indicates it does not exist
if self.revision:
rc = yield self._dovccmd(['cat-file', '-e', self.revision],
abandonOnFailure=False)
else:
rc = 1

# if revision exists checkout to that revision
# else fetch and update
if rc == RC_SUCCESS:
yield self._dovccmd(['reset', '--hard', self.revision, '--'])

if self.branch != 'HEAD':
yield self._dovccmd(['branch', '-M', self.branch],
abandonOnFailure=False)
else:
yield self._fetchOrFallback()
yield self._fetchOrFallback()

yield self._syncSubmodule(None)
yield self._updateSubmodule(None)
Expand Down Expand Up @@ -375,15 +359,25 @@ def evaluateCommand(_):

@defer.inlineCallbacks
def _fetch(self, _):
command = ['fetch', '-t', self.repourl, self.branch]
# 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
# with Git 1.7.2 or later.
if self.prog:
command.append('--progress')
fetch_required = True

# If the revision already exists in the repo, we dont need to fetch.
if 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', '-t', self.repourl, self.branch]
# 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
# with Git 1.7.2 or later.
if self.prog:
command.append('--progress')

yield self._dovccmd(command)
yield self._dovccmd(command)

if self.revision:
rev = self.revision
Expand All @@ -393,6 +387,7 @@ def _fetch(self, _):
abandonOnFailure = not self.retryFetch and not self.clobberOnFailure
res = yield self._dovccmd(command, abandonOnFailure)

# Rename the branch if needed.
if res == RC_SUCCESS and self.branch != 'HEAD':
# Ignore errors
yield self._dovccmd(['branch', '-M', self.branch], abandonOnFailure=False)
Expand Down
40 changes: 40 additions & 0 deletions master/buildbot/test/unit/test_steps_source_git.py
Expand Up @@ -932,6 +932,46 @@ def test_mode_incremental_given_revision(self):
self.expectProperty('got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', 'Git')
return self.runStep()

def test_mode_incremental_given_revision_not_exists(self):
self.setupStep(
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='incremental'), dict(
revision='abcdef01',
))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ ExpectShell.log('stdio',
stdout='git version 1.7.5')
+ 0,
Expect('stat', dict(file='wkdir/.buildbot-patched',
logEnviron=True))
+ 1,
Expect('listdir', {'dir': 'wkdir', 'logEnviron': True,
'timeout': 1200})
+ Expect.update('files', ['.git'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'cat-file', '-e', 'abcdef01'])
+ 1,
ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-t',
'http://github.com/buildbot/buildbot.git',
'HEAD'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'reset', '--hard', 'abcdef01', '--'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'rev-parse', 'HEAD'])
+ ExpectShell.log('stdio',
stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+ 0,
)
self.expectOutcome(result=SUCCESS)
self.expectProperty('got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', 'Git')
return self.runStep()

def test_mode_full_fresh_submodule(self):
self.setupStep(
git.Git(repourl='http://github.com/buildbot/buildbot.git',
Expand Down

0 comments on commit 6295d9f

Please sign in to comment.