def multi_push(origin, run, checkpoint, mirrors, config, **_): config.update(path_extra_push={ 'mirrored_path': [mirrors['extra_mirror'].repo_path]}) master = origin['refs/heads/master'] mc = master.make_commit mc('first commit', {'unrelated': 'cowabunga'}) mc('next commit', { 'mirrored_path': { 'mirror_file': 'awesome sauce', 'some_other_file': 'neat', }, 'unrelated': 'other', 'unrelated_path': 'not helpful', }) master.make_commit('unrelated commit', { 'unrelated_path': 'helpful?', }) checkpoint('repo is set up') run() checkpoint('should see stuff') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/master') == { 'mirror_file': ('awesome sauce', 0644), 'some_other_file': ('neat', 0644), } assert GitEntry.spec_for(mirrors['extra_mirror'], 'refs/heads/master') == { 'mirror_file': ('awesome sauce', 0644), 'some_other_file': ('neat', 0644), }
def testToFirstParent(self): r = self.mkRepo() SK = r['refs/heads/branch_SK'] S, K = r['refs/heads/branch_S'], r['refs/heads/branch_K'] spec_S, spec_K = GitEntry.spec_for(r, S.ref), GitEntry.spec_for(r, K.ref) newTreeHsh = GitTree.from_spec( GitEntry.merge_specs(spec_S, spec_K)).intern(r) cd = data.CommitData( newTreeHsh, [S.commit.hsh, K.commit.hsh], S.commit.data.author, S.commit.data.committer, (), ["merge commit"], (), False) merge = r.get_commit(r.intern(cd, 'commit')) SK.update_to(merge) A = r['refs/heads/root_A'] self.assertEqual( list(c.hsh for c in A.to(SK)), [self.repo[c] for c in 'BCGDHILJMKNOPQRS'] + [merge.hsh] ) self.assertEqual( list(c.hsh for c in A.to(SK, first_parent=True)), [self.repo[c] for c in 'BCDLMNOPQRS'] + [merge.hsh] )
def merge_commit(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mc = master.make_commit mc('main 1', {'mirrored_path': {'some_file': 'data'}}) master_head = mc('main 2', {'mirrored_path': {'some_file': 'data2'}}) mc = origin['refs/heads/other'].make_commit other_head = mc('other 1', {'mirrored_path': {'other_file': 'something'}}) # do a crappy merge commit. this logic should probably be on TestRepo at some # point, but merge commits are pretty rare so keep it here until the next # person needs to do this. tree_hsh = GitEntry.from_spec(GitEntry.merge_specs( origin.spec_for(master_head), origin.spec_for(other_head), )).intern(origin) user = master_head.data.author commit = origin.get_commit(origin.intern(data.CommitData( tree_hsh, [master_head.hsh, other_head.hsh], user, user, (), ["squish"], (), False ), 'commit')) master.fast_forward(commit) checkpoint('setup') run() checkpoint('should not see `other 1` in subtree mirror') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/master') == { 'some_file': ('data2', 0644), 'other_file': ('something', 0644), }
def multi_push(origin, run, checkpoint, mirrors, config, **_): config.update( path_extra_push={'mirrored_path': [mirrors['extra_mirror'].repo_path]}) master = origin['refs/heads/master'] mc = master.make_commit mc('first commit', {'unrelated': 'cowabunga'}) mc( 'next commit', { 'mirrored_path': { 'mirror_file': 'awesome sauce', 'some_other_file': 'neat', }, 'unrelated': 'other', 'unrelated_path': 'not helpful', }) master.make_commit('unrelated commit', { 'unrelated_path': 'helpful?', }) checkpoint('repo is set up') run() checkpoint('should see stuff') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/master') == { 'mirror_file': ('awesome sauce', 0644), 'some_other_file': ('neat', 0644), } assert GitEntry.spec_for(mirrors['extra_mirror'], 'refs/heads/master') == { 'mirror_file': ('awesome sauce', 0644), 'some_other_file': ('neat', 0644), }
def merge_commit(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mc = master.make_commit mc('main 1', {'mirrored_path': {'some_file': 'data'}}) master_head = mc('main 2', {'mirrored_path': {'some_file': 'data2'}}) mc = origin['refs/heads/other'].make_commit other_head = mc('other 1', {'mirrored_path': {'other_file': 'something'}}) # do a crappy merge commit. this logic should probably be on TestRepo at some # point, but merge commits are pretty rare so keep it here until the next # person needs to do this. tree_hsh = GitEntry.from_spec( GitEntry.merge_specs( origin.spec_for(master_head), origin.spec_for(other_head), )).intern(origin) user = master_head.data.author commit = origin.get_commit( origin.intern( data.CommitData(tree_hsh, [master_head.hsh, other_head.hsh], user, user, (), ["squish"], (), False), 'commit')) master.fast_forward(commit) checkpoint('setup') run() checkpoint('should not see `other 1` in subtree mirror') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/master') == { 'some_file': ('data2', 0644), 'other_file': ('something', 0644), }
def evolving_deps_single(f): """Dependencies evolve within the time span of a single invocation.""" deps1 = textwrap.dedent("""\ deps = { "fount/foo": "https://itdoesntmatter.com/xyzzy/foo@10803d79ece6d8752be370163d342030a816cb8f", } """) tree = {'DEPS': deps1, 'other': {'greeting.txt': 'Hello, world!'}} f.make_commit('first', tree) deps2 = textwrap.dedent("""\ deps = { "fount/foo": "https://itdoesntmatter.com/xyzzy/foo@4ebc8aea50e0a67e000ba29a30809d0a7b9b2666", "fount/bar": "https://chromium.googlesource.com/bar@05c319264387a6c782f10c5e27e602ee36f98d0f", } """) tree['DEPS'] = deps2 f.make_commit('second', tree) f.checkpoint('before') f.run() result_tree = GitEntry.spec_for(f.target, MASTER) gitmodules_file = result_tree.get('.gitmodules')[0] gitlinks = [result_tree.get(name) for name in ('foo', 'bar')] f.checkpoint('after', gitmodules_file, gitlinks)
def multiple_runs(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] other = origin['refs/heads/other'] mc = master.make_commit oc = other.make_commit mc('nerd_commit', {'mirrored_path': {'sweet subfile': 'nerds'}}) oc('what_commit', { 'mirrored_path': { 'sweet subfile': 'what', 'subpath': { 'nested': 'data in a subdir!?'}}}) checkpoint('all set up') run() checkpoint('lots refs') spec = GitEntry.spec_for(mirrors['mirrored_path/subpath'], 'refs/heads/other') assert spec == { 'nested': ('data in a subdir!?', 0644) } mc('new_commit', {'mirrored_path': {'whatpath': {'nested': 'datas'}}}) checkpoint('added new_commit') run() checkpoint('should gain new synthed commit')
def fix_footers(origin, run, checkpoint, mirrors, **_): branch = origin['refs/heads/branch'] branch.make_commit( 'sweet commit', {'mirrored_path': {'sweet': 'totally!'}}, OrderedDict([ ('git-svn-id', ['totally annoying!']), ('Cr-Commit-Position', ['refs/heads/branch@{#12345}']), ('Commit-Id', ['whaaat']), ('Cr-Branched-From', ['deadbeef-refs/heads/master@{#12300}']), ])) checkpoint('a really sweet commit') run() checkpoint('a really sweet (mirrored) commit') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/branch') == { 'sweet': ('totally!', 0644) } footers = mirrors['mirrored_path']['refs/heads/branch'].commit.data.footers assert thaw(footers) == OrderedDict([ ('Commit-Id', ['whaaat']), ('Cr-Original-Commit-Position', ['refs/heads/branch@{#12345}']), ('Cr-Original-Branched-From', ['deadbeef-refs/heads/master@{#12300}']), ('Cr-Mirrored-From', ['[FILE-URL]']), ('Cr-Mirrored-Commit', ['b404e807c89d3b8f4b255fec1aaa9e123808f63c']), ])
def bootstrap_history_with_extra_footers(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mirrored_path_repo = mirrors['mirrored_path'] mirrored_path = mirrored_path_repo['refs/heads/master'] mc = master.make_commit mpc = mirrored_path.make_commit initial = mc('initial commit', {'mirrored_path': {'file': 'data'}}) mc('second commit', {'mirrored_path': {'other': 'hat'}}) mpc('initial commit', {'file': 'data'}) # Deterministically create note commit mirrored_path_repo['refs/notes/extra_footers'].make_commit( 'Notes added by \'git notes add\'', {mirrored_path.commit.hsh: 'Cr-Mirrored-Commit: %s' % initial.hsh}) checkpoint('mirrored_path repo bootstrapped') run() checkpoint('mirrored_path repo should have second commit') assert GitEntry.spec_for(mirrored_path_repo, 'refs/heads/master') == { 'file': ('data', 0644), 'other': ('hat', 0644) }
def bootstrap_history_with_extra_footers(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mirrored_path_repo = mirrors['mirrored_path'] mirrored_path = mirrored_path_repo['refs/heads/master'] mc = master.make_commit mpc = mirrored_path.make_commit initial = mc('initial commit', {'mirrored_path': {'file': 'data'}}) mc('second commit', {'mirrored_path': {'other': 'hat'}}) mpc('initial commit', {'file': 'data'}) # Deterministically create note commit mirrored_path_repo['refs/notes/extra_footers'].make_commit( 'Notes added by \'git notes add\'', {mirrored_path.commit.hsh: 'Cr-Mirrored-Commit: %s' % initial.hsh} ) checkpoint('mirrored_path repo bootstrapped') run() checkpoint('mirrored_path repo should have second commit') assert GitEntry.spec_for(mirrored_path_repo, 'refs/heads/master') == { 'file': ('data', 0644), 'other': ('hat', 0644) }
def fix_footers(origin, run, checkpoint, mirrors, **_): branch = origin['refs/heads/branch'] branch.make_commit( 'sweet commit', {'mirrored_path': { 'sweet': 'totally!' }}, OrderedDict([ ('git-svn-id', ['totally annoying!']), ('Cr-Commit-Position', ['refs/heads/branch@{#12345}']), ('Commit-Id', ['whaaat']), ('Cr-Branched-From', ['deadbeef-refs/heads/master@{#12300}']), ])) checkpoint('a really sweet commit') run() checkpoint('a really sweet (mirrored) commit') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/branch') == { 'sweet': ('totally!', 0644) } footers = mirrors['mirrored_path']['refs/heads/branch'].commit.data.footers assert thaw(footers) == OrderedDict([ ('Commit-Id', ['whaaat']), ('Cr-Original-Commit-Position', ['refs/heads/branch@{#12345}']), ('Cr-Original-Branched-From', ['deadbeef-refs/heads/master@{#12300}']), ('Cr-Mirrored-From', ['[FILE-URL]']), ('Cr-Mirrored-Commit', ['b404e807c89d3b8f4b255fec1aaa9e123808f63c']), ])
def multiple_runs(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] other = origin['refs/heads/other'] mc = master.make_commit oc = other.make_commit mc('nerd_commit', {'mirrored_path': {'sweet subfile': 'nerds'}}) oc( 'what_commit', { 'mirrored_path': { 'sweet subfile': 'what', 'subpath': { 'nested': 'data in a subdir!?' } } }) checkpoint('all set up') run() checkpoint('lots refs') spec = GitEntry.spec_for(mirrors['mirrored_path/subpath'], 'refs/heads/other') assert spec == {'nested': ('data in a subdir!?', 0644)} mc('new_commit', {'mirrored_path': {'whatpath': {'nested': 'datas'}}}) checkpoint('added new_commit') run() checkpoint('should gain new synthed commit')
def removed(f): # pragma: no cover """Last remaining dep is removed.""" deps1 = textwrap.dedent("""\ deps = { "abc/def": "https://chromium.googlesource.com/xyz/foo@5d0be3947e7e238f38516eddbe286a61d3ec4bc9", "fount/foo": "https://chromoium.googlesource.com/xyz/bar@10803d79ece6d8752be370163d342030a816cb8f", } """) f.make_commit('initial commit', { 'DEPS': deps1, 'subdir': { 'bar': 'Hello, world' } }) f.checkpoint('before') f.run() deps2 = textwrap.dedent("""\ deps = { "abc/def": "https://chromium.googlesource.com/xyz/foo@5d0be3947e7e238f38516eddbe286a61d3ec4bc9", } """) f.make_commit('subsequent commit', { 'DEPS': deps2, 'subdir': { 'bar': 'Hello, world' } }) f.run() tree = GitEntry.spec_for(f.target, MASTER) assert not tree.get('.gitmodules') assert not tree.get('foo') f.checkpoint('after')
def hello_world(f): f.make_commit('first commit', {'abc': 'xyzzy'}) f.checkpoint('b4') f.run() f.checkpoint('after') assert GitEntry.spec_for(f.target, MASTER) == { 'abc': ('xyzzy', 0644), }
def path_map_exceptions(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mc = master.make_commit mc('first commit', {'exception': {'path': {'file': 'cowabunga'}}}) checkpoint('repo is set up') run() checkpoint('should see stuff') assert GitEntry.spec_for(mirrors['cool_path'], 'refs/heads/master') == { 'file': ('cowabunga', 0644), }
def deleted_tree_is_ok(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mc = master.make_commit mc('first commit', {'mirrored_path': {'file': 'data'}}) mc('revert first commit', {'mirrored_path': None}) mc('first commit again', {'mirrored_path': {'file': 'new data'}}) checkpoint('repo is set up') run() checkpoint('should see stuff') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/master') == { 'file': ('new data', 0644), }
def evolving_deps(f): """Dependencies which evolve over time, across separate calls.""" # Initially, just one dep. deps1 = textwrap.dedent("""\ deps = { "fount/foo": "https://itdoesntmatter.com/xyzzy/foo@10803d79ece6d8752be370163d342030a816cb8f", } """) tree = {'DEPS': deps1, 'other': {'greeting.txt': 'Hello, world!'}} f.make_commit('first', tree) tree['other']['README'] = '... (a file we added in the 2nd commit)' f.make_commit('second', tree) f.checkpoint('before') f.run() result_tree = GitEntry.spec_for(f.target, MASTER) gitmodules_file = result_tree.get('.gitmodules')[0] gitlinks = [result_tree.get(name) for name in ('foo', )] f.checkpoint('during', gitmodules_file, gitlinks) # Later, the "foo" dep has had its pinned SHA-1 modified, and a new # dep "bar" has been introduced. deps2 = textwrap.dedent("""\ deps = { "fount/foo": "https://itdoesntmatter.com/xyzzy/foo@4ebc8aea50e0a67e000ba29a30809d0a7b9b2666", "fount/bar": "https://chromium.googlesource.com/bar@05c319264387a6c782f10c5e27e602ee36f98d0f", } """) tree['DEPS'] = deps2 f.make_commit('third', tree) f.run() result_tree = GitEntry.spec_for(f.target, MASTER) gitmodules_file = result_tree.get('.gitmodules')[0] gitlinks = [result_tree.get(name) for name in ('foo', 'bar')] f.checkpoint('after', gitmodules_file, gitlinks)
def testToFirstParent(self): r = self.mkRepo() SK = r['refs/heads/branch_SK'] S, K = r['refs/heads/branch_S'], r['refs/heads/branch_K'] spec_S, spec_K = GitEntry.spec_for(r, S.ref), GitEntry.spec_for(r, K.ref) newTreeHsh = GitTree.from_spec(GitEntry.merge_specs(spec_S, spec_K)).intern(r) cd = data.CommitData(newTreeHsh, [S.commit.hsh, K.commit.hsh], S.commit.data.author, S.commit.data.committer, (), ["merge commit"], (), False) merge = r.get_commit(r.intern(cd, 'commit')) SK.update_to(merge) A = r['refs/heads/root_A'] self.assertEqual(list(c.hsh for c in A.to(SK)), [self.repo[c] for c in 'BCGDHILJMKNOPQRS'] + [merge.hsh]) self.assertEqual(list(c.hsh for c in A.to(SK, first_parent=True)), [self.repo[c] for c in 'BCDLMNOPQRS'] + [merge.hsh])
def mirrored_path_is_a_file(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mc = master.make_commit mc('first commit', {'unrelated': 'cowabunga'}) mc('bad subtree', {'mirrored_path': 'it\'s a file!!'}) mc('but now it\'s OK', {'mirrored_path': {'silly': 'data'}}) mc('now it\'s a file again', {'mirrored_path': 'fail!'}) mc('back to a dir', {'mirrored_path': {'what what': 'datars!'}}) checkpoint('repo is set up') run() checkpoint('should see 2 commits in synthesized') assert GitEntry.spec_for(mirrors['mirrored_path'], 'refs/heads/master') == { 'what what': ('datars!', 0644) }
def bootstrap_fails_without_footer(origin, run, checkpoint, mirrors, **_): master = origin['refs/heads/master'] mirrored_path_repo = mirrors['mirrored_path'] mirrored_path = mirrored_path_repo['refs/heads/master'] mc = master.make_commit mpc = mirrored_path.make_commit mc('initial commit', {'mirrored_path': {'file': 'data'}}) mc('second commit', {'mirrored_path': {'other': 'hat'}}) mpc('initial commit', {'file': 'data'}) checkpoint('mirrored_path repo bootstrapped') run() checkpoint('mirrored_path repo should not have changed') assert GitEntry.spec_for(mirrored_path_repo, 'refs/heads/master') == { 'file': ('data', 0644), }
def git_suffix(f): """Names the origin repo in the xxx.git format.""" f._init_origin('fount.git') deps_file_content = textwrap.dedent("""\ deps = { "fount/foo": "https://chromoium.googlesource.com/xyz/bar@10803d79ece6d8752be370163d342030a816cb8f", } """) f.make_commit('initial commit', { 'DEPS': deps_file_content, 'in': { 'bar': 'Hello, world' } }) f.checkpoint('before') f.run() tree = GitEntry.spec_for(f.target, MASTER) gitmodules_file = tree.get('.gitmodules')[0] gitlink = tree.get('foo') f.checkpoint('after', gitmodules_file, gitlink)
def primitive_deps_file(f): # https://stackoverflow.com/a/1412728/98761 discusses textwrap.dedent() # deps_file_content = textwrap.dedent("""\ deps = { "abc/def": "https://chromium.googlesource.com/xyz/foo@5d0be3947e7e238f38516eddbe286a61d3ec4bc9", "fount/foo": "https://chromoium.googlesource.com/xyz/bar@10803d79ece6d8752be370163d342030a816cb8f", } """) f.make_commit('initial commit', { 'DEPS': deps_file_content, 'in': { 'bar': 'Hello, world' } }) f.checkpoint('before') f.run() tree = GitEntry.spec_for(f.target, MASTER) gitmodules_file = tree.get('.gitmodules')[0] gitlink = tree.get('foo') f.checkpoint('after', gitmodules_file, gitlink)
def gitlink_in_subdir(f): deps_file_content = textwrap.dedent("""\ deps = { "fount/abc/pqr/wow": "http://chromium.googlesource.com/bar@4ebc8aea50e0a67e000ba29a30809d0a7b9b2666", "fount/ghi/aaa": "https://chromium.googlesource.com/yin@6ec0d686a7cd65baf620184617df1ed0f2828af3", "fount/abc/trl": "https://chromium.googlesource.com/foo@d020324450627468418945e0c7e53c0a141a3ab9", "fount/abc/def": "https://chromium.googlesource.com/foo@74bb638f337e6a79756595fae31737a8411a494b", "fount/ghi/zyx/deep": "https://chromium.googlesource.com/yin@da98e07bfc76bb53b8414656295e9b7ce9c00096", } """) f.make_commit('initial commit', { 'DEPS': deps_file_content, 'in': { 'bar': 'Hello, world' } }) f.checkpoint('before') f.run() tree = GitEntry.spec_for(f.target, MASTER) gitmodules_file = tree.get('.gitmodules')[0] subdir1 = tree.get('abc') subdir2 = tree.get('ghi') f.checkpoint('after', gitmodules_file, ('abc', subdir1), ('ghi', subdir2))