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_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_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_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 _bootstrap(self, args): """ Bootstrap the git repositories using git aggregator """ # Mostly adapted from the git aggregator main module with integration # into the dob structure jobs = max(args.jobs, 1) threads = [] sem = threading.Semaphore(jobs) err_queue = Queue() default = self.get(base.SECTION, "repo", default={}) repos = { key: utils.merge(default, value, replace=["merges"]) for key, value in self.get("repos", default={}).items() } for repo_dict in get_repos(repos, args.force): if not err_queue.empty(): break sem.acquire() r = Repo(**repo_dict) tname = os.path.basename(repo_dict["cwd"]) if jobs > 1: t = threading.Thread( target=aggregate_repo, args=(r, args, sem, err_queue), ) t.daemon = True t.name = tname threads.append(t) t.start() else: with ThreadNameKeeper(): threading.current_thread().name = tname aggregate_repo(r, args, sem, err_queue) for t in threads: t.join() if not err_queue.empty(): while True: try: exc_type, exc_obj, exc_trace = err_queue.get_nowait() except Empty: break traceback.print_exception(exc_type, exc_obj, exc_trace) return 1
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")