-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-track
executable file
·745 lines (702 loc) · 23.4 KB
/
git-track
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
#!/bin/sh
#
# Copyright (C) 2016 Mark Ferrell
#
# The distributed Git <bug/issue/note/whatever> tracker
#set -x
USAGE='<operation> [options] [<type|entry>]'
LONG_USAGE='Manage tracker entries.'
SUBDIRECTORY_OK=Yes
OPTIONS_SPEC=
. git-sh-setup
. git-sh-i18n
require_work_tree_exists
cd_to_toplevel
##
# utility routines
err() { echo "error: $*" >&2; }
die() { err "$*"; exit 1; }
tolower() { printf '%s\n' "$*"|tr '[A-Z]' '[a-z]'; }
toupper() { printf '%s\n' "$*"|tr '[a-z]' '[A-Z]'; }
getarg()
{
case "$#,$1" in
*,*=*) echo `expr "r$1" : 'r-[^=]*=\(.*\)'`
;;
1,*) return 1
;;
*) test "$#" -gt 1 || return 1
case "${2}" in (-*) return 1;; esac
echo "$2";;
esac
return 0
}
gitrack_mkdir()
{
: "gitrack_mkdir($*)"
test "$#" -gt '0' || die "no path specified to function 'gitrack_mkdir()'"
test -d ".gitrack/${1}" || mkdir -p ".gitrack/${1}"
}
gitrack_link()
{
: "gitrack_link($*)"
test "$#" -gt '0' || die "no link target specified to fucntion 'gitrack_link()'"
test "$#" -gt '1' || die "no link name specified to fucntion 'gitrack_link()'"
gitrack_mkdir "${2%/*}" || die "mkdir failed for link '${1}'"
gitrack_link "../../../${1}" "${2}" || die "link failed for '${1}'"
}
gitrack_rfc822_header()
{
: "gitrack_rfc822_header($*)"
test "$#" -eq '2' || die "too few arguments to function: 'gitrack_rfc822($*)'"
test -f "${2}" || die "no such file '${2}'"
awk "
BEGIN{IGNORECASE=1;}
/^summary:[[:space:]]*/{
sub(\"^[^:]+:[[:space:]]+\",\"\")
print
}" < "${2}"
}
gitrack_rfc822_body()
{
: "gitrack_rfc822_body($*)"
test "$#" -gt '0' || die "no file specified to function: 'gitrack_rfc922($*)'"
test -f "${1}" || die "no such file '${1}'"
awk 'BEGIN {body=0;}
/^$/{ body=1; }
{ if(body==1){ print; } }' < "${1}"
}
gitrack_fmt_list()
{
__list_fmt_max=0
for arg; do
__list_fmt_len="$(printf '%s' "${arg}"|wc -c)"
if test "${__list_fmt_len}" -gt "${__list_fmt_max}"; then
__list_fmt_max="${__list_fmt_len}"
fi
done
while test "$#" -gt '0'; do
__list_len=$((${__list_len} + ${__list_fmt_max} + 2))
if test "${__list_len}" -gt '78'; then
__list_len=0
printf '\n'
fi
printf ' %*s' "${__list_fmt_max}" "${1}"
shift
done
unset __list_fmt_max
unset __list_len
printf '\n'
}
gitrack_mktemp()
{
: "gitrack_mktemp($*)"
set -- "$(mktemp /tmp/gitrack.XXXXXX)"
test -f "${1}" || return 1
cat >"${1}"<<EOF
# Please enter a message for your entry. Lines starting with '#' will be
# ignored, and an empty message aborts the commit.
EOF
echo "${1}"
}
gitrack_msg_summary()
{
: "gitrack_msg_summary($*)"
test "$#" -eq '1' || die "no file specified to function 'gitrack_msg_summary()'"
test -f "${1}" || die "no such file '${1}'"
head -n 1 "${1}" | sed -e 's/^[[:space:]]*//g;s/[[:space:]]*$//g'
}
gitrack_msg_body()
{
: "gitrack_msg_body($*)"
test "$#" -eq '1' || die "no file specified to function 'gitrack_msg_body()'"
test -f "${1}" || die "no such file '${1}'"
set -- "${1}" $(wc -l "${1}" 2>/dev/null)
# delete leading/trailing newlines
tail -n "$((${2} - 1))" "${1}" | \
sed -e :a -e 's/^[[:space:]]*//g;/./,$!d;/^\n*$/{$d;N;};/\n$/ba'
}
gitrack_edit()
{
: "gitrack_edit($*)"
test "$#" -eq '1' || die "no file specified to function 'gitrack_edit()'"
test -f "${1}" || die "no such file '${1}'"
git_editor "${1}"
sed -i -e 's/^#.*//' "${1}"
if test -z "$(sed -e 's/[[:space:]]*//g' "${1}")"; then
err 'empty message, aborting'
rm -f "${1}"
return 1
fi
if test -z "$(gitrack_msg_summary "${1}")"; then
err 'empty summary line'
rm -f "${1}"
return 1
fi
return 0
}
gitrack_type()
{
: "gitrack_type($*)"
test "$#" -eq '1' || die "missing argument to function 'gitrack_type()'"
printf '%s\n' "${1%%/*}"
}
gitrack_ref()
{
: "gitrack_ref($*)"
test "$#" -eq '1' || die "missing argument to function 'gitrack_ref()'"
test "${1}" != "${1##*/}" || return 0
set -- "$(echo ".gitrack/${1%%/}"*)"
test -e "${1}" || return 1
printf '%s' "${1##*/}"
}
gitrack_exists()
{
: "gitrack_exist($*)"
test "$#" -eq '1' || die "missing argument to function 'gitrack_exists()'"
gitrack_ref "${1}" > /dev/null || die "invalid track '${1}'"
}
gitrack_set()
{
: "gitrack_set($*)"
test "$#" -eq '2' || die "too few arguments: git_track($*)"
test -d ".gitrack/${1%/*}" || die "cannot add '${1}'"
if test -e ".gitrack/${1}"; then
test -f ".gitrack/${1}" || die "not a file '${1}'"
fi
echo "${2}" > ".gitrack/${1}"
}
gitrack_get()
{
: "gitrack_get($*)"
test -e ".gitrack/${1}" || return 0
test -f ".gitrack/${1}" || die "not a file '${1}'"
printf '%s' "$(cat ".gitrack/${1}")"
}
gitrack_add()
{
: "gitrack_add($*)"
test "$#" -eq '2' || die "too few arguments: git_track($*)"
! test -f ".gitrack/${1}" || return 0
gitrack_mkdir "${1%/*}"
echo "${2}" > ".gitrack/${1}" || die "failed to add '${1}'"
}
gitrack_del()
{
: "gitrack_del($*)"
if test -e ".gitrack/${1}"; then
git rm -f ".gitrack/${1}" || die "failed to delete '${1}'"
fi
}
gitrack_entry()
{
: "gitrack_entry($*)"
# FIXME validate status/state
while test "$#" -gt '0'; do
case "${1}" in
(--type|--type=*)
entry_type="$(getarg "$@")" || die "option error '${1}'"
;;
(--ref|--ref=*)
# Add to an existing track
entry_ref="$(getarg "$@")" || die "option error '${1}'"
;;
(--state|--state=*)
entry_state="$(getarg "$@")" || die "option error '${1}'"
;;
(-m|--message|--message=*)
# Allow multiple message arguments
if test -z "${entry_summary}"; then
entry_summary="$(getarg "$@")" || die "option error '${1}'"
entry_body=''
elif test -z "${entry_body}"; then
entry_body="$(getarg "$@")" || die "option error '${1}'"
else
entry_body_append="$(getarg "$@")" || die "option error '${1}'"
entry_body="$(printf '%s\n\n%s\n' "${entry_body}" "${entry_body_append}")"
unset entry_body_append
fi
;;
(-r|--related|--related=*)
entry_related="$(getarg "$@")" || die "option error '${1}'"
entry_related="$(printf '%s' "${entry_depends}"|sed -e 's/,/ /g')"
;;
(-d|--depends|--depends=*)
entry_depends="$(getarg "$@")" || die "option error '${1}'"
entry_depends="$(printf '%s' "${entry_depends}"|sed -e 's/,/ /g')"
;;
(-b|--blocks|--blocks=*)
entry_blocks="$(getarg "$@")" || die "option error '${1}'"
entry_blocks="$(printf '%s' "${entry_blocks}"|sed -e 's/,/ /g')"
;;
(-s|--status|--status=*)
entry_status="$(getarg "$@")" || die "option error '${1}'"
;;
(-a|--attach|--attach=*)
entry_attach="$(getarg "$@")" || gitrack_cmd_help new
test -f "${attach}" || die "no such file '${attach}'"
;;
(-t|--tag|--tag=*)
entry_tags="$(getarg "$@")" || gitrack_cmd_help new
entry_tags="$(printf '%s' "${entry_tags}"|sed -e 's/,/ /g')"
;;
(-*) die "unknown argument '${1}'";;
esac
shift 1
done
##
# Sanity checks
! test -z "${entry_type}" || die 'no type specified'
if test -z "${entry_ref}"; then
test "${entry_state}" = 'open' || die 'new entries must be in an open state'
test "${entry_status}" = 'new' || die 'new entries must have an new status'
fi
for entry in ${entry_related}; do
gitrack_exists "${entry}" || die "invalid related '${entry}'"
done
for entry in ${entry_depends}; do
gitrack_exists "${entry}" || die "invalid dependancy '${entry}'"
done
for entry in ${entry_blocks}; do
gitrack_exists "${entry}" || die "invalid blocker '${entry}'"
done
##
# Prompt the user for a message
ENTRY_FILE="$(gitrack_mktemp)" || die 'failed to make temp file'
if test -z "${entry_summary}"; then
test -z "${entry_summary}" || printf '%s\n' "${entry_summary}" >> "${ENTRY_FILE}"
test -z "${entry_body}" || printf '\n%s\n' "${entry_body}" >> "${ENTRY_FILE}"
test -z "${entry_state}" || printf '# %20s: %s\n' state "$(tolower ${entry_state})" >> "${ENTRY_FILE}"
test -z "${entry_status}" || printf '# %20s: %s\n' status "$(tolower ${entry_status})" >> "${ENTRY_FILE}"
test -z "${entry_attach}" || printf '# %20s: %s\n' attachment "$(tolower ${entry_attach})" >> "${ENTRY_FILE}"
test -z "${entry_tags}" || printf '# %20s: %s\n' tags "$(tolower ${entry_tags})" >> "${ENTRY_FILE}"
test -z "${entry_related}" || printf '# %20s: %s\n' related "$(tolower ${entry_related})" >> "${ENTRY_FILE}"
test -z "${entry_depends}" || printf '# %20s: %s\n' depends "$(tolower ${entry_depends})" >> "${ENTRY_FILE}"
test -z "${entry_blocks}" || printf '# %20s: %s\n' blocks "$(tolower ${entry_blocks})" >> "${ENTRY_FILE}"
gitrack_edit "${ENTRY_FILE}" || exit 1
entry_summary="$(gitrack_msg_summary "${ENTRY_FILE}")"
entry_body="$(gitrack_msg_body "${ENTRY_FILE}")"
fi
##
# Rewrite the message into rfc822 format
echo "Author: $(git config user.name) <$(git config user.email)>" > "${ENTRY_FILE}"
echo "Date: $(date -u)" >> "${ENTRY_FILE}"
printf 'X-Type: %s\n' "${entry_type}" >> "${ENTRY_FILE}"
test -z "${entry_ref}" || printf 'X-Ref: %s\n' "${entry_ref}" >> "${ENTRY_FILE}"
test -z "${entry_state}" || printf 'X-State: %s\n' "${entry_state}" >> "${ENTRY_FILE}"
test -z "${entry_status}" || printf 'X-Status: %s\n' "${entry_status}" >> "${ENTRY_FILE}"
test -z "${entry_tags}" || printf 'X-Tags: %s\n' "${entry_tags}" >> "${ENTRY_FILE}"
test -z "${entry_attach}" || printf 'X-Attach: %s\n' "${entry_attach}" >> "${ENTRY_FILE}"
test -z "${entry_related}" || printf 'X-Related: %s\n' "${entry_related}" >> "${ENTRY_FILE}"
test -z "${entry_depends}" || printf 'X-Depends: %s\n' "${entry_depends}" >> "${ENTRY_FILE}"
test -z "${entry_blocks}" || printf 'X-Blocks: %s\n' "${entry_blocks}" >> "${ENTRY_FILE}"
printf 'Summary: %s\n\n%s\n' "${entry_summary}" "${entry_body}" >> "${ENTRY_FILE}"
# FIXME add support for GPG signing the entry?
##
# Construct the tracking entry
entry_hash="$(git hash-object "${ENTRY_FILE}")"
! test -z "${entry_hash}" || die "failed to generate object hash for '${ENTRY_FILE}'"
# new track?
if test -z "${entry_ref}"; then
entry_ref="${entry_hash}"
gitrack_mkdir "${entry_type}/${entry_ref}/refs" || die "failed to add entry '${entry_ref}'"
gitrack_set "${entry_type}/${entry_ref}/head" "${entry_ref}"
else # existing track
previous_state="$(gitrack_get "${entry_type}/${entry_ref}/state")"
previous_status="$(gitrack_get "${entry_type}/${entry_ref}/status")"
previous_owner="$(gitrack_get "${entry_type}/${entry_ref}/owner")"
# FIXME validate workflow
fi
mv "${ENTRY_FILE}" ".gitrack/${entry_type}/${entry_ref}/refs/${entry_hash}"
test -z "${entry_state}" || gitrack_set "${entry_type}/${entry_ref}/state" "${entry_state}"
test -z "${entry_status}" || gitrack_set "${entry_type}/${entry_ref}/status" "${entry_status}"
test -z "${entry_owner}" || gitrack_set "${entry_type}/${entry_ref}/owner" "${entry_owner}"
for entry in ${entry_tags}; do
gitrack_mkdir "${entry_type}/${entry_ref}/tags"
case "${entry}" in
(-*) gitrack_del "${entry_type}/${entry_ref}/tags/${entry}";;
(*) gitrack_add "${entry_type}/${entry_ref}/tags/${entry}" "${entry_hash}";;
esac
done
# FIXME support remove related
for entry in ${entry_related}; do
gitrack_link "${entry}" "${entry_type}/${entry_ref}/related/$(gitrack_ref "${entry}")"
gitrack_link "${entry_type}/${entry_ref}" "${entry}/related/${entry_ref}"
done
# FIXME support remove depends
for entry in ${entry_depends}; do
gitrack_link "${entry}" "${entry_type}/${entry_ref}/depends/$(gitrack_ref "${entry}")"
gitrack_link "${entry_type}/${entry_ref}" "${entry}/blocks/${entry_ref}"
done
# FIXME support remove blockers
for entry in ${entry_blocks}; do
gitrack_link "${entry}" "${entry_type}/${entry_ref}/blocks/$(gitrack_ref "${entry}")"
gitrack_link "${entry_type}/${entry_ref}" "${entry}/depends/${entry_ref}"
done
##
# Commit the track
git add ".gitrack/${entry_type}/${entry_ref}"
if test "${entry_ref}" = "${entry_hash}"; then
entry_action='New'
elif test "${entry_state}" != "${previous_state}"; then
if test "${entry_state}" = 'close'; then
entry_action='Closed'
else
entry_action='Reopen'
fi
else
entry_action='Update'
fi
git commit -m "${entry_action} ${entry_type}($(git rev-parse --short ${entry_ref})): ${entry_summary}" -m "${entry_body}"
}
##
# tracker command interaces
gitrack_cmd_config() { git config -f '.gitrack/config' "$@"; }
gitrack_cmd_help()
{
: "gitrack_cmd_help($*)"
case "${1}" in
commands)
echo 'git-track commands:'
printf ' %-20s %s\n' config 'Modify the tracker config'
printf ' %-20s %s\n' list 'List existing tracks and track types'
printf ' %-20s %s\n' new 'Create a new track'
printf ' %-20s %s\n' update 'Update/Modify an existing track'
printf ' %-20s %s\n' show 'Display the specified track'
printf ' %-20s %s\n' close 'Close an existing track'
printf ' %-20s %s\n' reopen 'Reopen a closed track'
printf ' %-20s %s\n' comment 'Comment on an existing track'
;;
config) echo 'usage: git-track config <options>'
echo " This is a wrapper to 'git-config -f .gitrack/config ...'"
echo " See: 'git help config' for <options> description."
;;
list) printf 'usage: git-track list [<type>] [<options>]\n options:\n'
printf ' %-20s %s\n' '--open' 'List only open entries'
printf ' %-20s %s\n' '--closed' 'List only closed entries'
printf ' %-20s %s\n' '--status=<status>' 'List entries with a given status'
printf ' %-20s %s\n' '--tag=<tag>' 'List entries with a given tag'
;;
new) # Always state=open, status=new
printf 'usage: git-track new <type> [<options>]\n options:\n'
printf ' %-20s %s\n' '--message=<message>' 'Use the specified message'
#printf ' %-20s %s\n' '--attach=<file>' 'Attach the specified file when opening the entry'
printf ' %-20s %s\n' '--tag=<tags>' 'Initial search tags of the entry'
;;
update)
printf 'usage: git-track update <type>/<ref> <options>\n options:\n'
printf ' %-20s %s\n' '--message=<message>' 'Use the specified message'
printf ' %-20s %s\n' '--status=<status>' 'Change the status of an entry.'
#printf ' %-20s %s\n' '--attach=<file>' 'Attach a file to an existing entry.'
printf ' %-20s %s\n' '--tag=<tags>' 'Tag the entry with the specified tags.'
;;
show) echo 'usage: git-track show <type>/<ref>'
;;
reopen) printf 'usage: git-track reopen <type>/<ref> [<options>]\n options:\n'
printf ' %-20s %s\n' '--message=<message>' 'Use the specified message'
#printf ' %-20s %s\n' '--attach=<file>' 'Attach a file when reopening the entry.'
;;
close) printf 'usage: git-track close <type>/<ref> <status> [<options>]\n options:\n'
printf ' %-20s %s\n' '--message=<message>' 'Use the specified message'
;;
comment) printf 'usage: git-track comment <type>/<ref> [<options>]\n options:\n'
printf ' %-20s %s\n' '--message=<message>' 'Use the specified message'
#printf ' %-20s %s\n' '--attach=<file>' 'Attach a file to an existing entry.'
;;
*) usage;;
esac
printf '\nReport bugs to http://github.com/major0/gitrack\n'
exit 0
}
gitrack_cmd_init()
{
: "gitrack_cmd_init($*)"
# init the tracker tree
mkdir '.gitrack'
gitrack_config --add webui.autoindex true
gitrack_config --add webui.indexfile BUGS.md
# allowed status types for open
gitrack_config --add status.open new,reopened,verified,assigned,fixed
gitrack_config --add status.close duplicate,wontfix,verified
# Severity is a bit of a special snowflake
#gitrack_config --add status.severity low,medium,high,critical
# Workflow for open entries
gitrack_config --add open.new open.verified,open.assigned,close.duplicate
gitrack_config --add open.verified open.assigned,close.duplicate,close.wontfix
gitrack_config --add open.assigned open.fixed,close.duplicate,close.wontfix
gitrack_config --add open.fixed close.verified
# Workflow for closed entries
gitrack_config --add close.verified open.reopen
gitrack_config --add close.wontfix open.reopen
gitrack_config --add close.duplicate open.reopen
git add '.gitrack' && git commit -m 'Initializing Gitrack distributed bug/issue/note tracker'
exit 0
}
gitrack_cmd_list()
{
: "gitrack_cmd_list($*)"
## Parse our CLI options
# Random --help in the CLI
for arg; do case "${arg}" in (help|--help) gitrack_cmd_help list;;esac;done
# No options, list available types.
if test "$#" -eq '0'; then
set -- $(ls -C1 -d .gitrack/*/ 2>/dev/null|sed -e 's,.gitrack,,;s,/,,g')
test "$#" -gt '0' || die 'No entries in tracker'
if test "$(echo "$*"|wc -c)" -lt 70; then
echo "Types: $*"
else
echo "Types:"
gitrack_fmt_list "$@"
fi
exit 0
fi
# List the head of every bug
case "${1}" in
*/*) type="${1%%/*}"
set -- $(ls -C1 -d ".gitrack/${1}"*/ 2>/dev/null)
test "$#" -gt '0' || die "No such entry '${1}'"
;;
*) type="${1}"
set -- $(ls -C1 -d ".gitrack/${1}"*/*/ 2>/dev/null)
test "$#" -gt '0' || die "No entries in the '${type}' tracker"
;;
esac
for entry; do
entry_type="$(gitrack_type "${entry#.gitrack/}")"
entry_ref="$(gitrack_ref "${entry#.gitrack/}")"
entry_head="$(gitrack_get "${entry_type}/${entry_ref}/head")"
entry_owner="$(gitrack_get "${entry_type}/${entry_ref}/owner")"
: "${entry_owner:=unassigned}"
entry_state="$(gitrack_get "${entry_type}/${entry_ref}/state")"
entry_status="$(gitrack_get "${entry_type}/${entry_ref}/status")"
printf '%s/%s: %6s:%-10s %10s %s\n' \
"${entry_type}" "$(git rev-parse --short ${entry_ref})" \
"${entry_state}" "${entry_status}" "${entry_owner}" \
"$(gitrack_rfc822_header summary "${entry}/${refs}/refs/${entry_head}")"
done | git_pager
}
gitrack_cmd_show()
{
: "gitrack_cmd_show($*)"
## parse our CLI options
test "$#" -gt '0' || die 'no track specified'
# Random --help in the CLI
for arg; do case "${arg}" in (help|--help) gitrack_cmd_help show;;esac;done
# Filter out valid arguments
for arg; do
case "${arg}" in
(-*) die "invalid option '${arg}'";;
esac
done
# sanity checks
gitrack_exists "${1}"
entry_type="$(gitrack_type "${1}")"
entry_ref="$(gitrack_ref "${1}")"
entry_head="$(gitrack_get "${entry_type}/${entry_ref}/head")"
printf 'Entry: %s/%s\n' "${entry_type}" "${entry_ref}"
printf 'State: %s\n' "$(gitrack_get "${entry_type}/${entry_ref}/state")"
printf 'Status: %s\n' "$(gitrack_get "${entry_type}/${entry_ref}/status")"
entry_owner="$(gitrack_get "${entry_type}/${entry_ref}/owner")"
: "${entry_owner:=unassigned}"
printf 'Owner: %s\n' "${entry_owner}"
printf 'Summary: %s\n' "$(gitrack_rfc822_header summary ".gitrack/${entry_type}/${entry_ref}/refs/${entry_head}")"
# Tags
shift $#
for tag in ".gitrack/${entry_type}/${entry_ref}/tags/"*; do
test -e "${tag}" || continue
set -- "${@}" "${tag##*/}"
done
if test "$#" -gt '0'; then
if test "$(echo "$*"|wc -c)" -lt 70; then
echo "Tags: $*"
else
echo "Tags:"
gitrack_fmt_list "$@"
fi
fi
unset tag
# Blocks
shift $#
for block in ".gitrack/${entry_type}/${entry_ref}/blocks/"*; do
test -e "${block}" || continue
set -- "${@}" "$(cat "${depend}")"
done
if test "$#" -gt '0'; then
if test "$(echo "$*"|wc -c)" -lt 70; then
echo "Blocks: $*"
else
echo "Blocks:"
gitrack_fmt_list "$@"
fi
fi
unset block
# Depends
shift $#
for depend in ".gitrack/${entry_type}/${entry_ref}/depends/"*; do
test -e "${depend}" || continue
set -- "${@}" "$(cat "${depend}")"
done
if test "$#" -gt '0'; then
if test "$(echo "$*"|wc -c)" -lt 70; then
echo "Depends: $*"
else
echo "Depends:"
gitrack_fmt_list "$@"
fi
fi
unset depend
gitrack_rfc822_body ".gitrack/${entry_type}/${entry_ref}/refs/${entry_head}"
}
gitrack_cmd_new()
{
: "gitrack_cmd_new($*)"
## Parse our CLI options
test "$#" -gt '0' || die 'no entry type specified'
# Random --help in the CLI
for arg; do case "${arg}" in (help|--help) gitrack_cmd_help new;;esac;done
# Filter out valid arguments
for arg; do
case "${arg}" in
#(--attach|--attach=*);;
(-m|--message|--message=*);;
(-r|--related|--related=*);;
(-d|--depends|--depends=*);;
(-b|--blocks|--blocks=*);;
(-t|--tag|--tag=*);;
(-*) die "invalid option '${arg}'";;
esac
done
# Grab our type
entry_type="$(gitrack_type "${1}")"
entry_ref="$(gitrack_ref "${1}")"
test -z "${entry_ref}" || die "illegal entry track specified '${1}'"
# Collect the message frum the user
gitrack_entry --state='open' --status='new' --type="${entry_type}" "${@}"
}
gitrack_cmd_close()
{
: "gitrack_cmd_close($*)"
## parse our CLI options
test "$#" -gt '0' || die 'no track specified'
# Random --help in the CLI
for arg; do case "${arg}" in (help|--help) gitrack_cmd_help close;;esac;done
# Filter out valid arguments
for arg; do
case "${arg}" in
(-m|--message|--message=*);;
(-*) die "invalid option '${arg}'";;
esac
done
# sanity checks
gitrack_exists "${1}"
entry_type="$(gitrack_type "${1}")"
entry_ref="$(gitrack_ref "${1}")"
shift
entry_state="$(gitrack_get "${entry_type}/${entry_ref}/state")"
test "${entry_state}" = 'open' || die "already closed '${entry_type}/${entry_ref}'"
entry_status="${2}"
! test -z "${entry_status}" || die 'no status specified'
# close track
gitrack_entry --type="${entry_type}" --ref="${entry_ref}" --state='closed' --status="${entry_status}" "${@}"
}
gitrack_cmd_reopen()
{
: "gitrack_cmd_reopen($*)"
## parse our CLI options
test "$#" -gt '0' || die 'no track specified'
# Random --help in the CLI
for arg; do case "${arg}" in (help|--help) gitrack_cmd_help reopen;;esac;done
# Filter out valid arguments
for arg; do
case "${arg}" in
(-m|--message|--message=*);;
(-r|--related|--related=*);;
(-d|--depends|--depends=*);;
(-b|--blocks|--blocks=*);;
(-*) die "invalid option '${arg}'";;
esac
done
# sanity checks
gitrack_exists "${1}"
entry_type="$(gitrack_type "${1}")"
entry_ref="$(gitrack_ref "${1}")"
shift
entry_state="$(gitrack_get "${entry_type}/${entry_ref}/state")"
test "${entry_state}" = 'close' || die "already opened '${entry_type}/${entry_ref}'"
# close track
gitrack_entry --type="${entry_type}" --ref="${entry_ref}" --state='open' --status='reopen' "${@}"
}
gitrack_cmd_update()
{
: "gitrack_cmd_update($*)"
## Parse our CLI options
test "$#" -gt '0' || die 'no track specified'
# Random --help in the CLI
for arg; do case "${arg}" in (help|--help) gitrack_cmd_help update;;esac;done
# Filter out valid arguments
for arg; do
case "${arg}" in
#(--attach|--attach=*);;
(-s|--status|--status=*);;
(-m|--message|--message=*);;
(-r|--related|--related=*);;
(-d|--depends|--depends=*);;
(-b|--blocks|--blocks=*);;
(-t|--tag|--tag=*);;
(-*) die "invalid option '${arg}'";;
esac
done
# sanity checks
gitrack_exists "${1}"
entry_type="$(gitrack_type "${1}")"
entry_ref="$(gitrack_ref "${1}")"
shift
# update track
gitrack_entry --type="${entry_type}" --entry_ref="${entry_ref}" "${@}"
}
gitrack_cmd_comment()
{
: "gitrack_cmd_comment($*)"
## Parse our CLI options
test "$#" -gt '0' || die 'no track specified'
# Random --help in the CLI
for arg; do case "${arg}" in (help|--help) gitrack_cmd_help comment;;esac;done
# Filter out valid arguments
for arg; do
case "${arg}" in
#(--attach|--attach=*);;
(-m|--message|--message=*);;
(-*) die "invalid option '${arg}'";;
esac
done
# sanity checks
gitrack_exists "${1}"
entry_type="$(gitrack_type "${1}")"
entry_ref="$(gitrack_ref "${1}")"
shift
# update track
gitrack_entry --type="${entry_type}" --entry_ref="${entry_ref}" "${@}"
}
##
# CLI argument handling
test "$#" -gt '0' || gitrack_cmd_help
cmd="${1}"
shift
case "${cmd}" in
-h|--help|help) gitrack_cmd_help "$@";;
--init) gitrack_cmd_init "$@";;
-*) die "unknown option '${cmd}'";;
*) ;;
esac
test -d '.gitrack' || die "tracker database needs to be initialized with 'git track --init'"
case "${cmd}" in
config) gitrack_cmd_config "$@";;
show) gitrack_cmd_show "$@";;
list|ls) gitrack_cmd_list "$@";;
new|open) gitrack_cmd_new "$@";;
close) gitrack_cmd_close "$@";;
reopen) gitrack_cmd_reopen "$@";;
comment) gitrack_cmd_comment "$@";;
update) gitrack_cmd_update "$@";;
*) die "unknown operation '${cmd}'";;
esac