def setUp(self): super().setUp() name = 'git-source' # must match what the tests expect def _add_and_commit_file(path, filename, contents=None, message=None): if not contents: contents = filename if not message: message = filename with open(os.path.join(path, filename), 'w') as fp: fp.write(contents) call(['git', '-C', name, 'add', filename]) call(['git', '-C', name, 'commit', '-am', message]) os.makedirs(name) call(['git', '-C', name, 'init']) call(['git', '-C', name, 'config', 'user.name', 'Test User']) call([ 'git', '-C', name, 'config', 'user.email', '*****@*****.**' ]) _add_and_commit_file(name, 'testing') call(['git', '-C', name, 'branch', 'test-branch']) _add_and_commit_file(name, 'testing-2') call(['git', '-C', name, 'tag', 'feature-tag']) _add_and_commit_file(name, 'testing-3') self.commit = call_with_output( ['git', '-C', name, 'rev-parse', 'HEAD'])
def setUp(self): super().setUp() name = 'git-source' # must match what the tests expect def _add_and_commit_file(path, filename, contents=None, message=None): if not contents: contents = filename if not message: message = filename with open(os.path.join(path, filename), 'w') as fp: fp.write(contents) call(['git', '-C', name, 'add', filename]) call(['git', '-C', name, 'commit', '-am', message]) os.makedirs(name) call(['git', '-C', name, 'init']) call(['git', '-C', name, 'config', 'user.name', 'Test User']) call(['git', '-C', name, 'config', 'user.email', '*****@*****.**']) _add_and_commit_file(name, 'testing') call(['git', '-C', name, 'branch', 'test-branch']) _add_and_commit_file(name, 'testing-2') call(['git', '-C', name, 'tag', 'feature-tag']) _add_and_commit_file(name, 'testing-3') self.commit = call_with_output( ['git', '-C', name, 'rev-parse', 'HEAD'])
def setUp(self): super().setUp() self.working_tree = 'bzr-test' self.source_dir = 'bzr-checkout' os.mkdir(self.working_tree) os.mkdir(self.source_dir) os.chdir(self.working_tree) call(['bzr', 'init']) call(['bzr', 'whoami', 'Test User <*****@*****.**>']) with open('testing', 'w') as fp: fp.write('testing') call(['bzr', 'add', 'testing']) call(['bzr', 'commit', '-m', 'testing']) call(['bzr', 'tag', 'test-tag']) self.expected_commit = call_with_output(['bzr', 'revno', '.']) self.expected_tag = 'test-tag' os.chdir('..') self.bzr = sources.Bazaar(self.working_tree, self.source_dir, silent=True) self.bzr.pull() self.source_details = self.bzr._get_source_details()
def _add_and_commit_file(filename, content=None, message=None): if not content: content = filename if not message: message = filename with open(filename, 'w') as fp: fp.write(content) call(['git', 'add', filename]) call(['git', 'commit', '-am', message])
def _add_and_commit_file(filename, content=None, message=None): if not content: content = filename if not message: message = filename with open(filename, 'w') as fp: fp.write(content) call(['git', 'add', filename]) call(['git', 'commit', '-am', message])
def _add_and_commit_file(path, filename, contents=None, message=None): if not contents: contents = filename if not message: message = filename with open(os.path.join(path, filename), 'w') as fp: fp.write(contents) call(['git', '-C', name, 'add', filename]) call(['git', '-C', name, 'commit', '-am', message])
def _add_and_commit_file(path, filename, contents=None, message=None): if not contents: contents = filename if not message: message = filename with open(os.path.join(path, filename), 'w') as fp: fp.write(contents) call(['git', '-C', name, 'add', filename]) call(['git', '-C', name, 'commit', '-am', message])
def setUp(self): super().setUp() self.working_tree = 'hg-test' self.source_dir = 'hg-checkout' self.clean_dir(self.working_tree) self.clean_dir(self.source_dir) os.chdir(self.working_tree) call(['hg', 'init']) with open('testing', 'w') as fp: fp.write('testing') call(['hg', 'add', 'testing']) call(['hg', 'commit', '-m', 'testing', '-u', 'Test User <*****@*****.**>']) call(['hg', 'tag', '-u', 'test', 'test-tag']) self.expected_commit = call_with_output(['hg', 'id']).split()[0] self.expected_branch = call_with_output(['hg', 'branch']) self.expected_tag = 'test-tag' os.chdir('..') self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True) self.hg.pull() self.source_details = self.hg._get_source_details()
def setUp(self): super().setUp() self.working_tree = 'hg-test' self.source_dir = 'hg-checkout' self.clean_dir(self.working_tree) self.clean_dir(self.source_dir) os.chdir(self.working_tree) call(['hg', 'init']) with open('testing', 'w') as fp: fp.write('testing') call(['hg', 'add', 'testing']) call(['hg', 'commit', '-m', 'testing', '-u', 'Test User <*****@*****.**>']) call(['hg', 'tag', '-u', 'test', 'test-tag']) self.expected_commit = call_with_output(['hg', 'id']).split()[0] self.expected_branch = call_with_output(['hg', 'branch']) self.expected_tag = 'test-tag' os.chdir('..') self.hg = sources.Mercurial(self.working_tree, self.source_dir, silent=True) self.hg.pull() self.source_details = self.hg._get_source_details()
def setUp(self): super().setUp() with return_to_cwd(): os.makedirs(self.name) os.chdir(self.name) call(['bzr', 'init']) call(['bzr', 'whoami', 'Test User <*****@*****.**>']) with open('testing', 'w') as fp: fp.write('testing') call(['bzr', 'add', 'testing']) call(['bzr', 'commit', '-m', 'testing']) call(['bzr', 'tag', 'feature-tag']) revno = call_with_output(['bzr', 'revno']) self.commit = revno
def setUp(self): def _add_and_commit_file(filename, content=None, message=None): if not content: content = filename if not message: message = filename with open(filename, 'w') as fp: fp.write(content) call(['git', 'add', filename]) call(['git', 'commit', '-am', message]) super().setUp() self.working_tree = 'git-test' self.source_dir = 'git-checkout' self.clean_dir(self.working_tree) os.chdir(self.working_tree) call(['git', 'init']) call(['git', 'config', 'user.name', '"Example Dev"']) call(['git', 'config', 'user.email', '*****@*****.**']) _add_and_commit_file('testing') self.expected_commit = call_with_output( ['git', 'rev-parse', 'HEAD']) _add_and_commit_file('testing-2') call(['git', 'tag', 'test-tag']) self.expected_tag = 'test-tag' _add_and_commit_file('testing-3') self.expected_branch = 'test-branch' call(['git', 'branch', self.expected_branch]) os.chdir('..') self.git = sources.Git(self.working_tree, self.source_dir, silent=True, source_commit=self.expected_commit) self.git.pull() self.source_details = self.git._get_source_details()
def setUp(self): def _add_and_commit_file(filename, content=None, message=None): if not content: content = filename if not message: message = filename with open(filename, 'w') as fp: fp.write(content) call(['git', 'add', filename]) call(['git', 'commit', '-am', message]) super().setUp() self.working_tree = 'git-test' self.source_dir = 'git-checkout' self.clean_dir(self.working_tree) os.chdir(self.working_tree) call(['git', 'init']) call(['git', 'config', 'user.name', '"Example Dev"']) call(['git', 'config', 'user.email', '*****@*****.**']) _add_and_commit_file('testing') self.expected_commit = call_with_output( ['git', 'rev-parse', 'HEAD']) _add_and_commit_file('testing-2') call(['git', 'tag', 'test-tag']) self.expected_tag = 'test-tag' _add_and_commit_file('testing-3') self.expected_branch = 'test-branch' call(['git', 'branch', self.expected_branch]) os.chdir('..') self.git = sources.Git(self.working_tree, self.source_dir, silent=True, source_commit=self.expected_commit) self.git.pull() self.source_details = self.git._get_source_details()
def setUp(self): super().setUp() self.repo_tree = 'svn-repo' self.working_tree = 'svn-test' self.source_dir = 'svn-checkout' self.clean_dir(self.repo_tree) self.clean_dir(self.working_tree) call(['svnadmin', 'create', self.repo_tree]) self.clone_repo(self.repo_tree, self.working_tree) os.chdir(self.working_tree) self.add_file('testing', 'test body', 'test message') self.expected_commit = '1' os.chdir('..') self.svn = sources.Subversion(self.repo_tree, self.source_dir, silent=True) self.svn.pull() self.source_details = self.svn._get_source_details()
def clone_repo(self, repo, tree): self.clean_dir(tree) call(['git', 'clone', repo, tree]) os.chdir(tree) call(['git', 'config', '--local', 'user.name', '"Example Dev"']) call(['git', 'config', '--local', 'user.email', '*****@*****.**'])
def clone_repo(self, repo, tree): self.clean_dir(tree) call(['git', 'clone', repo, tree]) os.chdir(tree) call(['git', 'config', '--local', 'user.name', '"Example Dev"']) call(['git', 'config', '--local', 'user.email', '*****@*****.**'])
def setUp(self): super().setUp() with return_to_cwd(): os.makedirs(self.name) os.chdir(self.name) call(['hg', 'init']) with open('testing', 'w') as fp: fp.write('testing') call(['hg', 'add', 'testing']) call(['hg', 'commit', '-m', 'testing', '-u', 'Test User <*****@*****.**>']) call(['hg', 'tag', 'feature-tag', '-u', 'Test User <*****@*****.**>']) revno = call_with_output(['hg', 'id']).split()[0] self.commit = revno
def setUp(self): super().setUp() working_tree = 'svn-repo' call(['svnadmin', 'create', self.name]) call(['svn', 'checkout', 'file://{}'.format(os.path.join(os.getcwd(), self.name)), working_tree]) with return_to_cwd(): os.chdir(working_tree) with open('testing', 'w') as fp: fp.write('testing') call(['svn', 'add', 'testing']) call(['svn', 'commit', '-m', 'svn testing']) revno = '1' self.commit = revno
def setUp(self): super().setUp() working_tree = 'svn-repo' call(['svnadmin', 'create', self.name]) call(['svn', 'checkout', 'file://{}'.format(os.path.join(os.getcwd(), self.name)), working_tree]) with return_to_cwd(): os.chdir(working_tree) with open('testing', 'w') as fp: fp.write('testing') call(['svn', 'add', 'testing']) call(['svn', 'commit', '-m', 'svn testing']) revno = '1' self.commit = revno
def setUp(self): super().setUp() bzr_home = self.useFixture(fixtures.TempDir()).path self.useFixture(fixtures.EnvironmentVariable('BZR_HOME', bzr_home)) self.useFixture(fixtures.EnvironmentVariable( 'BZR_EMAIL', 'Test User <*****@*****.**>')) with return_to_cwd(): os.makedirs(self.name) os.chdir(self.name) call(['bzr', 'init']) with open('testing', 'w') as fp: fp.write('testing') call(['bzr', 'add', 'testing']) call(['bzr', 'commit', '-m', 'testing']) call(['bzr', 'tag', 'feature-tag']) revno = call_with_output(['bzr', 'revno']) self.commit = revno
def setUp(self): super().setUp() bzr_home = self.useFixture(fixtures.TempDir()).path self.useFixture(fixtures.EnvironmentVariable('BZR_HOME', bzr_home)) self.useFixture(fixtures.EnvironmentVariable( 'BZR_EMAIL', 'Test User <*****@*****.**>')) with return_to_cwd(): os.makedirs(self.name) os.chdir(self.name) call(['bzr', 'init']) with open('testing', 'w') as fp: fp.write('testing') call(['bzr', 'add', 'testing']) call(['bzr', 'commit', '-m', 'testing']) call(['bzr', 'tag', 'feature-tag']) revno = call_with_output(['bzr', 'revno']) self.commit = revno
def test_git_conflicts(self): repo = '/tmp/conflict-test.git' working_tree = '/tmp/git-conflict-test' conflicting_tree = '{}-conflict'.format(working_tree) git = sources.Git(repo, working_tree, silent=True) self.clean_dir(repo) self.clean_dir(working_tree) self.clean_dir(conflicting_tree) os.chdir(repo) call(['git', 'init', '--bare']) self.clone_repo(repo, working_tree) # check out the original repo self.clone_repo(repo, conflicting_tree) # add a file to the repo os.chdir(working_tree) self.add_file('fake', 'fake 1', 'fake 1') call(['git', 'push', repo]) git.pull() os.chdir(conflicting_tree) self.add_file('fake', 'fake 2', 'fake 2') call(['git', 'push', '-f', repo]) os.chdir(working_tree) git.pull() body = None with open(os.path.join(working_tree, 'fake')) as fp: body = fp.read() self.assertThat(body, Equals('fake 2'))
def test_git_conflicts(self): repo = '/tmp/conflict-test.git' working_tree = '/tmp/git-conflict-test' conflicting_tree = '{}-conflict'.format(working_tree) git = sources.Git(repo, working_tree, silent=True) self.clean_dir(repo) self.clean_dir(working_tree) self.clean_dir(conflicting_tree) os.chdir(repo) call(['git', 'init', '--bare']) self.clone_repo(repo, working_tree) # check out the original repo self.clone_repo(repo, conflicting_tree) # add a file to the repo os.chdir(working_tree) self.add_file('fake', 'fake 1', 'fake 1') call(['git', 'push', repo]) git.pull() os.chdir(conflicting_tree) self.add_file('fake', 'fake 2', 'fake 2') call(['git', 'push', '-f', repo]) os.chdir(working_tree) git.pull() body = None with open(os.path.join(working_tree, 'fake')) as fp: body = fp.read() self.assertEqual(body, 'fake 2')
def test_git_submodules(self): """Test that updates to submodules are pulled""" repo = '/tmp/submodules.git' sub_repo = '/tmp/subrepo' working_tree = '/tmp/git-submodules' working_tree_two = '{}-two'.format(working_tree) sub_working_tree = '/tmp/git-submodules-sub' git = sources.Git(repo, working_tree, silent=True) self.clean_dir(repo) self.clean_dir(sub_repo) self.clean_dir(working_tree) self.clean_dir(working_tree_two) self.clean_dir(sub_working_tree) os.chdir(sub_repo) call(['git', 'init', '--bare']) self.clone_repo(sub_repo, sub_working_tree) self.add_file('sub-file', 'sub-file', 'sub-file') call(['git', 'push', sub_repo]) os.chdir(repo) call(['git', 'init', '--bare']) self.clone_repo(repo, working_tree) call(['git', 'submodule', 'add', sub_repo]) call(['git', 'commit', '-am', 'added submodule']) call(['git', 'push', repo]) git.pull() self.check_file_contents( os.path.join(working_tree, 'subrepo', 'sub-file'), 'sub-file') # add a file to the repo os.chdir(sub_working_tree) self.add_file('fake', 'fake 1', 'fake 1') call(['git', 'push', sub_repo]) os.chdir(working_tree) git.pull() # this shouldn't cause any change self.check_file_contents( os.path.join(working_tree, 'subrepo', 'sub-file'), 'sub-file') self.assertFalse( os.path.exists(os.path.join(working_tree, 'subrepo', 'fake'))) # update the submodule self.clone_repo(repo, working_tree_two) call([ 'git', 'submodule', 'update', '--init', '--recursive', '--remote' ]) call(['git', 'add', 'subrepo']) call(['git', 'commit', '-am', 'updated submodule']) call(['git', 'push']) os.chdir(working_tree) git.pull() # new file should be there now self.check_file_contents( os.path.join(working_tree, 'subrepo', 'sub-file'), 'sub-file') self.check_file_contents(os.path.join(working_tree, 'subrepo', 'fake'), 'fake 1')
def clone_repo(self, repo, tree): self.clean_dir(tree) call(['hg', 'clone', repo, tree]) os.chdir(tree)
def add_file(self, filename, body, message): with open(filename, 'w') as fp: fp.write(body) call(['git', 'add', filename]) call(['git', 'commit', '-am', message])
def test_git_submodules(self): """Test that updates to submodules are pulled""" repo = '/tmp/submodules.git' sub_repo = '/tmp/subrepo' working_tree = '/tmp/git-submodules' working_tree_two = '{}-two'.format(working_tree) sub_working_tree = '/tmp/git-submodules-sub' git = sources.Git(repo, working_tree, silent=True) self.clean_dir(repo) self.clean_dir(sub_repo) self.clean_dir(working_tree) self.clean_dir(working_tree_two) self.clean_dir(sub_working_tree) os.chdir(sub_repo) call(['git', 'init', '--bare']) self.clone_repo(sub_repo, sub_working_tree) self.add_file('sub-file', 'sub-file', 'sub-file') call(['git', 'push', sub_repo]) os.chdir(repo) call(['git', 'init', '--bare']) self.clone_repo(repo, working_tree) call(['git', 'submodule', 'add', sub_repo]) call(['git', 'commit', '-am', 'added submodule']) call(['git', 'push', repo]) git.pull() self.check_file_contents(os.path.join(working_tree, 'subrepo', 'sub-file'), 'sub-file') # add a file to the repo os.chdir(sub_working_tree) self.add_file('fake', 'fake 1', 'fake 1') call(['git', 'push', sub_repo]) os.chdir(working_tree) git.pull() # this shouldn't cause any change self.check_file_contents(os.path.join(working_tree, 'subrepo', 'sub-file'), 'sub-file') self.assertFalse(os.path.exists(os.path.join(working_tree, 'subrepo', 'fake'))) # update the submodule self.clone_repo(repo, working_tree_two) call(['git', 'submodule', 'update', '--init', '--recursive', '--remote']) call(['git', 'add', 'subrepo']) call(['git', 'commit', '-am', 'updated submodule']) call(['git', 'push']) os.chdir(working_tree) git.pull() # new file should be there now self.check_file_contents(os.path.join(working_tree, 'subrepo', 'sub-file'), 'sub-file') self.check_file_contents(os.path.join(working_tree, 'subrepo', 'fake'), 'fake 1')
def add_file(self, filename, body, message): with open(filename, 'w') as fp: fp.write(body) call(['hg', 'add', filename]) call(['hg', 'commit', '-am', message])
def clone_repo(self, repo, tree): self.clean_dir(tree) call(['hg', 'clone', repo, tree]) os.chdir(tree)
def test_git_submodules(self): """Test that updates to submodules are pulled""" repo = '/tmp/submodules.git' sub_repo = '/tmp/subrepo' working_tree = '/tmp/git-submodules' sub_working_tree = '/tmp/git-submodules-sub' git = sources.Git(repo, working_tree, silent=True) self.clean_dir(repo) self.clean_dir(sub_repo) self.clean_dir(working_tree) self.clean_dir(sub_working_tree) os.chdir(sub_repo) call(['git', 'init', '--bare']) self.clone_repo(sub_repo, sub_working_tree) self.add_file('sub-file', 'sub-file', 'sub-file') call(['git', 'push', sub_repo]) os.chdir(repo) call(['git', 'init', '--bare']) self.clone_repo(repo, working_tree) call(['git', 'submodule', 'add', sub_repo]) call(['git', 'commit', '-am', 'added submodule']) call(['git', 'push', repo]) git.pull() self.check_file_contents( os.path.join(working_tree, 'subrepo', 'sub-file'), 'sub-file') # add a file to the repo os.chdir(sub_working_tree) self.add_file('fake', 'fake 1', 'fake 1') call(['git', 'push', sub_repo]) os.chdir(working_tree) git.pull() self.check_file_contents(os.path.join(working_tree, 'subrepo', 'fake'), 'fake 1')
def clone_repo(self, repo, tree): self.clean_dir(tree) call([ 'svn', 'checkout', 'file://{}/{}'.format(os.getcwd(), repo), tree ])