@@ -30,6 +30,12 @@ if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
30
30
print_error " Not in a git repository"
31
31
fi
32
32
33
+ # Check if current branch is mainline
34
+ current_branch=$( git symbolic-ref --short HEAD)
35
+ if [ " $current_branch " != " mainline" ]; then
36
+ print_error " Must be on 'mainline' branch to sync. Currently on '$current_branch '"
37
+ fi
38
+
33
39
# Check for origin remote
34
40
if ! git remote | grep -q " ^origin$" ; then
35
41
print_error " Remote 'origin' not found"
@@ -43,88 +49,49 @@ if ! git remote | grep -q "^github$"; then
43
49
fi
44
50
fi
45
51
46
- # Verify remote configurations
47
- print_status " Verifying remote configurations..."
48
- github_url=$( git remote get-url github 2> /dev/null || echo " " )
49
- if [[ " $github_url " != * " github.com" * ]]; then
50
- print_error " GitHub remote does not point to GitHub. Current: $github_url "
51
- fi
52
-
53
- origin_url=$( git remote get-url origin 2> /dev/null || echo " " )
54
- if [[ " $origin_url " != * " amazon.com" * ]]; then
55
- print_error " Origin remote does not point to Amazon internal. Current: $origin_url "
52
+ # Test GitHub authentication
53
+ print_status " Testing GitHub authentication..."
54
+ if ! git ls-remote github & > /dev/null; then
55
+ print_error " GitHub authentication failed. Please check your SSH keys and permissions"
56
56
fi
57
57
58
58
# Check for uncommitted changes
59
- if ! git diff-index --quiet HEAD --; then
60
- print_error " You have uncommitted changes. Please commit or stash them before syncing."
61
- fi
62
-
63
- # Fetch from both remotes
64
- print_status " Fetching from origin (Amazon internal)..."
65
- if ! git fetch origin; then
66
- print_error " Failed to fetch from origin remote"
67
- fi
59
+ if ! git diff-index --quiet HEAD --; then
60
+ print_warning " You have uncommitted changes. Please commit or stash them before syncing."
61
+ exit 1
62
+ fi
68
63
69
- print_status " Fetching from GitHub..."
64
+ print_status " Fetching from GitHub remote ..."
70
65
if ! git fetch github; then
71
- print_error " Failed to fetch from GitHub remote"
72
- fi
73
-
74
- # Verify required branches exist
75
- print_status " Verifying required branches exist..."
76
- if ! git show-ref --verify --quiet refs/heads/mainline; then
77
- if git show-ref --verify --quiet refs/remotes/origin/mainline; then
78
- print_status " Pulling mainline branch from origin..."
79
- git checkout -b mainline origin/mainline
80
- else
81
- print_error " mainline branch not found locally or on origin"
82
- fi
83
- fi
84
-
85
- if ! git show-ref --verify --quiet refs/heads/master; then
86
- if git show-ref --verify --quiet refs/remotes/github/master; then
87
- print_status " Pulling master branch from github..."
88
- git checkout -b master github/master
89
- else
90
- print_error " master branch not found locally or on github"
91
- fi
92
- fi
93
-
94
- # Update mainline branch from origin
95
- print_status " Updating mainline branch from origin..."
96
- if ! git checkout mainline; then
97
- print_error " Failed to checkout mainline branch"
98
- fi
99
-
100
- if ! git merge origin/mainline --ff-only; then
101
- print_error " Failed to fast-forward mainline from origin. Manual intervention required."
102
- fi
103
-
104
- # Update master branch from GitHub
105
- print_status " Updating master branch from GitHub..."
106
- if ! git checkout master; then
107
- print_error " Failed to checkout master branch"
108
- fi
109
-
110
- if ! git merge github/master --ff-only; then
111
- print_error " Failed to fast-forward master from GitHub. Manual intervention required."
66
+ print_error " Failed to fetch from GitHub remote. Check your internet connection and repository permissions"
112
67
fi
113
68
114
- # Switch back to mainline and merge master
115
- print_status " Switching to mainline and merging master..."
116
- if ! git checkout mainline; then
117
- print_error " Failed to checkout mainline branch"
69
+ print_status " Attempting to merge github/mainline..."
70
+ if ! git merge github/mainline --no-edit; then
71
+ print_warning " Merge conflicts detected. Please:"
72
+ echo " 1. Resolve the conflicts"
73
+ echo " 2. Complete the merge with 'git commit'"
74
+ echo " 3. Run this script again to finish syncing"
75
+ exit 1
118
76
fi
119
77
120
- if ! git merge master --no-edit; then
121
- print_error " Merge conflicts detected between master and mainline. Please resolve manually."
78
+ print_status " Pushing changes to GitHub..."
79
+ if ! git push github; then
80
+ print_error " Failed to push to GitHub remote. Possible causes:"
81
+ echo " - You don't have push permissions"
82
+ echo " - The remote branch is protected"
83
+ echo " - There are new changes on the remote that you need to pull first"
84
+ exit 1
122
85
fi
123
86
124
- # Push mainline to origin
125
- print_status " Pushing mainline to origin..."
126
- if ! git push origin mainline; then
127
- print_error " Failed to push mainline to origin"
87
+ print_status " Pushing changes to origin..."
88
+ if ! git push origin; then
89
+ print_error " Failed to push to origin remote. Possible causes:"
90
+ echo " - You don't have push permissions"
91
+ echo " - The remote branch is protected"
92
+ echo " - There are new changes on the remote that you need to pull first"
93
+ exit 1
128
94
fi
129
95
130
- print_status " Successfully synced: GitHub master -> local master -> mainline -> origin"
96
+ # If we got here, everything worked
97
+ print_status " Successfully synced mainline branch between remotes!"
0 commit comments