-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpush.sh
executable file
·57 lines (48 loc) · 1.5 KB
/
push.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
#!/bin/bash
# https://github.com/dubniczky/Shell-Utilities
# Search for each git repository in current folder and push the commits
# Check for help
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Search for each git repository in current folder and push the commits"
echo ""
echo "Usage: push [directory?]"
echo " directory: Directory to search for git repositories (default: current directory)"
echo ""
echo "Examples:"
echo " push - search for git repositories and push them in current directory"
echo " push ~/Projects - search for git repositories and push them in ~/Projects"
exit 0
fi
c_red='\033[0;31m'
c_green='\033[0;32m'
c_none='\033[0m'
start_time=$(date +%s)
# Move to directory if it was specified
start_dir=$(pwd)
if [ "$#" -eq 1 ]; then
cd "$1"
fi
# Find repositories
repo_paths=$(find . -name .git -type d -prune -exec dirname {} \;)
echo "Found $( echo $repo_paths | wc -w | xargs echo ) repositories in $(pwd):"
#echo $repo_paths
# Push repositories
repos=(`echo ${repo_paths}`)
pwd=$(pwd)
for repo in "${repos[@]}"; do
echo -n " | Pushing $(echo $repo | sed "s|./||") "
cd $repo
git push --all --quiet origin >/dev/null 2>&1 && \
git push --tags >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e " - ${c_green}success${c_none}"
else
echo -e " - ${c_red}failed${c_none}"
fi
cd $pwd
done
cd $start_dir
# Display performance
end_time=$(date +%s)
runtime=$((end_time-start_time))
echo "Done in ${runtime}s"