| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 49 | 49 | If None, we will be compared to the working tree. | |
| 50 | 50 | If Treeish, it will be compared against the respective tree | |
| 51 | 51 | If Index ( type ), it will be compared against the index. | |
| 52 | + If the string 'root', it will compare the empty tree against this tree. | ||
| 52 | 53 | It defaults to Index to assure the method will not by-default fail | |
| 53 | 54 | on bare repositories. | |
| 54 | 55 | ||
@@ -87,10 +88,15 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 87 | 88 | if paths is not None and not isinstance(paths, (tuple, list)): | |
| 88 | 89 | paths = [paths] | |
| 89 | 90 | ||
| 90 | - if other is not None and other is not self.Index: | ||
| 91 | - args.insert(0, other) | ||
| 91 | + diff_cmd = self.repo.git.diff | ||
| 92 | 92 | if other is self.Index: | |
| 93 | - args.insert(0, "--cached") | ||
| 93 | + args.insert(0, '--cached') | ||
| 94 | + elif other == 'root': | ||
| 95 | + args.insert(0, '--root') | ||
| 96 | + diff_cmd = self.repo.git.diff_tree | ||
| 97 | + elif other is not None: | ||
| 98 | + args.insert(0, other) | ||
| 99 | + diff_cmd = self.repo.git.diff_tree | ||
| 94 | 100 | ||
| 95 | 101 | args.insert(0, self) | |
| 96 | 102 | ||
@@ -101,7 +107,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 101 | 107 | # END paths handling | |
| 102 | 108 | ||
| 103 | 109 | kwargs['as_process'] = True | |
| 104 | - proc = self.repo.git.diff(*self._process_diff_args(args), **kwargs) | ||
| 110 | + proc = diff_cmd(*self._process_diff_args(args), **kwargs) | ||
| 105 | 111 | ||
| 106 | 112 | diff_method = Diff._index_from_raw_format | |
| 107 | 113 | if create_patch: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + --- /dev/null | ||
| 2 | + +++ b/CHANGES | ||
| 3 | + @@ -0,0 +1,7 @@ | ||
| 4 | + +======= | ||
| 5 | + +CHANGES | ||
| 6 | + +======= | ||
| 7 | + + | ||
| 8 | + +0.1.0 | ||
| 9 | + +===== | ||
| 10 | + +initial release | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -128,6 +128,21 @@ def test_diff_index_raw_format(self): | |||
| 128 | 128 | assert res[0].deleted_file | |
| 129 | 129 | assert res[0].b_path == '' | |
| 130 | 130 | ||
| 131 | + def test_diff_initial_commit(self): | ||
| 132 | + initial_commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') | ||
| 133 | + | ||
| 134 | + # Without creating a patch... | ||
| 135 | + diff_index = initial_commit.diff('root') | ||
| 136 | + assert diff_index[0].b_path == 'CHANGES' | ||
| 137 | + assert diff_index[0].new_file | ||
| 138 | + assert diff_index[0].diff == '' | ||
| 139 | + | ||
| 140 | + # ...and with creating a patch | ||
| 141 | + diff_index = initial_commit.diff('root', create_patch=True) | ||
| 142 | + assert diff_index[0].b_path == 'CHANGES' | ||
| 143 | + assert diff_index[0].new_file | ||
| 144 | + assert diff_index[0].diff == fixture('diff_initial') | ||
| 145 | + | ||
| 131 | 146 | def test_diff_patch_format(self): | |
| 132 | 147 | # test all of the 'old' format diffs for completness - it should at least | |
| 133 | 148 | # be able to deal with it | |
@@ -149,7 +164,7 @@ def test_diff_interface(self): | |||
| 149 | 164 | diff_item = commit.tree | |
| 150 | 165 | # END use tree every second item | |
| 151 | 166 | ||
| 152 | - for other in (None, commit.Index, commit.parents[0]): | ||
| 167 | + for other in (None, 'root', commit.Index, commit.parents[0]): | ||
| 153 | 168 | for paths in (None, "CHANGES", ("CHANGES", "lib")): | |
| 154 | 169 | for create_patch in range(2): | |
| 155 | 170 | diff_index = diff_item.diff(other=other, paths=paths, create_patch=create_patch) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments