From 5de21c7fa2bdd5cd50c4f62ba848af54589167d0 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 12 Apr 2016 15:55:01 +0200 Subject: Support "root" as a special value in .diff() calls This enabled getting diff patches for root commits. --- git/test/test_diff.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'git/test/test_diff.py') diff --git a/git/test/test_diff.py b/git/test/test_diff.py index b0d98248..136e6fd9 100644 --- a/git/test/test_diff.py +++ b/git/test/test_diff.py @@ -128,6 +128,21 @@ class TestDiff(TestBase): assert res[0].deleted_file assert res[0].b_path == '' + def test_diff_initial_commit(self): + initial_commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') + + # Without creating a patch... + diff_index = initial_commit.diff('root') + assert diff_index[0].b_path == 'CHANGES' + assert diff_index[0].new_file + assert diff_index[0].diff == '' + + # ...and with creating a patch + diff_index = initial_commit.diff('root', create_patch=True) + assert diff_index[0].b_path == 'CHANGES' + assert diff_index[0].new_file + assert diff_index[0].diff == fixture('diff_initial') + def test_diff_patch_format(self): # test all of the 'old' format diffs for completness - it should at least # be able to deal with it @@ -149,7 +164,7 @@ class TestDiff(TestBase): diff_item = commit.tree # END use tree every second item - for other in (None, commit.Index, commit.parents[0]): + for other in (None, 'root', commit.Index, commit.parents[0]): for paths in (None, "CHANGES", ("CHANGES", "lib")): for create_patch in range(2): diff_index = diff_item.diff(other=other, paths=paths, create_patch=create_patch) -- cgit v1.2.1 From 1875885485e7c78d34fd56b8db69d8b3f0df830c Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Thu, 14 Apr 2016 15:55:21 +0200 Subject: Fix test cases --- git/test/test_diff.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'git/test/test_diff.py') diff --git a/git/test/test_diff.py b/git/test/test_diff.py index 136e6fd9..56e395fd 100644 --- a/git/test/test_diff.py +++ b/git/test/test_diff.py @@ -21,7 +21,8 @@ from git import ( Repo, GitCommandError, Diff, - DiffIndex + DiffIndex, + NULL_TREE, ) @@ -132,13 +133,13 @@ class TestDiff(TestBase): initial_commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') # Without creating a patch... - diff_index = initial_commit.diff('root') + diff_index = initial_commit.diff(NULL_TREE) assert diff_index[0].b_path == 'CHANGES' assert diff_index[0].new_file assert diff_index[0].diff == '' # ...and with creating a patch - diff_index = initial_commit.diff('root', create_patch=True) + diff_index = initial_commit.diff(NULL_TREE, create_patch=True) assert diff_index[0].b_path == 'CHANGES' assert diff_index[0].new_file assert diff_index[0].diff == fixture('diff_initial') @@ -164,7 +165,7 @@ class TestDiff(TestBase): diff_item = commit.tree # END use tree every second item - for other in (None, 'root', commit.Index, commit.parents[0]): + for other in (None, NULL_TREE, commit.Index, commit.parents[0]): for paths in (None, "CHANGES", ("CHANGES", "lib")): for create_patch in range(2): diff_index = diff_item.diff(other=other, paths=paths, create_patch=create_patch) -- cgit v1.2.1