-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncallgit.sh
executable file
·115 lines (95 loc) · 3.3 KB
/
syncallgit.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
echo "Checking for configfiles"
GIT_DIRS_FILE="$HOME/.config/git_dirs"
if [ -f "$GIT_DIRS_FILE" ]
then
CONF_LOOK_DIRS=''
echo ".config/git_dirs config file found."
CONF_LOOK_DIRS=$( while read -r line; do echo "$line" ;done < ~/.config/git_dirs )
GIT_LINKS_DIR="$HOME/.config/git_links.d"
if [ -d "$GIT_LINKS_DIR" ]
then
echo ".config/git_links.d folder found"
(find "$GIT_LINKS_DIR" -maxdepth 1 -type d ) | while read -r FOLDER
do
if [ "$(basename "$FOLDER")" != ".git" ]
then
(
(find "$FOLDER" -maxdepth 1 -type f ) | while read -r FILE
do
while read -r PUTPLACE LINK
do
(
if [ ! -d "$PUTPLACE" ]
then
echo ""; echo "Creating new directory:" "$PUTPLACE"
mkdir -p "$PUTPLACE"; cd "$PUTPLACE" || return
git clone --depth 5 "$LINK" .
fi
)
PARENTDIR="$(dirname -- "$(readlink -f -- "$PUTPLACE")")"
if [ "$(grep -Fxq "$PARENTDIR" "$GIT_DIRS_FILE")" ]
then
echo "Parent directory $PARENTDIR is not in $GIT_DIRS_FILE. Entry is added"
echo "$PARENTDIR" >> "$GIT_DIRS_FILE"
fi
done < "$FILE"
done
)
fi
done
fi
fi
#
GIT_EDITOR_FILE="$HOME/.config/syncallgit_editor_cmd"
if [ -f "$GIT_EDITOR_FILE" ]
then
SYNCALLGIT_EDITOR_CMD=$(cat "$GIT_EDITOR_FILE")
else
echo "no .config/syncallgit_editor_cmd file found. Using xterm -e vim as a default"
SYNCALLGIT_EDITOR_CMD="xterm -e vim"
fi
LOOK_DIRS=${1:-$CONF_LOOK_DIRS}
echo ""; echo "Looking for git folders in:"
echo "$LOOK_DIRS"
for ELEMENT in $LOOK_DIRS
do
echo ""; echo "Checking folder:" "$ELEMENT"
# for FOLDER in $(find "$ELEMENT" -maxdepth 1 -type d ); do
(find "$ELEMENT" -maxdepth 1 -type d ) | while read -r FOLDER
do
if [ -d "$FOLDER"/.git ]; then
echo "Git folder found in:" "$FOLDER"
cd "$FOLDER" || return
if [ -f ".pull_submodules" ]
then
echo ".submodule_update_recursive file found. Will do 'git pull --recurse-submodules; git submodule update --recursive --remote' to pull the repo and update all submodules. This takes precedence over .submodule_update_recursive files."
git pull --recurse-submodules
git submodule update --recursive --remote
elif [ -f ".submodule_update_recursive" ]
then
echo ".pull_recurse_submodules file found. Will do 'git pull --recurse-submodules'. This will update all submodules to their referenced Heads."
git pull --recurse-submodules
else
git pull
fi
if [ "$(git diff --stat)" != '' ]
then
echo "Uncommitted local changes found. Starting commit and push "
#THIS IS A WORKAROUND TO THE FOLLOWING ISSUE WITH "git commit -a" WHEN USING SIGNED COMMITS
#hint: Waiting for your editor to close the file... Vim: Warning: Input is not from a terminal
#Vim: Error reading input, exiting.
git commit -a --dry-run > .git/COMMIT_EDITMSG; sed -i -e 's/^/#/' .git/COMMIT_EDITMSG; sed -i -e '1i\\' .git/COMMIT_EDITMSG
$($SYNCALLGIT_EDITOR_CMD .git/COMMIT_EDITMSG )
#gedit .git/COMMIT_EDITMSG
sed -i -e '/^[[:blank:]]*#/d;s/#.*//' .git/COMMIT_EDITMSG
git commit -a -F .git/COMMIT_EDITMSG; git push; echo ""
fi
if [ "$(git diff @ @{upstream} )" != '' ]
then
echo "Unpushed local commits to master branch found. Starting push."
(git push origin master)
fi
fi
done
done