Example #1
0
	def test_aggressive_tree_merge(self):
		# head tree with additions, removals and modification compared to its predecessor
		odb = self.rorepo.odb
		HC = self.rorepo.commit("6c1faef799095f3990e9970bc2cb10aa0221cf9c") 
		H = HC.tree
		B = HC.parents[0].tree
		
		# entries from single tree
		trees = [H.binsha]
		self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
		
		# from multiple trees
		trees = [B.binsha, H.binsha]
		self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
		
		# three way, no conflict
		tree = self.rorepo.tree
		B = tree("35a09c0534e89b2d43ec4101a5fb54576b577905")
		H = tree("4fe5cfa0e063a8d51a1eb6f014e2aaa994e5e7d4")
		M = tree("1f2b19de3301e76ab3a6187a49c9c93ff78bafbd")
		trees = [B.binsha, H.binsha, M.binsha]
		self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
		
		# three-way, conflict in at least one file, both modified
		B = tree("a7a4388eeaa4b6b94192dce67257a34c4a6cbd26")
		H = tree("f9cec00938d9059882bb8eabdaf2f775943e00e5")
		M = tree("44a601a068f4f543f73fd9c49e264c931b1e1652")
		trees = [B.binsha, H.binsha, M.binsha]
		self._assert_index_entries(aggressive_tree_merge(odb, trees), trees)
		
		# too many trees
		self.failUnlessRaises(ValueError, aggressive_tree_merge, odb, trees*2)
Example #2
0
	def test_three_way_merge(self, rwrepo):
		def mkfile(name, sha, executable=0):
			return (sha, S_IFREG | 0644 | executable*0111, name)
		def mkcommit(name, sha):
			return (sha, S_IFDIR | S_IFLNK, name)
		def assert_entries(entries, num_entries, has_conflict=False):
			assert len(entries) == num_entries
			assert has_conflict == (len([e for e in entries if e.stage != 0]) > 0)
		mktree = self.mktree
			
		shaa = "\1"*20
		shab = "\2"*20
		shac = "\3"*20
		
		odb = rwrepo.odb
		
		# base tree
		bfn = 'basefile'
		fbase = mkfile(bfn, shaa)
		tb = mktree(odb, [fbase])
		
		# non-conflicting new files, same data
		fa = mkfile('1', shab)
		th = mktree(odb, [fbase, fa])
		fb = mkfile('2', shac)
		tm = mktree(odb, [fbase, fb])
		
		# two new files, same base file
		trees = [tb, th, tm]
		assert_entries(aggressive_tree_merge(odb, trees), 3)
		
		# both delete same file, add own one
		fa = mkfile('1', shab)
		th = mktree(odb, [fa])
		fb = mkfile('2', shac)
		tm = mktree(odb, [fb])
		
		# two new files
		trees = [tb, th, tm]
		assert_entries(aggressive_tree_merge(odb, trees), 2)
		
		# same file added in both, differently
		fa = mkfile('1', shab)
		th = mktree(odb, [fa])
		fb = mkfile('1', shac)
		tm = mktree(odb, [fb])
		
		# expect conflict
		trees = [tb, th, tm]
		assert_entries(aggressive_tree_merge(odb, trees), 2, True)
		
		# same file added, different mode
		fa = mkfile('1', shab)
		th = mktree(odb, [fa])
		fb = mkcommit('1', shab)
		tm = mktree(odb, [fb])
		
		# expect conflict
		trees = [tb, th, tm]
		assert_entries(aggressive_tree_merge(odb, trees), 2, True)
		
		# same file added in both
		fa = mkfile('1', shab)
		th = mktree(odb, [fa])
		fb = mkfile('1', shab)
		tm = mktree(odb, [fb])
		
		# expect conflict
		trees = [tb, th, tm]
		assert_entries(aggressive_tree_merge(odb, trees), 1)
		
		# modify same base file, differently
		fa = mkfile(bfn, shab)
		th = mktree(odb, [fa])
		fb = mkfile(bfn, shac)
		tm = mktree(odb, [fb])
		
		# conflict, 3 versions on 3 stages
		trees = [tb, th, tm]
		assert_entries(aggressive_tree_merge(odb, trees), 3, True)
		
		
		# change mode on same base file, by making one a commit, the other executable
		# no content change ( this is totally unlikely to happen in the real world )
		fa = mkcommit(bfn, shaa)
		th = mktree(odb, [fa])
		fb = mkfile(bfn, shaa, executable=1)
		tm = mktree(odb, [fb])
		
		# conflict, 3 versions on 3 stages, because of different mode
		trees = [tb, th, tm]
		assert_entries(aggressive_tree_merge(odb, trees), 3, True)
		
		for is_them in range(2):
			# only we/they change contents
			fa = mkfile(bfn, shab)
			th = mktree(odb, [fa])
			
			trees = [tb, th, tb]
			if is_them:
				trees = [tb, tb, th]
			entries = aggressive_tree_merge(odb, trees)
			assert len(entries) == 1 and entries[0].binsha == shab
			
			# only we/they change the mode
			fa = mkcommit(bfn, shaa)
			th = mktree(odb, [fa])
			
			trees = [tb, th, tb]
			if is_them:
				trees = [tb, tb, th]
			entries = aggressive_tree_merge(odb, trees)
			assert len(entries) == 1 and entries[0].binsha == shaa and entries[0].mode == fa[1]
			
			# one side deletes, the other changes = conflict
			fa = mkfile(bfn, shab)
			th = mktree(odb, [fa])
			tm = mktree(odb, [])
			trees = [tb, th, tm]
			if is_them:
				trees = [tb, tm, th]
			# as one is deleted, there are only 2 entries
			assert_entries(aggressive_tree_merge(odb, trees), 2, True)