@@ -30,14 +30,9 @@ def get_log(
30
30
if extra is None :
31
31
extra = []
32
32
33
- if ref is None :
34
- ref_args = []
35
- else :
36
- ref_args = [ref ]
37
- if n < 1 :
38
- n_args = []
39
- else :
40
- n_args = ["-n" , str (n )]
33
+ ref_args = [] if ref is None else [ref ]
34
+ n_args = [] if n < 1 else ["-n" , str (n )]
35
+
41
36
return subprocess .check_output (
42
37
["git" , "log" , f"--pretty=format:{ format } " , * n_args , * ref_args , * extra ],
43
38
encoding = "utf-8" ,
@@ -64,7 +59,9 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
64
59
# We need to make sure we have commits from main that are old enough to be
65
60
# the base of this branch, but not so old that we waste a ton of bandwidth
66
61
commit_date = datetime .datetime .fromisoformat (get_git_commit_date (dirname ))
67
- commit_date = commit_date - datetime .timedelta (365 * 2 )
62
+ commit_date = commit_date - datetime .timedelta (days = 365 * 2 )
63
+
64
+ # Get current commit hash
68
65
commit_hash = get_log ("%H" , dirname )
69
66
70
67
try :
@@ -79,10 +76,7 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
79
76
cwd = dirname ,
80
77
)
81
78
except subprocess .CalledProcessError as e :
82
- if e .returncode in (3 , 128 ):
83
- # Remote may already exist, that's ok
84
- pass
85
- else :
79
+ if e .returncode not in (3 , 128 ):
86
80
raise
87
81
88
82
subprocess .check_call (
@@ -96,6 +90,7 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
96
90
],
97
91
cwd = dirname ,
98
92
)
93
+
99
94
try :
100
95
merge_base = subprocess .check_output (
101
96
["git" , "merge-base" , "upstream/main" , "HEAD" ],
@@ -107,9 +102,10 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
107
102
return None
108
103
109
104
if merge_base == commit_hash :
105
+ # Get the parent commit if the merge base is the same as the current commit
110
106
return get_log ("%H" , dirname , "HEAD^" )
111
- else :
112
- return merge_base
107
+
108
+ return merge_base
113
109
114
110
115
111
def get_tags (dirname : PathLike ) -> list [str ]:
0 commit comments