mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
其中包含部分更优化和跟规范的算法或结构 --------- Co-authored-by: David <56174894+Constrat@users.noreply.github.com>
30 lines
912 B
Python
30 lines
912 B
Python
import os.path
|
|
import subprocess
|
|
|
|
def get_latest_file_content(file_path="./cli.py", encoding="utf-8", tag_name=""):
|
|
dirname = os.path.dirname(file_path)
|
|
basename = os.path.basename(file_path)
|
|
# 获取最近一次修改该文件的commit的ID
|
|
heading = "HEAD"
|
|
if tag_name:
|
|
result = subprocess.run(
|
|
["git", "rev-list", "-n", "1", "tag-autolocalization", "--", basename],
|
|
cwd=dirname,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
commit_id = result.stdout.replace('"', "").replace("'", "").strip()
|
|
heading = commit_id if commit_id else heading
|
|
result = subprocess.run(
|
|
["git", "show", f"{heading}:./{basename}"],
|
|
cwd=dirname,
|
|
capture_output=True,
|
|
text=True,
|
|
encoding=encoding,
|
|
)
|
|
return result.stdout
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(get_latest_file_content("cli.py"))
|