@@ -40,11 +40,10 @@ <h1 class="title">Module <code>continuous_delivery_scripts.utils.git_helpers</co
40
40
import os
41
41
import re
42
42
import shutil
43
- from pathlib import Path
44
- from typing import Optional, List, Union, Any, Tuple
45
-
46
43
from git import Repo, Actor, GitCommandError
47
44
from packaging import version
45
+ from pathlib import Path
46
+ from typing import Optional, List, Union, Any, Tuple
48
47
49
48
from .configuration import configuration, ConfigurationVariable
50
49
from .filesystem_helpers import TemporaryDirectory
@@ -434,7 +433,13 @@ <h1 class="title">Module <code>continuous_delivery_scripts.utils.git_helpers</co
434
433
return self.get_remote_branch(branch_name) is not None
435
434
436
435
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 []
438
443
if change_type:
439
444
change_type = change_type.upper()
440
445
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
580
585
logger.warning(e)
581
586
return None
582
587
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
+
583
596
def list_files_added_on_current_branch(self) -> List[str]:
584
597
"""Returns a list of files changed against master branch."""
585
598
master_branch = self.get_master_branch()
@@ -598,8 +611,7 @@ <h1 class="title">Module <code>continuous_delivery_scripts.utils.git_helpers</co
598
611
# The branch point off `beta` is more recent than off `master`.
599
612
# Hence, the difference between current and `beta` should be considered.
600
613
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")
603
615
604
616
def is_current_branch_feature(self) -> bool:
605
617
"""Returns boolean indicating if current branch is considered a feature."""
@@ -1012,6 +1024,7 @@ <h3>Inherited members</h3>
1012
1024
< 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 >
1013
1025
< 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 >
1014
1026
< 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 >
1015
1028
< 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 >
1016
1029
< 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 >
1017
1030
< 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>
1484
1497
return self.get_remote_branch(branch_name) is not None
1485
1498
1486
1499
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 []
1488
1507
if change_type:
1489
1508
change_type = change_type.upper()
1490
1509
change_type = change_type if change_type in diff.change_type else None
@@ -1630,6 +1649,14 @@ <h2 id="args">Args</h2>
1630
1649
logger.warning(e)
1631
1650
return None
1632
1651
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
+
1633
1660
def list_files_added_on_current_branch(self) -> List[str]:
1634
1661
"""Returns a list of files changed against master branch."""
1635
1662
master_branch = self.get_master_branch()
@@ -1648,8 +1675,7 @@ <h2 id="args">Args</h2>
1648
1675
# The branch point off `beta` is more recent than off `master`.
1649
1676
# Hence, the difference between current and `beta` should be considered.
1650
1677
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")
1653
1679
1654
1680
def is_current_branch_feature(self) -> bool:
1655
1681
"""Returns boolean indicating if current branch is considered a feature."""
@@ -2760,8 +2786,25 @@ <h2 id="returns">Returns</h2>
2760
2786
# The branch point off `beta` is more recent than off `master`.
2761
2787
# Hence, the difference between current and `beta` should be considered.
2762
2788
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 >
2765
2808
</ details >
2766
2809
</ dd >
2767
2810
< dt id ="continuous_delivery_scripts.utils.git_helpers.GitWrapper.merge "> < code class ="name flex ">
@@ -3049,6 +3092,7 @@ <h3>Inherited members</h3>
3049
3092
< 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 >
3050
3093
< 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 >
3051
3094
< 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 >
3052
3096
< 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 >
3053
3097
< 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 >
3054
3098
< 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
3168
3212
< 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 >
3169
3213
< 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 >
3170
3214
< 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 >
3171
3216
< 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 >
3172
3217
< 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 >
3173
3218
< 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