fix: Improve git push error handling and feedback
- Replace subprocess_check_output with subprocess_run for better error handling - Add specific error messages and formatting for push failures - Implement exit code when push fails to properly indicate failure
This commit is contained in:
parent
e591361e69
commit
6b04c3de11
@ -389,12 +389,24 @@ def push_changes():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
print(f"Pushing changes to origin/{current_branch}...", end="\n\n", flush=True)
|
print(f"Pushing changes to origin/{current_branch}...", end="\n\n", flush=True)
|
||||||
result = subprocess_check_output(["git", "push", "origin", current_branch])
|
result = subprocess_run(
|
||||||
|
["git", "push", "origin", current_branch],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
print(f"Push failed: {result.stderr}", end="\n\n", flush=True)
|
||||||
|
return False
|
||||||
print("Push completed successfully.", end="\n\n", flush=True)
|
print("Push completed successfully.", end="\n\n", flush=True)
|
||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"Push failed: {str(e)}", end="\n\n", file=sys.stderr, flush=True)
|
print(f"Push failed: {str(e)}", end="\n\n", file=sys.stderr, flush=True)
|
||||||
return False
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An unexpected error occurred: {str(e)}", end="\n\n", file=sys.stderr, flush=True)
|
||||||
|
return False
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global language
|
global language
|
||||||
@ -461,7 +473,9 @@ def main():
|
|||||||
else:
|
else:
|
||||||
# 添加推送步骤
|
# 添加推送步骤
|
||||||
if ask_for_push():
|
if ask_for_push():
|
||||||
push_changes()
|
if not push_changes():
|
||||||
|
print("Push failed.", flush=True)
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
print("Commit completed.", flush=True)
|
print("Commit completed.", flush=True)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -385,15 +385,27 @@ def push_changes():
|
|||||||
try:
|
try:
|
||||||
current_branch = get_current_branch()
|
current_branch = get_current_branch()
|
||||||
if not current_branch:
|
if not current_branch:
|
||||||
print("Could not determine current branch. Push failed.", file=sys.stderr, flush=True)
|
print("Could not determine current branch. Push failed.", end="\n\n", file=sys.stderr, flush=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print(f"Pushing changes to origin/{current_branch}...", flush=True)
|
print(f"Pushing changes to origin/{current_branch}...", end="\n\n", flush=True)
|
||||||
result = subprocess_check_output(["git", "push", "origin", current_branch])
|
result = subprocess_run(
|
||||||
print("Push completed successfully.", flush=True)
|
["git", "push", "origin", current_branch],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if result.returncode != 0:
|
||||||
|
print(f"Push failed: {result.stderr}", end="\n\n", flush=True)
|
||||||
|
return False
|
||||||
|
print("Push completed successfully.", end="\n\n", flush=True)
|
||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"Push failed: {str(e)}", file=sys.stderr, flush=True)
|
print(f"Push failed: {str(e)}", end="\n\n", file=sys.stderr, flush=True)
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An unexpected error occurred: {str(e)}", end="\n\n", file=sys.stderr, flush=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -461,7 +473,9 @@ def main():
|
|||||||
else:
|
else:
|
||||||
# 添加推送步骤
|
# 添加推送步骤
|
||||||
if ask_for_push():
|
if ask_for_push():
|
||||||
push_changes()
|
if not push_changes():
|
||||||
|
print("Push failed.", flush=True)
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
print("Commit completed.", flush=True)
|
print("Commit completed.", flush=True)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user