File tree Expand file tree Collapse file tree 1 file changed +27
-5
lines changed
src/codeql_wrapper/infrastructure Expand file tree Collapse file tree 1 file changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -135,12 +135,34 @@ def get_diff_files(self, git_info: GitInfo) -> List[str]:
135
135
base_ref_commit = self .repo .commit (base_ref_to_use )
136
136
137
137
# Use HEAD for current commit in detached HEAD state
138
- if git_info .current_ref == "HEAD" or git_info .current_ref .startswith (
139
- "refs/pull"
140
- ):
138
+ # Resolve current commit with fallback logic
139
+ try :
140
+ if git_info .current_ref == "HEAD" or git_info .current_ref .startswith (
141
+ "refs/pull"
142
+ ):
143
+ current_commit = self .repo .head .commit
144
+ self .logger .debug ("Using HEAD for current commit" )
145
+ else :
146
+ # Try to resolve the current_ref directly first
147
+ try :
148
+ current_commit = self .repo .commit (git_info .current_ref )
149
+ self .logger .debug (
150
+ f"Successfully resolved current ref: { git_info .current_ref } "
151
+ )
152
+ except Exception :
153
+ # If that fails, try alternative formats
154
+ if git_info .current_ref .startswith ("refs/heads/" ):
155
+ # Try as remote branch
156
+ remote_ref = git_info .current_ref .replace (
157
+ "refs/heads/" , "origin/"
158
+ )
159
+ self .logger .debug (f"Trying remote ref: { remote_ref } " )
160
+ current_commit = self .repo .commit (remote_ref )
161
+ except Exception as e :
162
+ self .logger .warning (
163
+ f"Failed to resolve current commit, using HEAD: { e } "
164
+ )
141
165
current_commit = self .repo .head .commit
142
- else :
143
- current_commit = self .repo .commit (git_info .current_ref )
144
166
145
167
# Get the diff from base_ref to current
146
168
diff = base_ref_commit .diff (current_commit )
You can’t perform that action at this time.
0 commit comments