-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync
More file actions
executable file
·78 lines (67 loc) · 2.09 KB
/
sync
File metadata and controls
executable file
·78 lines (67 loc) · 2.09 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
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
BASENAME="$(basename $0)"
usage() {
echo "Usage: $BASENAME [OPTION...]"
echo
echo "OPTIONS:"
echo " --push-plugins Commit and push local plugin configurations to remote"
echo " instead of overwriting local with remote"
echo " -h | --help Display this message and exit"
}
push_plugins=false
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
--push-plugins)
push_plugins=true
shift
;;
-*|--*)
>&2 echo "$BASENAME: Unknown option '$1'"
usage
exit 1
;;
*)
>&2 echo "$BASENAME: Unexpected positional argument '$1'"
usage
exit 1
;;
esac
done
if [[ push_plugins ]]; then
echo "Pushing local plugin configurations to the remote"
else
echo "Overwriting local plugin configurations with the remote..."
git restore --staged --worktree -- content/.obsidian/plugins/
fi
if [[ ! `git status --porcelain --untracked-files=no` ]]; then
echo "No local changes; just pulling from remote"
git pull
exit $?
fi
echo ""
echo "Attempting to Backup and Pull"
echo ""
git pull --autostash
if [[ $? -ne 0 ]]; then
>&2 echo ""
>&2 echo " !! ERROR DETECTED !!"
>&2 echo "======================"
>&2 echo "You may have gotten a merge conflict in the process of incorporating local changes."
>&2 echo "If so, you will need to resolve these conflicts using normal git process."
>&2 echo "If you are a non-compsci user, ping Joseph in the group chat for help!"
exit 1
fi
echo ""
echo "Attempting to Incorporate local changes -> Commit -> Push -> Delete backup"
echo ""
git add . && \
git commit -m "Sync by $(git config user.name) on $(date "+%B %-d, %Y at %-I:%M %p (%Z)")" && \
git push
if [[ $? -eq 0 ]] && [[ "$(git stash list -n 1)" == "stash@{0}: autostash" ]]; then
echo "Backup -> Pull -> Incorporate local changes -> Commit -> Push was successful. Deleting backup."
git stash drop
fi