-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-auto-add-commit-push
More file actions
executable file
·32 lines (25 loc) · 929 Bytes
/
git-auto-add-commit-push
File metadata and controls
executable file
·32 lines (25 loc) · 929 Bytes
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
#!/bin/bash
show_help () {
/usr/bin/cat <<END_OF_SHOW_HELP
$0 [ -h ] [ -b <BRANCH> ] [ -d <DIRECTORY> ] [ -m <MESSAGE> ]
-h Show this help
-d Change into <DIRECTORY> (default: current working directory)
-b Change into and push <BRANCH> (default: master)
-m Use <MESSAGE> in commit (default: \${HOSTNAME}:<DIR> Commit For \`date +%F\`)
END_OF_SHOW_HELP
}
OPTIND=1
while getopts "hb:d:m:" opt; do
case "$opt" in
b) brch=$OPTARG;;
d) gdir=$OPTARG;;
h) show_help && exit 0;;
m) cmsg=$OPTARG;;
'?') show_help >&2 && exit 1;;
esac
done
shift $((OPTIND-1))
[[ "${brch}" == "" ]] && brch='master'
[[ "${cmsg}" == "" ]] && cmsg="${HOSTNAME}:${gdir} Commit For `date +%F`"
[ -n "${gdir}" ] && { [ -d "${gdir}" ] && cd "${gdir}" || { echo "$gdir specified but doesn't exist."; exit 1; } }
/usr/bin/git add -A . && /usr/bin/git commit -am "${cmsg}" && /usr/bin/git push origin "${brch}"