Exemplo n.º 1
0
 def test_empty(self):
     c1, c2, c3 = build_commit_graph(self.repo.object_store, [[1], [2, 1],
         [3, 1, 2]])
     self.repo.refs[b"HEAD"] = c3.id
     outstream = BytesIO()
     porcelain.diff_tree(self.repo.path, c2.tree, c3.tree, outstream=outstream)
     self.assertEqual(outstream.getvalue(), b"")
Exemplo n.º 2
0
def git_diff(args):
    '''prints diff of currently staged files to console.. '''
    repo=_get_repo()

    index=repo.repo.open_index()
    store=repo.repo.object_store
    index_sha=index.commit(store)
    #tree_ver=store[tree.lookup_path(store.peel_sha,file)[1]].data
    porcelain.diff_tree('.',repo[repo['HEAD'].tree].id,repo[index_sha].id, sys.stdout)
Exemplo n.º 3
0
Arquivo: git.py Projeto: zychen/stash
def git_diff(args):
    '''prints diff of currently staged files to console.. '''
    repo=_get_repo()

    index=repo.repo.open_index()
    store=repo.repo.object_store
    index_sha=index.commit(store)
    #tree_ver=store[tree.lookup_path(store.peel_sha,file)[1]].data
    porcelain.diff_tree('.',repo[repo['HEAD'].tree].id,repo[index_sha].id, sys.stdout)
Exemplo n.º 4
0
	def get_diff(self):
		#p.diff_tree(self.repo,)
		f = "README"
		tree_list = []
		w = self.repo.get_walker(paths=[f], max_entries=None)
		for i in iter(w):
			tree_list.append(i.commit.tree)
			print i.commit.tree
		print len(tree_list)

		p.diff_tree(self.repo, tree_list[0], tree_list[3])
Exemplo n.º 5
0
    def get_diff(self):
        #p.diff_tree(self.repo,)
        f = "README"
        tree_list = []
        w = self.repo.get_walker(paths=[f], max_entries=None)
        for i in iter(w):
            tree_list.append(i.commit.tree)
            print i.commit.tree
        print len(tree_list)

        p.diff_tree(self.repo, tree_list[0], tree_list[3])
Exemplo n.º 6
0
    def run(self, args):
        opts, args = getopt(args, "", [])

        r = Repo(".")
        if args == []:
            commit_id = b'HEAD'
        else:
            commit_id = args[0]
        commit = parse_commit(r, commit_id)
        parent_commit = r[commit.parents[0]]
        porcelain.diff_tree(
            r, parent_commit.tree, commit.tree, outstream=sys.stdout.buffer)
Exemplo n.º 7
0
    def _git_diff(self, sha_1, sha_2):
        """Produce the diff between sha1 & sha2

        :param sha_1: commit sha of "before" state
        :param sha_2: commit sha of "before" state
        """
        _repo = Repo(self.config['top_dir'])

        c_old = _repo.get_object(sha_1)
        c_new = _repo.get_object(sha_1)

        # default writes to stdout
        try:
            porcelain.diff_tree(_repo, c_old.tree, c_new.tree)
        except:
            raise GitMethodsError(message=exit_codes[6], exit_code=6)
Exemplo n.º 8
0
    def _git_diff(self, sha_1, sha_2):
        """Produce the diff between sha1 & sha2

        :param sha_1: commit sha of "before" state
        :param sha_2: commit sha of "before" state
        """
        _repo = Repo(self.config['top_dir'])

        c_old = _repo.get_object(sha_1)
        c_new = _repo.get_object(sha_1)

        # default writes to stdout
        try:
            porcelain.diff_tree(_repo, c_old.tree, c_new.tree)
        except:
            raise GitMethodsError(message=exit_codes[6], exit_code=6)
Exemplo n.º 9
0
	def get_diff(self):
		#p.diff_tree(self.repo,)
		f = self.current_file_name
		tree_list = []
		w = self.repo.get_walker(paths=[f], max_entries=None)
		a = []
		for i in iter(w):
			tree_list.append(i.commit.tree)
			#print i.commit.tree
			a.append(i.commit.tree)
		#print len(tree_list)
		for i in range(len(tree_list) - 1):
			#print "Diff between commits"
			a.append(p.diff_tree(self.repo, tree_list[i], tree_list[i+1]))
			print 
		return a
Exemplo n.º 10
0
 def run(self, args):
     opts, args = getopt(args, "", [])
     if len(args) < 2:
         print("Usage: dulwich diff-tree OLD-TREE NEW-TREE")
         sys.exit(1)
     porcelain.diff_tree(".", args[0], args[1])
Exemplo n.º 11
0
     print >> sys.stderr, commit
     decode = lambda x: commit_decode(entry.commit, x)
     porcelain.print_commit(commit, decode=decode)
 elif command == "diff-tree":
     """
     diff_tree(repo, old_tree, new_tree, outstream=sys.stdout):
     Compares the content and mode of blobs found via two tree objects.
     :param repo: Path to repository
     :param old_tree: Id of old tree
     :param new_tree: Id of new tree
     :param outstream: Stream to write to
     """
     print >> sys.stderr, "handle command diff-tree"
     print >> sys.stderr, "old tree: " + str(sys.argv[2])
     print >> sys.stderr, "new tree: " + str(sys.argv[3])
     porcelain.diff_tree(repoPath, sys.argv[2], sys.argv[3])
 elif command == "ls-tree":
     try:
         treeish = sys.argv[2]
     except IndexError:
         treeish = 'HEAD'  # fallback to HEAD
     print treeish
     porcelain.ls_tree(repoPath, treeish)
 elif command == "fetch":
     """
     def fetch(repo, remote_location, outstream=sys.stdout, errstream=default_bytes_err_stream):
     """
     print >> sys.stderr, "handle command fetch"
     porcelain.fetch(repoPath, remote)
 elif command == "ls-remote":
     print >> sys.stderr, "handle command ls-remote"
    def test_patch_apply(self):
        # Prepare the repository

        # Create some files and commit them
        file_list = ["to_exists", "to_modify", "to_delete"]
        for file in file_list:
            file_path = os.path.join(self.repo_path, file)

            # Touch the files
            with open(file_path, "w"):
                pass

        self.repo.stage(file_list)

        first_commit = self.repo.do_commit(b"The first commit")

        # Make a copy of the repository so we can apply the diff later
        copy_path = os.path.join(self.test_dir, "copy")
        shutil.copytree(self.repo_path, copy_path)

        # Do some changes
        with open(os.path.join(self.repo_path, "to_modify"), "w") as f:
            f.write("Modified!")

        os.remove(os.path.join(self.repo_path, "to_delete"))

        with open(os.path.join(self.repo_path, "to_add"), "w"):
            pass

        self.repo.stage(["to_modify", "to_delete", "to_add"])

        second_commit = self.repo.do_commit(b"The second commit")

        # Get the patch
        first_tree = self.repo[first_commit].tree
        second_tree = self.repo[second_commit].tree

        outstream = BytesIO()
        porcelain.diff_tree(self.repo.path, first_tree, second_tree,
                            outstream=outstream)

        # Save it on disk
        patch_path = os.path.join(self.test_dir, "patch.patch")
        with open(patch_path, "wb") as patch:
            patch.write(outstream.getvalue())

        # And try to apply it to the copy directory
        git_command = ["-C", copy_path, "apply", patch_path]
        run_git_or_fail(git_command)

        # And now check that the files contents are exactly the same between
        # the two repositories
        original_files = set(os.listdir(self.repo_path))
        new_files = set(os.listdir(copy_path))

        # Check that we have the exact same files in both repositories
        self.assertEqual(original_files, new_files)

        for file in original_files:
            if file == ".git":
                continue

            original_file_path = os.path.join(self.repo_path, file)
            copy_file_path = os.path.join(copy_path, file)

            self.assertTrue(os.path.isfile(copy_file_path))

            with open(original_file_path, "rb") as original_file:
                original_content = original_file.read()

            with open(copy_file_path, "rb") as copy_file:
                copy_content = copy_file.read()

            self.assertEqual(original_content, copy_content)
Exemplo n.º 13
0
    def test_patch_apply(self):
        # Prepare the repository

        # Create some files and commit them
        file_list = ["to_exists", "to_modify", "to_delete"]
        for file in file_list:
            file_path = os.path.join(self.repo_path, file)

            # Touch the files
            with open(file_path, "w"):
                pass

        self.repo.stage(file_list)

        first_commit = self.repo.do_commit(b"The first commit")

        # Make a copy of the repository so we can apply the diff later
        copy_path = os.path.join(self.test_dir, "copy")
        shutil.copytree(self.repo_path, copy_path)

        # Do some changes
        with open(os.path.join(self.repo_path, "to_modify"), "w") as f:
            f.write("Modified!")

        os.remove(os.path.join(self.repo_path, "to_delete"))

        with open(os.path.join(self.repo_path, "to_add"), "w"):
            pass

        self.repo.stage(["to_modify", "to_delete", "to_add"])

        second_commit = self.repo.do_commit(b"The second commit")

        # Get the patch
        first_tree = self.repo[first_commit].tree
        second_tree = self.repo[second_commit].tree

        outstream = BytesIO()
        porcelain.diff_tree(self.repo.path, first_tree, second_tree,
                            outstream=outstream)

        # Save it on disk
        patch_path = os.path.join(self.test_dir, "patch.patch")
        with open(patch_path, "wb") as patch:
            patch.write(outstream.getvalue())

        # And try to apply it to the copy directory
        git_command = ["-C", copy_path, "apply", patch_path]
        run_git_or_fail(git_command)

        # And now check that the files contents are exactly the same between
        # the two repositories
        original_files = set(os.listdir(self.repo_path))
        new_files = set(os.listdir(copy_path))

        # Check that we have the exact same files in both repositories
        self.assertEquals(original_files, new_files)

        for file in original_files:
            if file == ".git":
                continue

            original_file_path = os.path.join(self.repo_path, file)
            copy_file_path = os.path.join(copy_path, file)

            self.assertTrue(os.path.isfile(copy_file_path))

            with open(original_file_path, "rb") as original_file:
                original_content = original_file.read()

            with open(copy_file_path, "rb") as copy_file:
                copy_content = copy_file.read()

            self.assertEquals(original_content, copy_content)
Exemplo n.º 14
0
Arquivo: repo.py Projeto: tek/proteome
 def patch(self):
     return self._patch(
         lambda f:
         porcelain.diff_tree(self.repo.repo, self.parent, self.target, f)
     )