Skip to content

Commit cd348da

Browse files
guenhterguenthgr
andauthored
Add summary fields (#1013)
Co-authored-by: guenthgr <[email protected]>
1 parent aea25d2 commit cd348da

File tree

5 files changed

+132
-71
lines changed

5 files changed

+132
-71
lines changed

Commands.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ Outputs a repo or path summary:
151151
```bash
152152
$ git summary
153153

154-
project : git-extras
155-
repo age : 10 months ago
156-
commits : 163
157-
active : 60 days
158-
files : 93
159-
authors :
154+
project : git-extras
155+
repo age : 10 months ago
156+
last active : 3 weeks ago
157+
active on : 93 days
158+
commits : 163
159+
files : 93
160+
uncommitted : 3
161+
authors :
160162
97 Tj Holowaychuk 59.5%
161163
37 Jonhnny Weslley 22.7%
162164
8 Kenneth Reitz 4.9%

bin/git-summary

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ project=${PWD##*/}
5252
#
5353
# get date for the given <commit>
5454
#
55-
5655
date() {
5756
# the $1 can be empty
5857
# shellcheck disable=SC2086
@@ -62,7 +61,6 @@ date() {
6261
#
6362
# get active days for the given <commit>
6463
#
65-
6664
active_days() {
6765
# shellcheck disable=SC2086
6866
date $1 | sort -r | uniq | awk '
@@ -74,7 +72,6 @@ active_days() {
7472
#
7573
# get the commit total
7674
#
77-
7875
commit_count() {
7976
# shellcheck disable=SC2086
8077
git log $MERGES_ARG --oneline $commit | wc -l | tr -d ' '
@@ -83,15 +80,13 @@ commit_count() {
8380
#
8481
# total file count
8582
#
86-
8783
file_count() {
8884
git ls-files | wc -l | tr -d ' '
8985
}
9086

9187
#
9288
# remove duplicate authors who belong to the same email address
9389
#
94-
9590
dedup_by_email() {
9691
# in:
9792
# 27 luo zexuan <[email protected]>
@@ -132,7 +127,6 @@ dedup_by_email() {
132127
#
133128
# list authors
134129
#
135-
136130
format_authors() {
137131
# a rare unicode character is used as separator to avoid conflicting with
138132
# author name. However, Linux column utility will escape tab if separator
@@ -150,9 +144,15 @@ format_authors() {
150144
#
151145
# fetch repository age from oldest commit
152146
#
153-
154147
repository_age() {
155-
git log --reverse --pretty=oneline --format="%ar" | head -n 1 | LC_ALL=C sed 's/ago//'
148+
git log --reverse --pretty=oneline --format="%ar" -n 1 | LC_ALL=C sed 's/ago//'
149+
}
150+
151+
#
152+
# fetch repository age of the latest commit
153+
#
154+
last_active() {
155+
git log --pretty=oneline --format="%ar" -n 1
156156
}
157157

158158
#
@@ -181,27 +181,32 @@ line_count() {
181181
lines "$@" | wc -l
182182
}
183183

184-
# summary
184+
uncommitted_changes_count() {
185+
git status --porcelain | wc -l
186+
}
185187

188+
# summary
186189
echo
187-
echo " project : $project"
190+
echo " project : $project"
188191

189192
if [ -n "$SUMMARY_BY_LINE" ]; then
190-
echo " lines : $(line_count "${paths[@]}")"
191-
echo " authors :"
193+
echo " lines : $(line_count "${paths[@]}")"
194+
echo " authors :"
192195
lines "${paths[@]}" | sort | uniq -c | sort -rn | format_authors
193196
else
194-
echo " repo age : $(repository_age)"
197+
echo " repo age : $(repository_age)"
198+
echo " last active : $(last_active)"
195199
# shellcheck disable=SC2086
196-
echo " active : $(active_days $commit) days"
200+
echo " active on : $(active_days $commit) days"
197201
# shellcheck disable=SC2086
198-
echo " commits : $(commit_count $commit)"
202+
echo " commits : $(commit_count $commit)"
199203

200204
# The file count doesn't support passing a git ref so ignore it if a ref is given
201205
if [ "$commit" == "HEAD" ]; then
202-
echo " files : $(file_count)"
206+
echo " files : $(file_count)"
203207
fi
204-
echo " authors : "
208+
echo " uncommitted : $(uncommitted_changes_count)"
209+
echo " authors : "
205210
if [ -n "$DEDUP_BY_EMAIL" ]; then
206211
# the $commit can be empty
207212
# shellcheck disable=SC2086

man/git-summary.1

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,87 @@
1-
.\" generated with Ronn-NG/v0.9.1
2-
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3-
.TH "GIT\-SUMMARY" "1" "August 2021" "" "Git Extras"
1+
.\" generated with Ronn/v0.7.3
2+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3+
.
4+
.TH "GIT\-SUMMARY" "1" "December 2022" "" "Git Extras"
5+
.
46
.SH "NAME"
57
\fBgit\-summary\fR \- Show repository summary
8+
.
69
.SH "SYNOPSIS"
710
\fBgit\-summary\fR [\-\-dedup\-by\-email] [\-\-no\-merges] [<committish>]
11+
.
812
.br
913
\fBgit\-summary\fR \-\-line [<path>]
14+
.
1015
.SH "DESCRIPTION"
1116
Shows a summary of the repository or a path within it\.
17+
.
1218
.SH "OPTIONS"
1319
<committish>
20+
.
1421
.P
1522
Summarize only the range of commits included in the <committish>\.
23+
.
1624
.P
1725
<path>
26+
.
1827
.P
1928
Summarize only the range of files included in the <path>\.
29+
.
2030
.P
2131
\-\-dedup\-by\-email
32+
.
2233
.P
2334
Remove duplicate authors who belong to the same email address\. For example,
35+
.
2436
.IP "" 4
37+
.
2538
.nf
39+
2640
$ git summary
27-
\|\.\|\.\|\.
41+
\.\.\.
2842
133 TJ Holowaychuk 9\.9%
2943
115 Tj Holowaychuk 8\.5%
3044

3145
$ git summary \-\-dedup\-by\-email
32-
\|\.\|\.\|\.
46+
\.\.\.
3347
248 TJ Holowaychuk 18\.4%
48+
.
3449
.fi
50+
.
3551
.IP "" 0
52+
.
3653
.P
3754
\-\-no\-merges
55+
.
3856
.P
3957
Exclude merge commits\.
58+
.
4059
.P
4160
\-\-line
61+
.
4262
.P
4363
Summarize with lines other than commits\. When \fB\-\-line\fR is specified, the last argument is treated as <path>\.
64+
.
4465
.P
4566
This option can not be used together with \fB\-\-dedup\-by\-email\fR or \fB\-\-no\-merges\fR\.
67+
.
4668
.SH "EXAMPLES"
4769
Outputs a repo summary:
70+
.
4871
.IP "" 4
72+
.
4973
.nf
74+
5075
$ git summary
5176

52-
project : express
53-
repo age : 10 months ago
54-
commits : 1893
55-
active : 93 days
56-
files : 111
57-
authors :
77+
project : express
78+
repo age : 10 months ago
79+
last active : 3 weeks ago
80+
active on : 93 days
81+
commits : 1893
82+
files : 111
83+
uncommitted : 3
84+
authors :
5885
1285 visionmedia
5986
478 Tj Holowaychuk
6087
48 Aaron Heckmann
@@ -73,42 +100,65 @@ authors :
73100
1 ewoudj
74101
1 isaacs
75102
1 Matt Colyer
103+
.
76104
.fi
105+
.
77106
.IP "" 0
107+
.
78108
.P
79109
This command can also take a committish, and will print a summary for the range of commits included in the committish:
110+
.
80111
.IP "" 4
112+
.
81113
.nf
114+
82115
$ git summary v42\.\.
116+
.
83117
.fi
118+
.
84119
.IP "" 0
120+
.
85121
.P
86122
Outputs a repo summary by line:
123+
.
87124
.IP "" 4
125+
.
88126
.nf
127+
89128
$ git summary \-\-line
90129

91130
project : git\-extras
92131
lines : 26820
93132
authors :
94-
\|\.\|\.\|\.
133+
\.\.\.
134+
.
95135
.fi
136+
.
96137
.IP "" 0
138+
.
97139
.P
98140
Filter with the path:
141+
.
99142
.IP "" 4
143+
.
100144
.nf
145+
101146
$ git summary \-\-line bin/
102147

103148
project : git\-extras
104149
lines : 4420
105150
authors :
106-
\|\.\|\.\|\.
151+
\.\.\.
152+
.
107153
.fi
154+
.
108155
.IP "" 0
156+
.
109157
.SH "AUTHOR"
110158
Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR>
159+
.
111160
.SH "REPORTING BUGS"
112161
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
162+
.
113163
.SH "SEE ALSO"
114164
<\fIhttps://github\.com/tj/git\-extras\fR>

0 commit comments

Comments
 (0)