def testUpdateClone(self): if not self.enabled: return options = self.Options() origin_root_dir = self.root_dir self.root_dir = tempfile.mkdtemp() self.relpath = '.' self.base_path = join(self.root_dir, self.relpath) scm = gclient_scm.CreateSCM(url=origin_root_dir, root_dir=self.root_dir, relpath=self.relpath) expected_file_list = [ join(self.base_path, "a"), join(self.base_path, "b") ] file_list = [] options.revision = 'unmanaged' scm.update(options, (), file_list) self.assertEquals(file_list, expected_file_list) self.assertEquals(scm.revinfo(options, (), None), '069c602044c5388d2d15c3f875b057c852003458') # indicates detached HEAD self.assertEquals(self.getCurrentBranch(), None) self.checkInStdout( 'Checked out refs/remotes/origin/master to a detached HEAD') rmtree(origin_root_dir)
def testUpdateCloneOnFetchedRemoteBranch(self): if not self.enabled: return options = self.Options() origin_root_dir = self.root_dir self.root_dir = tempfile.mkdtemp() self.relpath = '.' self.base_path = join(self.root_dir, self.relpath) url_with_branch_ref = origin_root_dir + '@refs/remotes/origin/feature' scm = gclient_scm.CreateSCM(url=url_with_branch_ref, root_dir=self.root_dir, relpath=self.relpath) expected_file_list = [ join(self.base_path, "a"), join(self.base_path, "b"), join(self.base_path, "c") ] file_list = [] options.revision = 'unmanaged' scm.update(options, (), file_list) self.assertEquals(file_list, expected_file_list) self.assertEquals(scm.revinfo(options, (), None), '9a51244740b25fa2ded5252ca00a3178d3f665a9') # indicates detached HEAD self.assertEquals(self.getCurrentBranch(), None) self.checkInStdout( 'Checked out refs/remotes/origin/feature to a detached HEAD') rmtree(origin_root_dir)
def testUpdateCloneOnCommit(self): if not self.enabled: return options = self.Options() origin_root_dir = self.root_dir self.root_dir = tempfile.mkdtemp() self.relpath = '.' self.base_path = join(self.root_dir, self.relpath) url_with_commit_ref = origin_root_dir +\ '@a7142dc9f0009350b96a11f372b6ea658592aa95' scm = gclient_scm.CreateSCM(url=url_with_commit_ref, root_dir=self.root_dir, relpath=self.relpath) expected_file_list = [ join(self.base_path, "a"), join(self.base_path, "b") ] file_list = [] options.revision = 'unmanaged' scm.update(options, (), file_list) self.assertEquals(file_list, expected_file_list) self.assertEquals(scm.revinfo(options, (), None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') # indicates detached HEAD self.assertEquals(self.getCurrentBranch(), None) self.checkInStdout( 'Checked out a7142dc9f0009350b96a11f372b6ea658592aa95 to a detached HEAD' ) rmtree(origin_root_dir)
def testRevertNew(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.update(options, None, file_list) file_path = join(self.base_path, 'c') f = open(file_path, 'w') f.writelines('new\n') f.close() Popen(['git', 'add', 'c'], stdout=PIPE, stderr=STDOUT, cwd=self.base_path).communicate() file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, [file_path]) file_list = [] scm.diff(options, self.args, file_list) self.assertEquals(file_list, []) self.assertEquals(scm.revinfo(options, self.args, None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') expectation = ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' 'Fast-forward\n a | 1 +\n b | 1 +\n' ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' '________ running \'git reset --hard origin/master\' in \'%s\'\n' 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.') self.assertTrue(sys.stdout.getvalue().startswith(expectation)) sys.stdout.close()
def testUpdateConflict(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_path = join(self.base_path, 'b') open(file_path, 'w').writelines('conflict\n') scm._Run(['commit', '-am', 'test'], options) __builtin__.raw_input = lambda x: 'y' exception = ('Conflict while rebasing this branch.\n' 'Fix the conflict and run gclient again.\n' 'See \'man git-rebase\' for details.\n') self.assertRaisesError(exception, scm.update, options, (), []) exception = ('\n____ . at refs/heads/master\n' '\tYou have unstaged changes.\n' '\tPlease commit, stash, or reset.\n') self.assertRaisesError(exception, scm.update, options, (), []) # The hash always changes. Use a cheap trick. start = ('\n________ running \'git commit -am test\' in \'%s\'\n' '[new ') % join(self.root_dir, '.') end = ('] test\n 1 files changed, 1 insertions(+), ' '1 deletions(-)\n\n_____ . at refs/heads/master\n' 'Attempting rebase onto refs/remotes/origin/master...\n') self.assertTrue(sys.stdout.getvalue().startswith(start)) self.assertTrue(sys.stdout.getvalue().endswith(end)) self.assertEquals(len(sys.stdout.getvalue()), len(start) + len(end) + 7) sys.stdout.close()
def testGetUsableRevGit(self): # pylint: disable=E1101 options = self.Options(verbose=True) self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsValidRevision', True) gclient_scm.scm.GIT.IsValidRevision(cwd=self.base_path, rev=self.fake_hash_1 ).AndReturn(True) self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) gclient_scm.scm.GIT.IsGitSvn(cwd=self.base_path).MultipleTimes( ).AndReturn(False) gclient_scm.scm.os.path.isdir(self.base_path).AndReturn(True) gclient_scm.os.path.isdir(self.base_path).AndReturn(True) self.mox.ReplayAll() git_scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) # A [fake] git sha1 with a git repo should work (this is in the case that # the LKGR gets flipped to git sha1's some day). self.assertEquals(git_scm.GetUsableRev(self.fake_hash_1, options), self.fake_hash_1) # An SVN rev with an existing purely git repo should raise an exception. self.assertRaises(gclient_scm.gclient_utils.Error, git_scm.GetUsableRev, '1', options)
def testDir(self): members = [ 'BinaryExists', 'FullUrlForRelativeUrl', 'GetCheckoutRoot', 'GetRevisionDate', 'GetUsableRev', 'RunCommand', 'cache_dir', 'cache_locks', 'cleanup', 'diff', 'nag_max', 'nag_timer', 'pack', 'UpdateSubmoduleConfig', 'relpath', 'revert', 'revinfo', 'runhooks', 'status', 'update', 'url', ] # If you add a member, be sure to add the relevant test! self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
def testRevertModified(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.update(options, None, file_list) file_path = join(self.base_path, 'a') open(file_path, 'a').writelines('touched\n') file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, [file_path]) file_list = [] scm.diff(options, self.args, file_list) self.assertEquals(file_list, []) self.assertEquals(scm.revinfo(options, self.args, None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') self.checkstdout( ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' 'Fast-forward\n a | 1 +\n b | 1 +\n' ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' '________ running \'git reset --hard origin/master\' in \'%s\'\n' 'HEAD is now at a7142dc Personalized\n') % join(self.root_dir, '.'))
def testRevertNew(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.update(options, None, file_list) file_path = join(self.base_path, 'c') f = open(file_path, 'w') f.writelines('new\n') f.close() Popen(['git', 'add', 'c'], stdout=PIPE, stderr=STDOUT, cwd=self.base_path).communicate() file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, [file_path]) file_list = [] scm.diff(options, self.args, file_list) self.assertEquals(file_list, []) self.assertEquals(scm.revinfo(options, self.args, None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') sys.stdout.close()
def testRevinfo(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) rev_info = scm.revinfo(options, (), None) self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458')
def testDir(self): members = [ 'FullUrlForRelativeUrl', 'GetRevisionDate', 'RunCommand', 'cleanup', 'diff', 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'status', 'update', 'url', ] # If you add a member, be sure to add the relevant test! self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
def setUp(self): super(GitHungTest, self).setUp() self.old = gclient_scm.gclient_utils.CheckCallAndFilter self.old2 = gclient_scm.gclient_utils.subprocess2.Popen self.options = self.Options() self.options.verbose = False self.scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) os.environ['GCLIENT_KILL_GIT_FETCH_AFTER'] = '1.0'
def testDir(self): members = [ 'COMMAND', 'Capture', 'CaptureStatus', 'FullUrlForRelativeUrl', 'GetEmail', 'RunCommand', 'cleanup', 'diff', 'export', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', ] # If you add a member, be sure to add the relevant test! self.compareMembers(gclient_scm.CreateSCM(url=self.url), members)
def testStatusNew(self): if not self.enabled: return options = self.Options() file_path = gclient_scm.os.path.join(self.base_path, 'a') open(file_path, 'a').writelines('touched\n') scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.status(options, self.args, file_list) self.assertEquals(file_list, [file_path])
def testRevertNone(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, []) self.assertEquals(scm.revinfo(options, self.args, None), '069c602044c5388d2d15c3f875b057c852003458')
def testUpdateUpdate(self): if not self.enabled: return options = self.Options() expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.update(options, (), file_list) self.assertEquals(file_list, expected_file_list) self.assertEquals(scm.revinfo(options, (), None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') sys.stdout.close()
def testUpdateLocked(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_path = join(self.base_path, '.git', 'index.lock') with open(file_path, 'w'): pass with self.assertRaises(subprocess2.CalledProcessError): scm.update(options, (), []) sys.stdout.close()
def testRevertNone(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.update(options, None, file_list) file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, []) self.assertEquals(scm.revinfo(options, self.args, None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') sys.stdout.close()
def GetURLAndRev(name, original_url): url, revision = gclient_utils.SplitUrlRevision(original_url) if not revision: if revision_overrides.has_key(name): return (url, revision_overrides[name]) else: scm = gclient_scm.CreateSCM(solution["url"], self._root_dir, name) return (url, scm.revinfo(self._options, [], None)) else: if revision_overrides.has_key(name): return (url, revision_overrides[name]) else: return (url, revision)
def testUpdateUpdate(self): if not self.enabled: return options = self.Options() expected_file_list = [] scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] options.revision = 'unmanaged' scm.update(options, (), file_list) self.assertEquals(file_list, expected_file_list) self.assertEquals(scm.revinfo(options, (), None), '069c602044c5388d2d15c3f875b057c852003458') self.checkstdout('________ unmanaged solution; skipping .\n')
def testUpdateNotGit(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) git_path = join(self.base_path, '.git') rename(git_path, git_path + 'foo') exception = ('\n____ . at refs/heads/master\n' '\tPath is not a git repo. No .git dir.\n' '\tTo resolve:\n' '\t\trm -rf .\n' '\tAnd run gclient sync again\n') self.assertRaisesError(exception, scm.update, options, (), [])
def testRevertMissing(self): if not self.enabled: return options = self.Options() file_path = gclient_scm.os.path.join(self.base_path, 'a') gclient_scm.os.remove(file_path) scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, [file_path]) file_list = [] scm.diff(options, self.args, file_list) self.assertEquals(file_list, [])
def testStatusNew(self): if not self.enabled: return options = self.Options() file_path = join(self.base_path, 'a') open(file_path, 'a').writelines('touched\n') scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.status(options, self.args, file_list) self.assertEquals(file_list, [file_path]) self.checkstdout( ('\n________ running \'git diff --name-status ' '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\n') % join(self.root_dir, '.'))
def testRevertModified(self): if not self.enabled: return options = self.Options() file_path = gclient_scm.os.path.join(self.base_path, 'a') open(file_path, 'a').writelines('touched\n') scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, [file_path]) file_list = [] scm.diff(options, self.args, file_list) self.assertEquals(file_list, []) self.assertEquals(scm.revinfo(options, self.args, None), '069c602044c5388d2d15c3f875b057c852003458')
def testUpdateLockedBreak(self): if not self.enabled: return options = self.Options() options.break_repo_locks = True scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_path = join(self.base_path, '.git', 'index.lock') with open(file_path, 'w'): pass scm.update(options, (), []) self.assertRegexpMatches(sys.stdout.getvalue(), "breaking lock.*\.git/index\.lock") self.assertFalse(os.path.exists(file_path)) sys.stdout.close()
def testStatus2New(self): if not self.enabled: return options = self.Options() expected_file_list = [] for f in ['a', 'b']: file_path = gclient_scm.os.path.join(self.base_path, f) open(file_path, 'a').writelines('touched\n') expected_file_list.extend([file_path]) scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.status(options, self.args, file_list) expected_file_list = [gclient_scm.os.path.join(self.base_path, x) for x in ['a', 'b']] self.assertEquals(sorted(file_list), expected_file_list)
def testUpdateUpdate(self): if not self.enabled: return options = self.Options() expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.update(options, (), file_list) self.assertEquals(file_list, expected_file_list) self.assertEquals(scm.revinfo(options, (), None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') self.checkstdout( '\n_____ . at refs/heads/master\n' 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n')
def testRevertModified(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.update(options, None, file_list) file_path = join(self.base_path, 'a') open(file_path, 'a').writelines('touched\n') file_list = [] scm.revert(options, self.args, file_list) self.assertEquals(file_list, [file_path]) file_list = [] scm.diff(options, self.args, file_list) self.assertEquals(file_list, []) self.assertEquals(scm.revinfo(options, self.args, None), 'a7142dc9f0009350b96a11f372b6ea658592aa95') sys.stdout.close()
def testUpdateUnstagedConflict(self): if not self.enabled: return options = self.Options() scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_path = join(self.base_path, 'b') open(file_path, 'w').writelines('conflict\n') try: scm.update(options, (), []) self.fail() except (gclient_scm.gclient_utils.Error, subprocess2.CalledProcessError): # The exact exception text varies across git versions so it's not worth # verifying it. It's fine as long as it throws. pass # Manually flush stdout since we can't verify it's content accurately across # git versions. sys.stdout.getvalue() sys.stdout.close()
def testStatus2New(self): if not self.enabled: return options = self.Options() expected_file_list = [] for f in ['a', 'b']: file_path = join(self.base_path, f) open(file_path, 'a').writelines('touched\n') expected_file_list.extend([file_path]) scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.status(options, self.args, file_list) expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] self.assertEquals(sorted(file_list), expected_file_list) self.checkstdout( ('\n________ running \'git diff --name-status ' '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\nM\tb\n') % join(self.root_dir, '.'))