-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-sub-commit-changelog
More file actions
executable file
·76 lines (66 loc) · 2.01 KB
/
git-sub-commit-changelog
File metadata and controls
executable file
·76 lines (66 loc) · 2.01 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /bin/bash
# Commit the changelog for a pending submodule
#
# Commits the updated submodule with the changelog as the commit description.
#
# Options:
# --verbose Show the changelog.
f() {
verbose=false
if [[ $1 == --verbose ]]; then
verbose=true
shift
fi
module=$1
if [ ! -d $module ] ; then
echo
echo "Error: Submodule $module does not exist."
return -1
fi
git add $module
if [ $? -ne 0 ] ; then
echo
echo "Error: No changes in submodule $module."
return -1
fi
prev_head=$(git diff --staged $module | sed -n -e's/-Subproject commit \(.*\)/\1/p')
if [[ -z $prev_head ]]; then
git reset -- $module
echo
echo "Error: No changes in submodule $module."
return -1
fi
changelog=$(git -C $module log --pretty=%s --first-parent $prev_head..HEAD)
if [[ $? > 0 ]]; then
# Git error
git reset -- $module
echo
echo "Error: Git didn't understand revision range. Often occurs when committed"
echo "submodule contains unpushed commits. Likely the working copy submodule is out"
echo "of date."
echo " Try git sub-update."
return -1
elif [[ $(echo "$changelog" | wc -c) -eq 1 ]]; then
# One character means just a newline. No data.
git reset -- $module
echo
echo "Error: No changes in changelog. Often occurs when working copy submodule is"
echo "older than committed submodule."
echo " Try git sub-update."
echo
echo "Changes in committed submodule that are missing from working copy:"
git -C $module log --pretty=" * %s" --first-parent HEAD..$prev_head
echo
return -1
fi
echo "$changelog" | cat \
<(printf 'Update %s\n\nChangelog:\n' $module) \
- | git commit --file=-
if [[ "$verbose" == true ]]; then
echo
echo "Submitted with changelog:"
echo
echo "$changelog"
fi
}
f $*