-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitRemotesUpdate
More file actions
executable file
·57 lines (48 loc) · 2.04 KB
/
gitRemotesUpdate
File metadata and controls
executable file
·57 lines (48 loc) · 2.04 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
#!/bin/bash
## -------------------------------------------------------------------
## Git Remote Updater 1.0.0
##
## This is free software: you are free to change and redistribute it.
## There is NO WARRANTY, to the extent permitted by law.
## -------------------------------------------------------------------
### Pushes all branches in all repos to a remote.
### Usage: gitRemoteUpdate [options] <remote>
###
### -q, --quiet Quiets output
### -i, --ignore Ignores repos that are marked to be ignored
### -h, --help Show help options.
### -v, --version Print program version.
help=$(grep "^### " "$0" | cut -c 5-)
version=$(grep "^## " "$0" | cut -c 4-)
eval "$(docopts -A args -h "$help" -V "$version" : "$@")"
. $(dirname $0)/scriptsConfig
IGNORES=""
if ${args[--ignore]}; then
if [[ -e $GITDIR/.autoUpdateIgnore ]]; then
IGNORES=$(cat $GITDIR/.autoUpdateIgnore)
else
echo -e "\e[31mERROR: Ignore option set, but ignores file does not exist. Continuing without ignoring any repos.\e[m"
fi
fi
if [[ -n $RSAKEYLOC ]] && [[ $(ssh-add -l) != *"$RSAKEYLOC"* ]]; then
ssh-add
fi
cd $GITDIR
for FILE in `ls`; do
if [ -d $FILE ] && [[ -z $(echo $IGNORES | egrep "\b$FILE\b") ]]; then
cd $FILE
if [ -e '.git' ] && [[ $(git remote) = *"${args[<remote>]}"* ]]; then
for BRANCH in `git branch | sed s/"*"//g`; do
if ! ${args[--quiet]}; then echo "Pushing branch $BRANCH in $FILE."; fi
OUTPUT="$(git push --tags ${args[<remote>]} 2>&1) $(git push ${args[<remote>]} $BRANCH 2>&1)"
if [ $? -ne 0 ]; then
if ! ${args[--quiet]}; then echo -e "\e[31m ERROR: Pushing of $BRANCH in $FILE to ${args[<remote>]} failed.\e[m"; fi
fi
if [[ $OUTPUT = *"->"* ]] && [[ $OUTPUT != *"[rejected]"* ]]; then
if ! ${args[--quiet]}; then echo -e "\e[36m Pushed $BRANCH in $FILE to ${args[<remote>]}.\e[m"; fi
fi
done
fi
cd ..
fi
done