This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit.sh
145 lines (117 loc) · 2.11 KB
/
git.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#! /usr/bin/env sh
progs="$HOME/progs"
gh="$progs/github.com"
bb="$progs/bitbucket.org"
start_tpl="
=============
*
* Repository: %s
*
"
end_tpl="
*
* End repository: %s
*
"
repos="
$gh/insar_meteo
$gh/utils
$gh/pygomma
$gh/geodynamics
$gh/dotfiles
$bb/stm-bi
$HOME/Dokumentumok/texfiles
"
check_narg() {
if [ "$1" -lt "$2" ]; then
printf "error: Wrong number of arguments!\n"
return 1
fi
}
last_field() {
echo "$(echo "$1" | awk -F '/' '{ print $NF; }')"
}
git_remote_add() {
check_narg $# 1
git remote add origin "$1"
}
git_push() {
check_narg $# 1
git commit -am "$*"
git push origin master
}
main() {
check_narg "$#" "1"
local passwd="false"
local out="$HOME/git_report.html"
local config_path=".git/config"
local tpl="https://bozso:%[email protected]/bozso"
local nocom="nothing to commit, working tree clean"
if [ "all" = "$1" ]; then
case "$2" in
"push")
passwd="true"
;;
"pull")
passwd="true"
;;
*) ;;
esac
#if [ "true" = "$passwd" ]; then
#stty -echo
#printf "Password: "
#read pwd
#stty echo
#printf "\n"
#fi
printf "<!DOCTYPE html>\n<html>\n<body>\n" >"$out"
printf "<style>\np {white-space: pre-wrap}\n</style>\n" >>"$out"
for repo in "$repos"; do
# [ ! -f "${repo}" ] && continue
cd "$repo"
printf "$start_tpl" "$repo"
case "$2" in
"stat")
printf "\n<h1> Repository: %s </h1> \n" "$repo" >>"$out"
local stat="$(git status)"
printf "<p>%s</p>\n" "$stat" >>"$out"
printf "$stat"
;;
"push")
local msg="$(git status | awk 'FNR == 2 { print $0 }')"
[ "$nocom" = "$msg" ] && continue
printf "Type in commit message for $(last_field "$repo")!\n"
git commit -a -F -
git push origin master
;;
"pull")
git pull origin master
;;
*)
printf "Unrecognized option %s!\n" "$2" >&2
return 1
;;
esac
printf "$end_tpl" "$repo"
done
printf "\n</html>\n</body>" >>"$out"
return 0
fi
case $1 in
"stat")
git status
;;
"push")
shift
git_push "$@"
;;
"pull")
git pull origin master
;;
*)
printf "Unrecognized option %s!\n" "$1" >&2
return 1
;;
esac
}
main "$@"