@@ -40,11 +40,10 @@ <h1 class="title">Module <code>continuous_delivery_scripts.utils.git_helpers</co
4040import os
4141import re
4242import shutil
43- from pathlib import Path
44- from typing import Optional, List, Union, Any, Tuple
45-
4643from git import Repo, Actor, GitCommandError
4744from packaging import version
45+ from pathlib import Path
46+ from typing import Optional, List, Union, Any, Tuple
4847
4948from .configuration import configuration, ConfigurationVariable
5049from .filesystem_helpers import TemporaryDirectory
@@ -434,7 +433,13 @@ <h1 class="title">Module <code>continuous_delivery_scripts.utils.git_helpers</co
434433 return self.get_remote_branch(branch_name) is not None
435434
436435 def _get_specific_changes(self, change_type: Optional[str], commit1: Any, commit2: Any) -> List[str]:
437- diff = commit1.diff(commit2)
436+ diff = None
437+ if commit1:
438+ diff = commit1.diff(commit2) if commit2 else commit1.diff()
439+ elif commit2:
440+ diff = commit2.diff()
441+ if not diff:
442+ return []
438443 if change_type:
439444 change_type = change_type.upper()
440445 change_type = change_type if change_type in diff.change_type else None
@@ -580,6 +585,14 @@ <h1 class="title">Module <code>continuous_delivery_scripts.utils.git_helpers</co
580585 logger.warning(e)
581586 return None
582587
588+ def list_files_added_to_current_commit(self) -> List[str]:
589+ """Returns a list of files added in the current commit."""
590+ current_commit = self.repo.head.commit
591+ previous_commit = self.repo.commit("HEAD~1")
592+ if not current_commit:
593+ current_commit = self.get_current_commit()
594+ return self.get_changes_list(previous_commit, current_commit, change_type="a")
595+
583596 def list_files_added_on_current_branch(self) -> List[str]:
584597 """Returns a list of files changed against master branch."""
585598 master_branch = self.get_master_branch()
@@ -598,8 +611,7 @@ <h1 class="title">Module <code>continuous_delivery_scripts.utils.git_helpers</co
598611 # The branch point off `beta` is more recent than off `master`.
599612 # Hence, the difference between current and `beta` should be considered.
600613 branch_point = beta_branch_point
601- changes = self.get_changes_list(branch_point, current_branch_commit, change_type="a")
602- return changes
614+ return self.get_changes_list(branch_point, current_branch_commit, change_type="a")
603615
604616 def is_current_branch_feature(self) -> bool:
605617 """Returns boolean indicating if current branch is considered a feature."""
@@ -1012,6 +1024,7 @@ <h3>Inherited members</h3>
10121024< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.is_release_branch " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.is_release_branch "> is_release_branch</ a > </ code > </ li >
10131025< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_branches " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_branches "> list_branches</ a > </ code > </ li >
10141026< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_on_current_branch " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_on_current_branch "> list_files_added_on_current_branch</ a > </ code > </ li >
1027+ < li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_to_current_commit " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_to_current_commit "> list_files_added_to_current_commit</ a > </ code > </ li >
10151028< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge "> merge</ a > </ code > </ li >
10161029< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull "> pull</ a > </ code > </ li >
10171030< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull_all " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull_all "> pull_all</ a > </ code > </ li >
@@ -1484,7 +1497,13 @@ <h2 id="args">Args</h2>
14841497 return self.get_remote_branch(branch_name) is not None
14851498
14861499 def _get_specific_changes(self, change_type: Optional[str], commit1: Any, commit2: Any) -> List[str]:
1487- diff = commit1.diff(commit2)
1500+ diff = None
1501+ if commit1:
1502+ diff = commit1.diff(commit2) if commit2 else commit1.diff()
1503+ elif commit2:
1504+ diff = commit2.diff()
1505+ if not diff:
1506+ return []
14881507 if change_type:
14891508 change_type = change_type.upper()
14901509 change_type = change_type if change_type in diff.change_type else None
@@ -1630,6 +1649,14 @@ <h2 id="args">Args</h2>
16301649 logger.warning(e)
16311650 return None
16321651
1652+ def list_files_added_to_current_commit(self) -> List[str]:
1653+ """Returns a list of files added in the current commit."""
1654+ current_commit = self.repo.head.commit
1655+ previous_commit = self.repo.commit("HEAD~1")
1656+ if not current_commit:
1657+ current_commit = self.get_current_commit()
1658+ return self.get_changes_list(previous_commit, current_commit, change_type="a")
1659+
16331660 def list_files_added_on_current_branch(self) -> List[str]:
16341661 """Returns a list of files changed against master branch."""
16351662 master_branch = self.get_master_branch()
@@ -1648,8 +1675,7 @@ <h2 id="args">Args</h2>
16481675 # The branch point off `beta` is more recent than off `master`.
16491676 # Hence, the difference between current and `beta` should be considered.
16501677 branch_point = beta_branch_point
1651- changes = self.get_changes_list(branch_point, current_branch_commit, change_type="a")
1652- return changes
1678+ return self.get_changes_list(branch_point, current_branch_commit, change_type="a")
16531679
16541680 def is_current_branch_feature(self) -> bool:
16551681 """Returns boolean indicating if current branch is considered a feature."""
@@ -2760,8 +2786,25 @@ <h2 id="returns">Returns</h2>
27602786 # The branch point off `beta` is more recent than off `master`.
27612787 # Hence, the difference between current and `beta` should be considered.
27622788 branch_point = beta_branch_point
2763- changes = self.get_changes_list(branch_point, current_branch_commit, change_type="a")
2764- return changes</ code > </ pre >
2789+ return self.get_changes_list(branch_point, current_branch_commit, change_type="a")</ code > </ pre >
2790+ </ details >
2791+ </ dd >
2792+ < dt id ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_to_current_commit "> < code class ="name flex ">
2793+ < span > def < span class ="ident "> list_files_added_to_current_commit</ span > </ span > (< span > self) ‑> List[str]</ span >
2794+ </ code > </ dt >
2795+ < dd >
2796+ < div class ="desc "> < p > Returns a list of files added in the current commit.</ p > </ div >
2797+ < details class ="source ">
2798+ < summary >
2799+ < span > Expand source code</ span >
2800+ </ summary >
2801+ < pre > < code class ="python "> def list_files_added_to_current_commit(self) -> List[str]:
2802+ """Returns a list of files added in the current commit."""
2803+ current_commit = self.repo.head.commit
2804+ previous_commit = self.repo.commit("HEAD~1")
2805+ if not current_commit:
2806+ current_commit = self.get_current_commit()
2807+ return self.get_changes_list(previous_commit, current_commit, change_type="a")</ code > </ pre >
27652808</ details >
27662809</ dd >
27672810< dt id ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge "> < code class ="name flex ">
@@ -3049,6 +3092,7 @@ <h3>Inherited members</h3>
30493092< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.is_release_branch " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.is_release_branch "> is_release_branch</ a > </ code > </ li >
30503093< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_branches " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_branches "> list_branches</ a > </ code > </ li >
30513094< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_on_current_branch " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_on_current_branch "> list_files_added_on_current_branch</ a > </ code > </ li >
3095+ < li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_to_current_commit " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_to_current_commit "> list_files_added_to_current_commit</ a > </ code > </ li >
30523096< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge "> merge</ a > </ code > </ li >
30533097< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull "> pull</ a > </ code > </ li >
30543098< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull_all " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull_all "> pull_all</ a > </ code > </ li >
@@ -3168,6 +3212,7 @@ <h4><code><a title="continuous_delivery_scripts.utils.git_helpers.GitWrapper" hr
31683212< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.is_release_branch " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.is_release_branch "> is_release_branch</ a > </ code > </ li >
31693213< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_branches " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_branches "> list_branches</ a > </ code > </ li >
31703214< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_on_current_branch " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_on_current_branch "> list_files_added_on_current_branch</ a > </ code > </ li >
3215+ < li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_to_current_commit " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.list_files_added_to_current_commit "> list_files_added_to_current_commit</ a > </ code > </ li >
31713216< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge "> merge</ a > </ code > </ li >
31723217< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull "> pull</ a > </ code > </ li >
31733218< li > < code > < a title ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull_all " href ="#continuous_delivery_scripts.utils.git_helpers.GitWrapper.pull_all "> pull_all</ a > </ code > </ li >
0 commit comments