-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit_submodules.sh
executable file
·43 lines (34 loc) · 1.15 KB
/
commit_submodules.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
#!/bin/bash
#
# commit_submodules.sh
# Script to automatically commit submodule updates
#
set -e
# make sure we're in a git repo and cd to the top
git status >/dev/null
topdir=$(git rev-parse --show-toplevel 2>/dev/null)
[[ -d $topdir ]] && cd $topdir
# unstage changes so we don't accidentally commit other stuff
git reset HEAD .
# cache the output of git submodule status because it forks a bunch and is sloooowwww on cygwin
subs_status="$(git submodule status)"
subs_status_cached="$(git submodule status --cached)"
subs_dirty="$(gawk '/^+/ {print $2}' <<<"$subs_status")"
[[ -z $subs_dirty ]] && exit 0
# Generate commit message
stage_changes()
{
echo 'Update submodules'
for sub in $subs_dirty; do
oldrev="$(gawk '/ '"${sub//\//\\/}"' /{sub(/^+/, "", $1); print $1}' <<<"$subs_status_cached")"
oldrev="${oldrev#+}"
newrev="$(gawk '/ '"${sub//\//\\/}"' /{sub(/^+/, "", $1); print $1}' <<<"$subs_status")"
newrev="${newrev#+}"
echo -e "\n $sub"
git -C "$sub" log --pretty=' * %h %s' $oldrev..$newrev
git add "$sub"
done
}
commitmsg="$(stage_changes)"
git commit -F - <<<"$commitmsg"
git log -1