INNER CODE UNIT · Python
get_changed_files
alibaba/loongcollector · tools/coverage-diff/main.py:10
def get_changed_files():
try:
result = subprocess.check_output(['git', 'diff', '--unified=0', 'HEAD^1' ,'HEAD'], universal_newlines=True)
return result
except subprocess.CalledProcessError as e:
print(f'An error occurred while running git command: {e}')
return []
def parse_diff(diff_output):
changes = {}
current_file = None
for line in diff_output.split('\n'):
# 识别文件名
file_match = re.match(r'^diff --git a/(.*) b/(.*)$', line)
if file_match:
current_file = file_match.group(2)
changes[current_file] = []