-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate
More file actions
executable file
·66 lines (57 loc) · 2 KB
/
Copy pathupdate
File metadata and controls
executable file
·66 lines (57 loc) · 2 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
62
63
64
65
66
#!/bin/bash
LRED='\033[0;31m'
LYELLOW='\033[1;33m'
LGREEN='\033[1;32m'
LNOCOLOR='\033[0m'
REPO_DIR="$HOME/dotf2git"
UPSTREAM_URL="git@github.com:PeachlifeAB/dotf2git.git"
PWD=$(pwd)
echo -e "+-------------------- Debug Info --------------------+"
echo -e "REPO_DIR: ${LYELLOW}$REPO_DIR${LNOCOLOR}"
echo -e "+----------------------------------------------------+"
cd "$REPO_DIR" || {
echo -e "${LRED}Failed to change directory to $REPO_DIR. Aborting.${LNOCOLOR}"
exit 1
}
if git remote get-url upstream >/dev/null 2>&1; then
git remote set-url upstream "$UPSTREAM_URL" 2>/dev/null
else
git remote add upstream "$UPSTREAM_URL" 2>/dev/null
fi
echo -e "${LYELLOW}Fetching latest changes from upstream${LNOCOLOR}"
git fetch --all --quiet || {
echo -e "${LRED}Failed to fetch changes.${LNOCOLOR}"
exit 1
}
if ! git diff-index --quiet HEAD --ignore-submodules --; then
echo -e "${LYELLOW}Stashing local changes${LNOCOLOR}"
git stash -u -q 2>/dev/null || {
echo -e "${LRED}Failed to stash local changes.${LNOCOLOR}"
exit 1
}
git reset --hard HEAD --quiet || {
echo -e "${LRED}Failed to reset local changes.${LNOCOLOR}"
exit 1
}
fi
git checkout main --quiet || {
echo -e "${LRED}Failed to switch to main branch.${LNOCOLOR}"
exit 1
}
echo -e "${LYELLOW}Merging latest changes from origin/main into main${LNOCOLOR}"
git merge -X theirs --quiet -m "Merging latest changes from origin/main into main" origin/main || {
echo -e "${LRED}Failed to merge changes from origin/main.${LNOCOLOR}"
exit 1
}
echo -e "${LYELLOW}Merging latest changes from upstream/main into main${LNOCOLOR}"
git merge -X theirs --quiet -m "Merging latest changes from upstream/main" upstream/main || {
echo -e "${LRED}Failed to merge changes from upstream.${LNOCOLOR}"
exit 1
}
echo -e "${LYELLOW}Pushing updates to origin main${LNOCOLOR}"
git push origin main --quiet || {
echo -e "${LRED}Failed to push updates from upstream to origin main.${LNOCOLOR}"
exit 1
}
cd "$PWD" || exit
echo -e "${LGREEN}Update complete!${LNOCOLOR}"