Repository navigation
Expand file tree
/
Copy pathgit_push.py
More file actions
61 lines (45 loc) · 1.81 KB
/
Copy pathgit_push.py
File metadata and controls
61 lines (45 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import subprocess
import sys
import os
os.chdir('/Users/abhijayhome/MEGA_2/VSCODE/PROJECT/Resume_22BCE11001')
def run_cmd(cmd, description=""):
"""Run a shell command and return result"""
if description:
print(f"\n{'='*50}")
print(f"{description}")
print('='*50)
print(f"$ {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.stdout:
print(result.stdout)
if result.stderr and result.returncode != 0:
print(f"Error: {result.stderr}", file=sys.stderr)
return result
# Check if merge in progress
if os.path.exists('.git/MERGE_HEAD'):
run_cmd(['git', 'merge', '--abort'], "Aborting pending merge...")
# Add all changes
run_cmd(['git', 'add', '-A'], "Adding all changes...")
# Check status
run_cmd(['git', 'status', '--short'], "Staged changes:")
# Configure user
subprocess.run(['git', 'config', 'user.email', 'abhijay@example.com'], capture_output=True)
subprocess.run(['git', 'config', 'user.name', 'Abhijay'], capture_output=True)
# Check if there are changes to commit
result = subprocess.run(['git', 'diff-index', '--quiet', 'HEAD', '--'], capture_output=True)
if result.returncode != 0: # There are changes
run_cmd(['git', 'commit', '-m', 'Update resume files'], "Committing changes...")
else:
print("\nNo changes to commit")
# Configure pull strategy
subprocess.run(['git', 'config', 'pull.rebase', 'false'], capture_output=True)
# Verify remote
run_cmd(['git', 'remote', '-v'], "Checking remote configuration...")
# Pull latest
run_cmd(['git', 'pull', 'origin', 'main', '--no-edit'], "Pulling latest from remote...")
# Push
run_cmd(['git', 'push', 'origin', 'main'], "Pushing to remote...")
# Final status
run_cmd(['git', 'status'], "Final status:")
print("\n✅ Push complete!")