def test_simple_merge(self): remotes = [{ 'name': 'r1', 'url': self.url_remote1 }, { 'name': 'r2', 'url': self.url_remote2 }] merges = [{ 'remote': 'r1', 'ref': 'tag1' }, { 'remote': 'r2', 'ref': self.commit_3_sha }] target = { 'remote': 'r1', 'branch': 'agg' } repo = Repo(self.cwd, remotes, merges, target) repo.aggregate() last_rev = git_get_last_rev(self.cwd) self.assertEqual(last_rev, self.commit_3_sha) # push repo.push() rtype, sha = repo.query_remote_ref('r1', 'agg') self.assertEquals(rtype, 'branch') self.assertTrue(sha)
def test_update_aggregate_2(self): # in this test # * we'll aggregate a first time r1 commit1 with r2 # at commit 3 # * create a new commit on r1 # aggregate again # the last change of r1 must not be in the aggregated branch remotes = [{ 'name': 'r1', 'url': self.url_remote1 }, { 'name': 'r2', 'url': self.url_remote2 }] merges = [{ 'remote': 'r1', 'ref': self.commit_1_sha }, { 'remote': 'r2', 'ref': self.commit_3_sha }] target = { 'remote': 'r1', 'branch': 'agg' } repo = Repo(self.cwd, remotes, merges, target) repo.aggregate() self.assertTrue(os.path.isfile(os.path.join(self.cwd, 'tracked'))) self.assertTrue(os.path.isfile(os.path.join(self.cwd, 'tracked2'))) git_write_commit( self.remote1, 'tracked_new', "last", msg="new file on remote1") repo.aggregate() self.assertFalse(os.path.isfile(os.path.join(self.cwd, 'tracked_new')))
def test_depth(self): """Ensure `depth` is used correctly.""" remotes = [{ 'name': 'r1', 'url': self.url_remote1 }, { 'name': 'r2', 'url': self.url_remote2 }] merges = [{ 'remote': 'r1', "ref": "master", }, { "remote": "r2", 'ref': "b2", }] target = {'remote': 'r1', 'branch': 'agg'} defaults = { "depth": 2, } repo = Repo(self.cwd, remotes, merges, target, defaults=defaults) repo.aggregate() self.assertTrue(os.path.isfile(os.path.join(self.cwd, 'tracked'))) self.assertTrue(os.path.isfile(os.path.join(self.cwd, 'tracked2'))) with working_directory_keeper: os.chdir(self.cwd) log_r1 = subprocess.check_output(("git", "rev-list", "r1/master")) log_r2 = subprocess.check_output(("git", "rev-list", "r2/b2")) # Shallow fetch: just 1 commmit self.assertEqual(len(log_r1.splitlines()), 2) # Full fetch: all 3 commits self.assertEqual(len(log_r2.splitlines()), 2)
def test_depth_1(self): """Ensure a simple shallow clone with 1 commit works.""" remotes = [{ 'name': 'shallow', 'url': self.url_remote1 }] merges = [{ 'remote': 'shallow', "ref": "master", }] target = { 'remote': 'shallow', 'branch': 'master' } defaults = { "depth": 1, } repo = Repo(self.cwd, remotes, merges, target, defaults=defaults) repo.aggregate() self.assertTrue(os.path.isfile(os.path.join(self.cwd, 'tracked'))) with working_directory_keeper: os.chdir(self.cwd) log_shallow = subprocess.check_output( ("git", "rev-list", "shallow/master")) # Shallow fetch: just 1 commmit self.assertEqual(len(log_shallow.splitlines()), 1)
def test_simple_merge_from_existing_git(self): # Launched from an existing git repository remotes = [{ 'name': 'r1', 'url': self.url_remote1 }, { 'name': 'r2', 'url': self.url_remote2 }] merges = [{ 'remote': 'r1', 'ref': 'tag1' }, { 'remote': 'r2', 'ref': self.commit_3_sha }] target = { 'remote': 'r1', 'branch': 'agg' } subprocess.call(['git', 'init', self.cwd]) repo = Repo(self.cwd, remotes, merges, target, fetch_all=True) repo.aggregate() last_rev = git_get_last_rev(self.cwd) self.assertEqual(last_rev, self.commit_3_sha) # push repo.push() rtype, ref, sha = list(repo.query_remote('r1', 'agg'))[0] self.assertEquals(rtype, 'branch') self.assertTrue(sha)
def test_minimal(self): remotes = [{'name': 'r1', 'url': self.url_remote1}] merges = [{'remote': 'r1', 'ref': 'tag1'}] target = {'remote': 'r1', 'branch': 'agg1'} repo = Repo(self.cwd, remotes, merges, target) repo.aggregate() last_rev = git_get_last_rev(self.cwd) self.assertEqual(last_rev, self.commit_1_sha)
def test_minimal(self): remotes = [{ 'name': 'r1', 'url': self.url_remote1 }] merges = [{ 'remote': 'r1', 'ref': 'tag1' }] target = { 'remote': 'r1', 'branch': 'agg1' } repo = Repo(self.cwd, remotes, merges, target) repo.aggregate() last_rev = git_get_last_rev(self.cwd) self.assertEqual(last_rev, self.commit_1_sha)
def test_force(self): """Ensure --force works fine.""" remotes = [{ 'name': 'r1', 'url': self.url_remote1 }] merges = [{ 'remote': 'r1', 'ref': 'tag1' }] target = { 'remote': 'r1', 'branch': 'agg1' } # Aggregate 1st time repo_noforce = Repo(self.cwd, remotes, merges, target) repo_noforce.aggregate() # Create a dummy file to set the repo dirty dummy_file = os.path.join(self.cwd, "dummy") with open(dummy_file, "a"): pass # Aggregate 2nd time, dirty, which should fail with self.assertRaises(exception.DirtyException): repo_noforce.aggregate() # Aggregate 3rd time, forcing, so it should work and remove that file repo_force = Repo(self.cwd, remotes, merges, target, force=True) repo_force.aggregate() self.assertFalse(os.path.exists(dummy_file))
def test_push_missing_remote(self): remotes = [{ 'name': 'r1', 'url': self.url_remote1 }, { 'name': 'r2', 'url': self.url_remote2 }] merges = [{ 'remote': 'r1', 'ref': 'tag1' }, { 'remote': 'r2', 'ref': self.commit_3_sha }] target = {'remote': None, 'branch': 'agg'} repo = Repo(self.cwd, remotes, merges, target, fetch_all=True) repo.aggregate() with self.assertRaises(exception.GitAggregatorException) as ex: repo.push() self.assertEquals(ex.exception.args[0], "Cannot push agg, no target remote configured")