Skip to content

Commit

Permalink
Support untagged repository during the release process
Browse files Browse the repository at this point in the history
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
  • Loading branch information
extsoft committed Dec 31, 2019
1 parent 04ec914 commit 4ec7ef7
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 36 deletions.
7 changes: 4 additions & 3 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ usage: git elegant release-work [tag name]

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

The command uses branch and stash pipes to preserve the current Git state prior
to execution and restore after.
Expand Down
2 changes: 1 addition & 1 deletion libexec/git-elegant-accept-work
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ MESSAGE

--accept-work-logic() {
local WORK_BRANCH="__eg"
source ${BINS}/plugins/rebase
source ${BINS}/plugins/state
if is-there-active-rebase; then
local rb=$(rebasing-branch)
if [[ ${WORK_BRANCH} == ${rb} ]]; then
Expand Down
2 changes: 1 addition & 1 deletion libexec/git-elegant-deliver-work
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ MESSAGE
}

--deliver-work-logic() {
source ${BINS}/plugins/rebase
source ${BINS}/plugins/state
if is-there-active-rebase; then
git-verbose rebase --continue
else
Expand Down
2 changes: 1 addition & 1 deletion libexec/git-elegant-polish-work
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ default() {
error-box "'master' branch history can't be rewritten. Please read more on ${__site}"
exit 42
fi
source ${BINS}/plugins/rebase
source ${BINS}/plugins/state
if is-there-active-rebase; then
git-verbose rebase --continue
else
Expand Down
19 changes: 13 additions & 6 deletions libexec/git-elegant-release-work
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ command-description() {
cat<<MESSAGE
Annotates the latest commit of \`master\` branch with a given tag and publishes
it. The tag's message will be prepopulated using commits subjects (from oldest
to newest) between the last available tag and HEAD. The release notes will be
either copied to clipboard (if \`pbcopy\` or \`xclip\` is available) or printed
to standard output using \`git elegant show-release-notes\`.
to newest) between the last available tag and HEAD. If there are no tags, then
all commits will be used. The release notes will be either copied to clipboard
(if \`pbcopy\` or \`xclip\` is available) or printed to standard output using
\`git elegant show-release-notes\`.
The command uses branch and stash pipes to preserve the current Git state prior
to execution and restore after.
Expand Down Expand Up @@ -51,22 +52,28 @@ MESSAGE
--release-work() {
git-verbose checkout ${MASTER}
git-verbose pull --tags
source ${BINS}/plugins/state
local new_tag="${1}"
local last_tag=$(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/tags --count 1)
local last_tag=$(last-tag)
if [[ -z ${new_tag} ]]; then
question-text "'${last_tag}' is the last tag. Which one will be next? "
read new_tag
fi
local message="tag-message"
echo "Release ${new_tag}" >> ${message}
echo "" >> ${message}
git log ${last_tag}...@ --pretty=format:'- %s' --reverse >> ${message}
local diapason=${last_tag}...@
if [[ -z ${last_tag} ]]; then
diapason=@
last_tag=all-commits
fi
git log ${diapason} --pretty=format:'- %s' --reverse >> ${message}
echo "" >> ${message}
echo "" >> ${message}
git-verbose tag --annotate --file ${message} --edit ${new_tag}
remove-file ${message}
git-verbose push --tags
git-verbose-op --copy-notes-if-possible elegant show-release-notes smart ${last_tag} ${new_tag}
git-verbose-op --copy-notes-if-possible elegant show-release-notes smart ${last_tag} @
}

default() {
Expand Down
35 changes: 14 additions & 21 deletions libexec/git-elegant-show-release-notes
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ MESSAGE
}

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

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

--simple-release-notes() {
local first="${1}"
local second="${2}"
local diapason="${1}"
local changelog="simple-release-notes"
echo "Release notes" > ${changelog}
for hash in $(git log ${first}...${second} --format=%H --reverse); do
for hash in $(git log ${diapason} --format=%H --reverse); do
echo "- $(git show -s --pretty=%s ${hash})" >> ${changelog}
done
cat ${changelog}
remove-file ${changelog}
}

default() {
local layout="${1}"
local first="${2}"
local second="${3}"
if [[ -z "${layout}" ]]; then
layout=simple
source ${BINS}/plugins/state
local layout=${1:-simple}
local first=${2:-$(last-tag)}
local second=${3:-@}
local diapason=${first}...${second}
if [[ ${first} == all-commits ]]; then
diapason=${second}
fi
if [[ -z "${first}" ]]; then
first=$(git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/tags --count 1)
fi
if [[ -z "${second}" ]]; then
second=HEAD
fi

case ${layout} in
simple)
--simple-release-notes ${first} ${second}
--simple-release-notes ${diapason}
;;
smart)
if [[ "$(git remote get-url origin)" =~ ((https://)|(git@))github.com ]]; then
--github-release-notes ${first} ${second}
--github-release-notes ${diapason}
else
--simple-release-notes ${first} ${second}
--simple-release-notes ${diapason}
fi
;;
*) error-text "A layout can be 'simple' or 'smart'! '${layout}' layout is not supported."
Expand Down
7 changes: 6 additions & 1 deletion libexec/plugins/rebase → libexec/plugins/state
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# The plugin that wraps some useful operations around `git rebase`.
# The plugin that wraps the useful operations that describes a state of the repository.

is-there-active-rebase(){
# Says if there is a rebase in progress.
Expand All @@ -23,3 +23,8 @@ rebasing-branch() {
fi
done
}

last-tag() {
# Seeks for the last created tag.
git for-each-ref --sort "-version:refname" --format "%(refname:short)" refs/tags --count 1
}
12 changes: 10 additions & 2 deletions tests/git-elegant-release-work.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ setup() {
fake-pass "git push --tags"
fake-pass "git tag --annotate --file tag-message --edit ${new_tag}"
fake-pass "git remote get-url origin" "https://fake-repo.git"
read-answer ${new_tag}
}

teardown() {
Expand All @@ -39,14 +38,15 @@ teardown() {
}

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

@test "'release-work': working branch is restored when the command runs in non-master branch" {
repo "git checkout -b new"
check git-elegant release-work
check git-elegant release-work ${new_tag}
[[ ${status} -eq 0 ]]
[[ ${lines[@]} =~ "git checkout new" ]]
}
Expand All @@ -60,3 +60,11 @@ teardown() {
[[ ${status} -eq 0 ]]
[[ ${lines[@]} =~ "git checkout new" ]]
}

@test "'release-work': creates an annotated tag if there are no other tags" {
repo "git tag | xargs git tag -d"
check git-elegant release-work ${new_tag}
[[ "${status}" -eq 0 ]]
[[ "${lines[@]}" =~ "Release notes" ]]
[[ "${lines[@]}" =~ "- Add file" ]]
}

0 comments on commit 4ec7ef7

Please sign in to comment.