@@ -116,12 +116,23 @@ def cmd_result_set(cmd):
116
116
return set ()
117
117
return {f .strip () for f in ret .split ("\n " )}
118
118
119
+ def rel_paths (files , root ):
120
+ return {os .path .relpath (os .path .join (root , f .strip ()), "." ) for f in files }
121
+
119
122
try :
120
123
ret = set ()
121
124
125
+ # get path to root of repository
126
+ root_dir = (
127
+ subprocess .run (["git" , "rev-parse" , "--show-toplevel" ], capture_output = True )
128
+ .stdout .strip ()
129
+ .decode ()
130
+ )
131
+
122
132
# Check locally modified files
123
- dirty = cmd_result_set (["git" , "status" , "--porcelain" ])
124
- ret = {line .split (" " , 1 )[- 1 ] for line in dirty }
133
+ status = cmd_result_set (["git" , "status" , "--porcelain" ])
134
+ dirty_files = rel_paths ({line .split (" " , 1 )[- 1 ] for line in status }, root_dir )
135
+ ret |= dirty_files
125
136
126
137
# Current commit and branch
127
138
current_commit = (
@@ -144,7 +155,10 @@ def cmd_result_set(cmd):
144
155
# List the files modified on current branch
145
156
if verbose :
146
157
print ("Scanning changes from current branch and any local changes" )
147
- ret |= cmd_result_set (["git" , "diff" , "--relative" , "--name-only" , BASE_BRANCH ])
158
+ files_on_branch = rel_paths (
159
+ cmd_result_set (["git" , "diff" , "--name-only" , BASE_BRANCH ]), root_dir
160
+ )
161
+ ret |= files_on_branch
148
162
return ret
149
163
except :
150
164
# Git not available, run on entire repo
0 commit comments