Skip to content

Commit

Permalink
Don't add show-release-notes call to the release notes
Browse files Browse the repository at this point in the history
The `release-work` command uses the `git-verbose-op` function for
handling release notes. This change allows excluding of `show-release-notes`
invocation from a release notes being redirected to a clipboard.

Also, `which` is replaced with `type` in order to rely on builtin
functions.
  • Loading branch information
extsoft committed Oct 15, 2019
1 parent f008b6e commit 038346e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
6 changes: 2 additions & 4 deletions libexec/git-elegant
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ git-verbose() {

git-verbose-op() {
# Prints a command to be executed, executes it using `git` executable,
# prints the output, and processes the output by a given function.
# and processes the output by a given function instead of printing it.
# usage: git-verbose-op <function> [arg]...
local processor=${1}; shift
command-text "git $@"
local output=$(git "$@" 2>&1)
echo "${output}"
${processor} "${output}"
${processor} "$(git "$@" 2>&1)"
}

MASTER="master"
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 @@ -41,7 +41,7 @@ MESSAGE
}

--open-urls-if-possible() {
type open >/dev/null 2>&1 || return 0
type open >/dev/null 2>&1 || { echo "${1}"; return 0; }
for line in ${1}; do
[[ ${line} =~ ^http(.+) ]] && open ${line}
done
Expand Down
29 changes: 14 additions & 15 deletions libexec/git-elegant-release-work
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ git elegant show-release-notes smart 1.1.12 1.2.0
MESSAGE
}

--copy-notes-if-possible(){
local default_tool="cat"
local copy_tool=${default_tool}
# mac
type pbcopy >/dev/null 2>&1 && copy_tool="pbcopy"
# linux
type xclip >/dev/null 2>&1 && copy_tool="xclip -selection clipboard"
echo "${1}" | ${copy_tool}
if [[ ! "${default_tool}" == "${copy_tool}" ]]; then
info-text "The release notes are copied to clipboard."
fi
}

--release-work() {
git-verbose checkout ${MASTER}
git-verbose pull --tags
Expand All @@ -54,21 +67,7 @@ MESSAGE
git-verbose tag --annotate --file ${message} --edit ${new_tag}
remove-file ${message}
git-verbose push --tags


local default_tool="cat"
local copy_tool=${default_tool}
# mac
which pbcopy >/dev/null && copy_tool="pbcopy"
# linux
which xclip >/dev/null && copy_tool="xclip -selection clipboard"
(
git-verbose elegant show-release-notes smart ${last_tag} ${new_tag}
) | ${copy_tool}
if [[ ! "${default_tool}" == "${copy_tool}" ]]; then
info-text "The release notes are copied to clipboard."
fi

git-verbose-op --copy-notes-if-possible elegant show-release-notes smart ${last_tag} ${new_tag}
}

default() {
Expand Down
2 changes: 0 additions & 2 deletions tests/git-elegant-release-work.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ setup() {
fake-pass "git pull --tags"
fake-pass "git push --tags"
fake-pass "git tag --annotate --file tag-message --edit ${new_tag}"
fake-fail "which pbcopy"
fake-fail "which xclip"
fake-pass "git remote get-url origin" "https://fake-repo.git"
read-answer ${new_tag}
}
Expand Down

0 comments on commit 038346e

Please sign in to comment.