-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsync.sh
More file actions
47 lines (37 loc) · 1.34 KB
/
sync.sh
File metadata and controls
47 lines (37 loc) · 1.34 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
#!/bin/bash
set -euo pipefail
BRANCH="${BRANCH:-main}"
UPSTREAM_REMOTE="${UPSTREAM_REMOTE:-upstream}"
UPSTREAM_BRANCH="${UPSTREAM_BRANCH:-main}"
UPSTREAM_URL="${UPSTREAM_URL:-https://github.com/anlit75/RepoGallery.git}"
# Ensure the upstream remote exists
if ! git remote get-url "$UPSTREAM_REMOTE" > /dev/null 2>&1; then
git remote add "$UPSTREAM_REMOTE" "$UPSTREAM_URL"
fi
# Switch to the main branch
echo "Switching to $BRANCH branch..."
git checkout "$BRANCH"
# Ensure the working directory is clean
if [ -n "$(git status --porcelain)" ]; then
echo "The working directory has uncommitted changes. Please commit or stash them before running this script."
exit 1
fi
# Fetch the latest updates from upstream
echo "Fetching updates from $UPSTREAM_REMOTE..."
git fetch "$UPSTREAM_REMOTE"
# Rebase to get the changes from upstream
echo "Rebasing onto $UPSTREAM_REMOTE/$UPSTREAM_BRANCH..."
if ! git rebase "$UPSTREAM_REMOTE/$UPSTREAM_BRANCH"; then
echo "Conflict detected, resolving..."
# Keep local changes for config.yaml, use upstream version for other files
git checkout --ours config.yaml
git add config.yaml
git checkout --theirs .
git add .
# Continue rebase
git rebase --continue
fi
# Push changes to origin
echo "Pushing changes to origin..."
git push --force-with-lease origin "$BRANCH"
echo "Rebase complete!"