Skip to content

Commit a9d0e9d

Browse files
committed
sync script
1 parent e2776d7 commit a9d0e9d

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

scripts/sync-upstream.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Usage/help
5+
usage() {
6+
cat <<'EOF'
7+
Usage: scripts/sync-upstream-manual.sh [options]
8+
9+
Options:
10+
-u, --upstream-branch BRANCH Upstream branch to merge (default: master)
11+
--no-new-branch Merge into current branch instead of creating a new one
12+
-h, --help Show this help and exit
13+
EOF
14+
}
15+
16+
# Defaults
17+
UPSTREAM_BRANCH="master"
18+
CREATE_NEW_BRANCH="true"
19+
20+
# Parse args
21+
while [[ $# -gt 0 ]]; do
22+
case "$1" in
23+
-u|--upstream-branch)
24+
if [[ $# -lt 2 ]]; then
25+
echo "Missing value for $1" >&2
26+
usage
27+
exit 1
28+
fi
29+
UPSTREAM_BRANCH="$2"
30+
shift 2
31+
;;
32+
--no-new-branch)
33+
CREATE_NEW_BRANCH="false"
34+
shift
35+
;;
36+
-h|--help)
37+
usage
38+
exit 0
39+
;;
40+
*)
41+
echo "Unknown option: $1" >&2
42+
usage
43+
exit 1
44+
;;
45+
esac
46+
done
47+
48+
# Check if upstream remote exists, add if not
49+
if ! git remote get-url upstream >/dev/null 2>&1; then
50+
echo "Adding upstream remote..."
51+
git remote add upstream https://github.com/m1k1o/neko.git
52+
else
53+
echo "Upstream remote already exists"
54+
fi
55+
56+
if [[ "${CREATE_NEW_BRANCH}" == "true" ]]; then
57+
branch="sync/upstream-$(date +%Y%m%d)"
58+
git checkout -b "$branch" # work on a throw-away branch
59+
else
60+
echo "Merging into existing branch: $(git rev-parse --abbrev-ref HEAD)"
61+
fi
62+
63+
# merge selected upstream branch into this branch
64+
git fetch upstream
65+
git merge --no-edit "upstream/${UPSTREAM_BRANCH}" || true
66+
echo "there are now likely conflicts to resolve. Go forth and resolve them!"
67+
68+
# For each stop:
69+
# - run git status to see the conflicted files
70+
# - open each file, remove the conflict markers (<<<<<<<, =======, >>>>>>>) and keep the version you want,
71+
# OR, if you simply want the upstream copy: git checkout --theirs path/to/file.
72+
# If you want to keep your fork's version: git checkout --ours path/to/file.
73+
# - git add <file> (or git rm if you really mean to delete it).
74+
# - git merge --continue.
75+
76+
77+
# When git merge is completed, push the branch back to GitHub:
78+
# git push --force-with-lease -u origin HEAD

0 commit comments

Comments
 (0)