Index: tests/git_common_test.py |
diff --git a/tests/git_common_test.py b/tests/git_common_test.py |
index 711543222734440c8b852ff3f3e6c284a7f5b489..4279b6c074eda6482e8059af7fee8cc345d7e0b2 100755 |
--- a/tests/git_common_test.py |
+++ b/tests/git_common_test.py |
@@ -63,6 +63,20 @@ class Support(GitCommonTestBase): |
def testMemoizeOneThreadsafe(self): |
self._testMemoizeOneBody(threadsafe=True) |
+ def testOnce(self): |
+ testlist = [] |
+ |
+ @self.gc.once |
+ def add_to_list(): |
+ testlist.append('dog') |
+ |
+ add_to_list() |
+ add_to_list() |
+ add_to_list() |
+ add_to_list() |
+ |
+ self.assertEquals(testlist, ['dog']) |
+ |
def slow_square(i): |
"""Helper for ScopedPoolTest. |
@@ -142,7 +156,7 @@ class ProgressPrinterTest(GitCommonTestBase): |
class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase, |
GitCommonTestBase): |
- REPO = """ |
+ REPO_SCHEMA = """ |
A B C D |
B E D |
""" |
@@ -207,7 +221,7 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase, |
def testBranches(self): |
self.assertEqual(self.repo.run(set, self.gc.branches()), |
- set(('branch_D', 'root_A'))) |
+ set(('master', 'branch_D', 'root_A'))) |
def testTags(self): |
self.assertEqual(set(self.repo.run(self.gc.tags)), |
@@ -279,7 +293,7 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase, |
class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase, |
GitCommonTestBase): |
- REPO = '' |
+ REPO_SCHEMA = '' |
def _intern_data(self, data): |
with tempfile.TemporaryFile() as f: |
@@ -311,6 +325,22 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase, |
self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), |
['food', 'cat']) |
+ self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) |
+ |
+ self.repo.run(self.gc.set_config, 'dude.bob', 'dog') |
+ |
+ self.assertEquals('dog', self.repo.run(self.gc.config, 'dude.bob', 'cat')) |
+ |
+ self.repo.run(self.gc.del_config, 'dude.bob') |
+ |
+ self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) |
+ |
+ self.assertEquals('origin/master', self.repo.run(self.gc.root)) |
+ |
+ self.repo.git('config', 'depot-tools.upstream', 'catfood') |
+ |
+ self.assertEquals('catfood', self.repo.run(self.gc.root)) |
+ |
def testUpstream(self): |
self.repo.git('commit', '--allow-empty', '-am', 'foooooo') |
self.assertEquals(self.repo.run(self.gc.upstream, 'bobly'), None) |
@@ -320,6 +350,157 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase, |
'master') |
+class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase, |
+ GitCommonTestBase): |
+ REPO_SCHEMA = """ |
+ A B C D E F G |
+ B H I J K |
+ J L |
+ |
+ X Y Z |
+ """ |
+ |
+ COMMIT_B = {'file': {'data': 'B'}} |
+ COMMIT_H = {'file': {'data': 'H'}} |
+ COMMIT_I = {'file': {'data': 'I'}} |
+ COMMIT_J = {'file': {'data': 'J'}} |
+ COMMIT_K = {'file': {'data': 'K'}} |
+ COMMIT_L = {'file': {'data': 'L'}} |
+ |
+ def setUp(self): |
+ super(GitMutableStructuredTest, self).setUp() |
+ self.repo.git('branch', '--set-upstream-to', 'root_X', 'branch_Z') |
+ self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K') |
+ self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L') |
+ self.repo.git('branch', '--set-upstream-to', 'root_A', 'branch_G') |
+ self.repo.git('branch', '--set-upstream-to', 'root_X', 'root_A') |
+ |
+ def testMergeBase(self): |
+ self.repo.git('checkout', 'branch_K') |
+ |
+ self.assertEqual( |
+ self.repo['B'], |
+ self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
+ ) |
+ |
+ self.assertEqual( |
+ self.repo['B'], self.repo.run(self.gc.config, 'branch.branch_K.base') |
+ ) |
+ |
+ # deadbeef is a bad hash, so this will result in repo['B'] |
+ self.repo.run(self.gc.manual_merge_base, 'branch_K', 'deadbeef') |
+ |
+ self.assertEqual( |
+ self.repo['B'], |
+ self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
+ ) |
+ |
+ # but if we pick a real ancestor, then it'll work |
+ self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['I']) |
+ |
+ self.assertEqual( |
+ self.repo['I'], |
+ self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
+ ) |
+ |
+ self.repo.run(self.gc.remove_merge_base, 'branch_K') |
+ |
+ self.assertEqual(None, |
+ self.repo.run(self.gc.config, 'branch.branch_K.base')) |
+ |
+ def testGetBranchTree(self): |
+ skipped, tree = self.repo.run(self.gc.get_branch_tree) |
+ self.assertEqual(skipped, ['master', 'root_X']) |
+ self.assertEqual(tree, { |
+ 'branch_G': 'root_A', |
+ 'root_A': 'root_X', |
+ 'branch_K': 'branch_G', |
+ 'branch_L': 'branch_K', |
+ 'branch_Z': 'root_X' |
+ }) |
+ |
+ topdown = list(self.gc.topo_iter(tree)) |
+ bottomup = list(self.gc.topo_iter(tree, top_down=False)) |
+ |
+ self.assertEqual(topdown, [ |
+ ('root_A', 'root_X'), |
+ ('branch_Z', 'root_X'), |
+ ('branch_G', 'root_A'), |
+ ('branch_K', 'branch_G'), |
+ ('branch_L', 'branch_K'), |
+ ]) |
+ |
+ self.assertEqual(bottomup, [ |
+ ('branch_L', 'branch_K'), |
+ ('branch_Z', 'root_X'), |
+ ('branch_K', 'branch_G'), |
+ ('branch_G', 'root_A'), |
+ ('root_A', 'root_X'), |
+ ]) |
+ |
+ def testSquashBranch(self): |
+ self.repo.git('checkout', 'branch_K') |
+ |
+ self.repo.run(self.gc.squash_current_branch, 'cool message') |
+ |
+ lines = ['cool message'] |
+ for l in 'HIJK': |
+ lines.extend((self.repo[l], l, '')) |
+ lines.pop() |
+ msg = '\n'.join(lines) |
+ |
+ self.assertEquals(self.repo.run(self.gc.run, 'log', '-n1', '--format=%B'), |
+ msg) |
+ |
+ self.assertEquals( |
+ self.repo.git('cat-file', 'blob', 'branch_K:file').stdout, |
+ 'K' |
+ ) |
+ |
+ def testRebase(self): |
+ before_raw = self.repo.git('rev-list', 'branch_K~4..branch_K') |
+ before = before_raw.stdout.splitlines() |
+ self.assertEquals(list(reversed(before)), [self.repo[l] for l in 'HIJK']) |
+ |
+ rslt = self.repo.run( |
+ self.gc.rebase, 'branch_G', 'branch_K~4', 'branch_K', ignore_date=True) |
+ self.assertTrue(rslt.success) |
+ |
+ after_raw = self.repo.git('rev-list', 'branch_K~4..branch_K') |
+ after = after_raw.stdout.splitlines() |
+ self.assertEquals( |
+ list(reversed(after)), |
+ [ |
+ 'b2868a2282fbce7abf08f1ed1589f80d459dbd4e', |
+ '64f3b5f10b7bf759f448f05933206780d698405e', |
+ '1aea9bdab53e5f8f8546ce4316090b06f5f7a88d', |
+ 'fbd3fde9849c3c0dcd984cce6a8fe336ef948271' |
+ ] |
+ ) |
+ |
+ rslt = self.repo.run( |
+ self.gc.rebase, 'branch_K', 'branch_L~1', 'branch_L', abort=True, |
+ ignore_date=True) |
+ self.assertFalse(rslt.success) |
+ |
+ self.assertFalse(self.repo.run(self.gc.in_rebase)) |
+ |
+ rslt = self.repo.run( |
+ self.gc.rebase, 'branch_K', 'branch_L~1', 'branch_L', abort=False, |
+ ignore_date=True) |
+ self.assertFalse(rslt.success) |
+ |
+ self.assertEqual(self.repo.git('status', '--porcelain').stdout, 'UU file\n') |
+ self.repo.git('checkout', '--theirs', 'file') |
+ self.repo.git('add', 'file') |
+ self.repo.git('rebase', '--continue', '--committer-date-is-author-date') |
+ |
+ self.assertEquals( |
+ self.repo.git('rev-parse', 'branch_L').stdout.strip(), |
+ '2c84f5091d4dd902084d91b9f37bae5a601c146e' |
+ ) |
+ |
+ |
if __name__ == '__main__': |
sys.exit(coverage_utils.covered_main( |
os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') |