-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28695 from taosdata/main
merge: from main to 3.0
- Loading branch information
Showing
47 changed files
with
2,651 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import subprocess | ||
import re | ||
|
||
# 执行 git fetch 命令并捕获输出 | ||
def git_fetch(): | ||
result = subprocess.run(['git', 'fetch'], capture_output=True, text=True) | ||
return result | ||
|
||
# 解析分支名称 | ||
def parse_branch_name_type1(error_output): | ||
# 使用正则表达式匹配 'is at' 前的分支名称 | ||
match = re.search(r"error: cannot lock ref '(refs/remotes/origin/[^']+)': is at", error_output) | ||
if match: | ||
return match.group(1) | ||
return None | ||
|
||
# 解析第二种错误中的分支名称 | ||
def parse_branch_name_type2(error_output): | ||
# 使用正则表达式匹配 'exists' 前的第一个引号内的分支名称 | ||
match = re.search(r"'(refs/remotes/origin/[^']+)' exists;", error_output) | ||
if match: | ||
return match.group(1) | ||
return None | ||
|
||
# 执行 git update-ref -d 命令 | ||
def git_update_ref(branch_name): | ||
if branch_name: | ||
subprocess.run(['git', 'update-ref', '-d', f'{branch_name}'], check=True) | ||
|
||
# 解析错误类型并执行相应的修复操作 | ||
def handle_error(error_output): | ||
# 错误类型1:本地引用的提交ID与远程不一致 | ||
if "is at" in error_output and "but expected" in error_output: | ||
branch_name = parse_branch_name_type1(error_output) | ||
if branch_name: | ||
print(f"Detected error type 1, attempting to delete ref for branch: {branch_name}") | ||
git_update_ref(branch_name) | ||
else: | ||
print("Error parsing branch name for type 1.") | ||
# 错误类型2:尝试创建新的远程引用时,本地已经存在同名的引用 | ||
elif "exists; cannot create" in error_output: | ||
branch_name = parse_branch_name_type2(error_output) | ||
if branch_name: | ||
print(f"Detected error type 2, attempting to delete ref for branch: {branch_name}") | ||
git_update_ref(branch_name) | ||
else: | ||
print("Error parsing branch name for type 2.") | ||
|
||
# 主函数 | ||
def main(): | ||
fetch_result = git_fetch() | ||
if fetch_result.returncode != 0: # 如果 git fetch 命令失败 | ||
error_output = fetch_result.stderr | ||
handle_error(error_output) | ||
else: | ||
print("Git fetch successful.") | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.