Skip to content

Commit 4ec7ef7

Browse files
committed
Support untagged repository during the release process
If the release process starts for a repository without tags, all commits have to be included in the release. This is achieved by introducing a `diapason` variable for specifying a revisions range in both `release-work` and `show-release-notes` commands. The variable is set to head if there are no tags in the repository. And, since the `show-release-notes` is always called with arguments within `release-work`, a `from-reference` argument has `all-commits` value that allows to recognize untagged repository and displays a release log that includes all commits. If the repository has at least one tag, the release process works without changes. #240
1 parent 04ec914 commit 4ec7ef7

File tree

8 files changed

+50
-36
lines changed

8 files changed

+50
-36
lines changed

docs/commands.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ usage: git elegant release-work [tag name]
266266

267267
Annotates the latest commit of `master` branch with a given tag and publishes
268268
it. The tag's message will be prepopulated using commits subjects (from oldest
269-
to newest) between the last available tag and HEAD. The release notes will be
270-
either copied to clipboard (if `pbcopy` or `xclip` is available) or printed
271-
to standard output using `git elegant show-release-notes`.
269+
to newest) between the last available tag and HEAD. If there are no tags, then
270+
all commits will be used. The release notes will be either copied to clipboard
271+
(if `pbcopy` or `xclip` is available) or printed to standard output using
272+
`git elegant show-release-notes`.
272273

273274
The command uses branch and stash pipes to preserve the current Git state prior
274275
to execution and restore after.

libexec/git-elegant-accept-work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ MESSAGE
4545

4646
--accept-work-logic() {
4747
local WORK_BRANCH="__eg"
48-
source ${BINS}/plugins/rebase
48+
source ${BINS}/plugins/state
4949
if is-there-active-rebase; then
5050
local rb=$(rebasing-branch)
5151
if [[ ${WORK_BRANCH} == ${rb} ]]; then

libexec/git-elegant-deliver-work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ MESSAGE
5151
}
5252

5353
--deliver-work-logic() {
54-
source ${BINS}/plugins/rebase
54+
source ${BINS}/plugins/state
5555
if is-there-active-rebase; then
5656
git-verbose rebase --continue
5757
else

libexec/git-elegant-polish-work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ default() {
4242
error-box "'master' branch history can't be rewritten. Please read more on ${__site}"
4343
exit 42
4444
fi
45-
source ${BINS}/plugins/rebase
45+
source ${BINS}/plugins/state
4646
if is-there-active-rebase; then
4747
git-verbose rebase --continue
4848
else

libexec/git-elegant-release-work

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ command-description() {
1616
cat<<MESSAGE
1717
Annotates the latest commit of \`master\` branch with a given tag and publishes
1818
it. The tag's message will be prepopulated using commits subjects (from oldest
19-
to newest) between the last available tag and HEAD. The release notes will be
20-
either copied to clipboard (if \`pbcopy\` or \`xclip\` is available) or printed
21-
to standard output using \`git elegant show-release-notes\`.
19+
to newest) between the last available tag and HEAD. If there are no tags, then
20+
all commits will be used. The release notes will be either copied to clipboard
21+
(if \`pbcopy\` or \`xclip\` is available) or printed to standard output using
22+
\`git elegant show-release-notes\`.
2223
2324
The command uses branch and stash pipes to preserve the current Git state prior
2425
to execution and restore after.
@@ -51,22 +52,28 @@ MESSAGE
5152
--release-work() {
5253
git-verbose checkout ${MASTER}
5354
git-verbose pull --tags
55+
source ${BINS}/plugins/state
5456
local new_tag="${1}"
55-
local last_tag=$(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/tags --count 1)
57+
local last_tag=$(last-tag)
5658
if [[ -z ${new_tag} ]]; then
5759
question-text "'${last_tag}' is the last tag. Which one will be next? "
5860
read new_tag
5961
fi
6062
local message="tag-message"
6163
echo "Release ${new_tag}" >> ${message}
6264
echo "" >> ${message}
63-
git log ${last_tag}...@ --pretty=format:'- %s' --reverse >> ${message}
65+
local diapason=${last_tag}...@
66+
if [[ -z ${last_tag} ]]; then
67+
diapason=@
68+
last_tag=all-commits
69+
fi
70+
git log ${diapason} --pretty=format:'- %s' --reverse >> ${message}
6471
echo "" >> ${message}
6572
echo "" >> ${message}
6673
git-verbose tag --annotate --file ${message} --edit ${new_tag}
6774
remove-file ${message}
6875
git-verbose push --tags
69-
git-verbose-op --copy-notes-if-possible elegant show-release-notes smart ${last_tag} ${new_tag}
76+
git-verbose-op --copy-notes-if-possible elegant show-release-notes smart ${last_tag} @
7077
}
7178

7279
default() {

libexec/git-elegant-show-release-notes

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ MESSAGE
3737
}
3838

3939
--github-release-notes() {
40-
local first="${1}"
41-
local second="${2}"
40+
local diapason="${1}"
4241
local changelog="github-release-notes"
4342
echo "<h3>Release notes</h3>" > ${changelog}
4443
local url=$(git remote get-url origin)
@@ -47,7 +46,7 @@ MESSAGE
4746
[[ ${url} =~ "github.com:" ]] && repository=${url##*github.com:}
4847
repository=${repository%%.git}
4948

50-
for hash in $(git log ${first}...${second} --format=%H --reverse); do
49+
for hash in $(git log ${diapason} --format=%H --reverse); do
5150
local issues=$(git show -s --pretty=%B ${hash} | grep "#")
5251
[[ ! -z ${issues} ]] && issues=" [${issues}]"
5352
local subject=$(git show -s --pretty=%s ${hash})
@@ -58,40 +57,34 @@ MESSAGE
5857
}
5958

6059
--simple-release-notes() {
61-
local first="${1}"
62-
local second="${2}"
60+
local diapason="${1}"
6361
local changelog="simple-release-notes"
6462
echo "Release notes" > ${changelog}
65-
for hash in $(git log ${first}...${second} --format=%H --reverse); do
63+
for hash in $(git log ${diapason} --format=%H --reverse); do
6664
echo "- $(git show -s --pretty=%s ${hash})" >> ${changelog}
6765
done
6866
cat ${changelog}
6967
remove-file ${changelog}
7068
}
7169

7270
default() {
73-
local layout="${1}"
74-
local first="${2}"
75-
local second="${3}"
76-
if [[ -z "${layout}" ]]; then
77-
layout=simple
71+
source ${BINS}/plugins/state
72+
local layout=${1:-simple}
73+
local first=${2:-$(last-tag)}
74+
local second=${3:-@}
75+
local diapason=${first}...${second}
76+
if [[ ${first} == all-commits ]]; then
77+
diapason=${second}
7878
fi
79-
if [[ -z "${first}" ]]; then
80-
first=$(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/tags --count 1)
81-
fi
82-
if [[ -z "${second}" ]]; then
83-
second=HEAD
84-
fi
85-
8679
case ${layout} in
8780
simple)
88-
--simple-release-notes ${first} ${second}
81+
--simple-release-notes ${diapason}
8982
;;
9083
smart)
9184
if [[ "$(git remote get-url origin)" =~ ((https://)|(git@))github.com ]]; then
92-
--github-release-notes ${first} ${second}
85+
--github-release-notes ${diapason}
9386
else
94-
--simple-release-notes ${first} ${second}
87+
--simple-release-notes ${diapason}
9588
fi
9689
;;
9790
*) error-text "A layout can be 'simple' or 'smart'! '${layout}' layout is not supported."

libexec/plugins/rebase renamed to libexec/plugins/state

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# The plugin that wraps some useful operations around `git rebase`.
2+
# The plugin that wraps the useful operations that describes a state of the repository.
33

44
is-there-active-rebase(){
55
# Says if there is a rebase in progress.
@@ -23,3 +23,8 @@ rebasing-branch() {
2323
fi
2424
done
2525
}
26+
27+
last-tag() {
28+
# Seeks for the last created tag.
29+
git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/tags --count 1
30+
}

tests/git-elegant-release-work.bats

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ setup() {
2323
fake-pass "git push --tags"
2424
fake-pass "git tag --annotate --file tag-message --edit ${new_tag}"
2525
fake-pass "git remote get-url origin" "https://fake-repo.git"
26-
read-answer ${new_tag}
2726
}
2827

2928
teardown() {
@@ -39,14 +38,15 @@ teardown() {
3938
}
4039

4140
@test "'release-work': release work when a new tag is provided via question" {
41+
read-answer ${new_tag}
4242
check git-elegant release-work
4343
[[ "${status}" -eq 0 ]]
4444
[[ "${lines[@]}" =~ "Release notes" ]]
4545
}
4646

4747
@test "'release-work': working branch is restored when the command runs in non-master branch" {
4848
repo "git checkout -b new"
49-
check git-elegant release-work
49+
check git-elegant release-work ${new_tag}
5050
[[ ${status} -eq 0 ]]
5151
[[ ${lines[@]} =~ "git checkout new" ]]
5252
}
@@ -60,3 +60,11 @@ teardown() {
6060
[[ ${status} -eq 0 ]]
6161
[[ ${lines[@]} =~ "git checkout new" ]]
6262
}
63+
64+
@test "'release-work': creates an annotated tag if there are no other tags" {
65+
repo "git tag | xargs git tag -d"
66+
check git-elegant release-work ${new_tag}
67+
[[ "${status}" -eq 0 ]]
68+
[[ "${lines[@]}" =~ "Release notes" ]]
69+
[[ "${lines[@]}" =~ "- Add file" ]]
70+
}

0 commit comments

Comments
 (0)