diff --git a/completions/_git-elegant b/completions/_git-elegant index 9776dbc..ecec30c 100755 --- a/completions/_git-elegant +++ b/completions/_git-elegant @@ -25,6 +25,7 @@ _git-elegant (){ 'show-commands:prints available Elegant Git commands' 'show-release-notes:prints a release log between two references' 'show-work:shows a state of current work in progress' + 'show-workflows:shows configured workflows in the repository' 'start-work:creates a new branch' ) diff --git a/docs/commands.md b/docs/commands.md index 17a272f..3c6c968 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -14,31 +14,36 @@ usage: git elegant [-h | --help | help | --version | version] There are commands used in various situations such as - act with a repository + enable Elegnat Git services + acquire-git Configures a Git installation. + acquire-repository Configures current repository. clone-repository Clones a repository and configures it. init-repository Initializes a new repository and configures it. - acquire-repository Configures current repository. + + serve a repository prune-repository Removes useless local branches. - manage a personal work + enhance contribution rules + show-workflows Shows configured workflows in the repository. + + make day-to-day contributions start-work Creates a new branch. save-work Commits current modifications. amend-work Amends some changes to the most recent commit. show-work Shows a state of current work in progress. polish-work Reapplies branch commits interactively. - deliver-work Publishes current branch to a remote repository. - operate a flow of work management + interact with others + deliver-work Publishes current branch to a remote repository. obtain-work Checkouts a remote branch matching by a name. - accept-work Incorporates a branch on top of the `master`. - release new versions - show-release-notes Prints a release log between two references. + manage contributions + accept-work Incorporates a branch on top of the `master`. release-work Releases available work as a new annotated tag. + show-release-notes Prints a release log between two references. and others show-commands Prints available Elegant Git commands. - acquire-git Configures a Git installation. Please visit https://elegant-git.bees-hive.org to find out more. @@ -312,7 +317,7 @@ Displays all available Elegant Git commands. This is useful for completion functions as well as for other cases when you need iteration over the available commands. -Approximate commands flow is +Approximate command's output is ```bash ==>> git elegant show-commands start-work @@ -338,10 +343,9 @@ There are two options for a `layout`: hosting is unknown, the default layout is used. Now only GitHub is supported (an HTML output). -Approximate commands flow is +Approximate command's output is ```bash ==>> git elegant show-release-notes -# produces output like this Release notes - Add `show-release-notes` command - Add `release-work` command @@ -365,6 +369,30 @@ git status --short git stash list ``` +# `show-workflows` + +```bash +usage: git elegant show-workflows +``` + +Shows all personal and common workflows files that are available in the +repository. + +Personal workflows are located in `.git/.workflows` directory and common ones +are in \'.workflows` relatively to the repository root directory. + +Approximate command's output is +```bash +==>> git elegant show-workflows +.git/.workflows/accept-work-after +.workflows/amend-work-ahead +.workflows/amend-work-after +.workflows/release-work-after +.workflows/save-work-ahead +.workflows/save-work-after +.... +``` + # `start-work` ```bash diff --git a/libexec/git-elegant b/libexec/git-elegant index 778bca4..48d0a4c 100755 --- a/libexec/git-elegant +++ b/libexec/git-elegant @@ -71,31 +71,36 @@ usage: git elegant [-h | --help | help | --version | version] There are commands used in various situations such as - act with a repository + enable Elegnat Git services +$(--print-command-in-usage acquire-git) +$(--print-command-in-usage acquire-repository) $(--print-command-in-usage clone-repository) $(--print-command-in-usage init-repository) -$(--print-command-in-usage acquire-repository) + + serve a repository $(--print-command-in-usage prune-repository) - manage a personal work + enhance contribution rules +$(--print-command-in-usage show-workflows) + + make day-to-day contributions $(--print-command-in-usage start-work) $(--print-command-in-usage save-work) $(--print-command-in-usage amend-work) $(--print-command-in-usage show-work) $(--print-command-in-usage polish-work) -$(--print-command-in-usage deliver-work) - operate a flow of work management + interact with others +$(--print-command-in-usage deliver-work) $(--print-command-in-usage obtain-work) -$(--print-command-in-usage accept-work) - release new versions -$(--print-command-in-usage show-release-notes) + manage contributions +$(--print-command-in-usage accept-work) $(--print-command-in-usage release-work) +$(--print-command-in-usage show-release-notes) and others $(--print-command-in-usage show-commands) -$(--print-command-in-usage acquire-git) Please visit ${__site} to find out more. @@ -113,11 +118,8 @@ MESSAGE --run-workflow(){ local type=${1} local command=${2} - if [[ ! "init-repository clone-repository" =~ ${command} ]]; then - local prefix=$(git rev-parse --show-cdup 2>/dev/null) - fi - --run-file "${prefix}.git/.workflows/${command}-${type}" - --run-file "${prefix}.workflows/${command}-${type}" + --run-file "$(personal-workflows-file ${command} ${type})" + --run-file "$(common-workflows-file ${command} ${type})" } --load-command(){ @@ -148,6 +150,7 @@ MESSAGE default "$@" ;; *) + source ${BINS}/plugins/workflows --run-workflow ahead ${COMMAND} default "$@" --run-workflow after ${COMMAND} diff --git a/libexec/git-elegant-show-commands b/libexec/git-elegant-show-commands index f99e4a6..f12a4b6 100644 --- a/libexec/git-elegant-show-commands +++ b/libexec/git-elegant-show-commands @@ -19,7 +19,7 @@ Displays all available Elegant Git commands. This is useful for completion functions as well as for other cases when you need iteration over the available commands. -Approximate commands flow is +Approximate command's output is \`\`\`bash ==>> git elegant show-commands start-work diff --git a/libexec/git-elegant-show-release-notes b/libexec/git-elegant-show-release-notes index d36df40..6b9d911 100755 --- a/libexec/git-elegant-show-release-notes +++ b/libexec/git-elegant-show-release-notes @@ -26,10 +26,9 @@ There are two options for a \`layout\`: hosting is unknown, the default layout is used. Now only GitHub is supported (an HTML output). -Approximate commands flow is +Approximate command's output is \`\`\`bash ==>> git elegant show-release-notes -# produces output like this Release notes - Add \`show-release-notes\` command - Add \`release-work\` command diff --git a/libexec/git-elegant-show-workflows b/libexec/git-elegant-show-workflows new file mode 100644 index 0000000..9b544b0 --- /dev/null +++ b/libexec/git-elegant-show-workflows @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +command-purpose() { + cat <> git elegant show-workflows +.git/.workflows/accept-work-after +.workflows/amend-work-ahead +.workflows/amend-work-after +.workflows/release-work-after +.workflows/save-work-ahead +.workflows/save-work-after +.... +\`\`\` +MESSAGE +} + +--list() { + if test -e "${1}" ; then + echo "${1}" + fi +} + +default() { + for command in $(git elegant show-commands); do + --list $(personal-workflows-file ${command} ahead) + --list $(personal-workflows-file ${command} after) + --list $(common-workflows-file ${command} ahead) + --list $(common-workflows-file ${command} after) + done +} diff --git a/libexec/plugins/workflows b/libexec/plugins/workflows new file mode 100644 index 0000000..88cd1cb --- /dev/null +++ b/libexec/plugins/workflows @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +--prefix(){ + if [[ ! "init-repository clone-repository" =~ ${1} ]]; then + git rev-parse --show-cdup 2>/dev/null + fi +} + +personal-workflows() { + # usage: personal-workflows + echo "$(--prefix ${1}).git/.workflows" +} + +common-workflows() { + # usage: common-workflows + echo "$(--prefix ${1}).workflows" +} + +personal-workflows-file() { + # usage: personal-workflows-file + echo "$(personal-workflows ${1})/${1}-${2}" +} + +common-workflows-file() { + # usage: common-workflows-file + echo "$(common-workflows ${1})/${1}-${2}" +} diff --git a/tests/git-elegant-show-commands.bats b/tests/git-elegant-show-commands.bats index 267221b..afb2191 100644 --- a/tests/git-elegant-show-commands.bats +++ b/tests/git-elegant-show-commands.bats @@ -29,6 +29,7 @@ teardown() { "show-release-notes" "release-work" "polish-work" + "show-workflows" ) check git-elegant show-commands [[ ${#lines[@]} -eq ${#COMMANDS[@]} ]] diff --git a/tests/git-elegant-show-workflows.bats b/tests/git-elegant-show-workflows.bats new file mode 100644 index 0000000..78c2789 --- /dev/null +++ b/tests/git-elegant-show-workflows.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +load addons-common +load addons-repo + +setup() { + repo-new +} + +teardown(){ + repo-clean +} + +@test "'show-workflows': displays all available workflow files" { + repo "mkdir -p .workflows .git/.workflows" + repo "echo echo ahead git > .git/.workflows/start-work-ahead" + repo "echo echo ahead no > .workflows/start-work-ahead" + repo "echo echo after git > .git/.workflows/start-work-after" + repo "echo echo after no > .workflows/start-work-after" + repo "ls -lah .git/.workflows/* .workflows/*" + check git-elegant show-workflows + [[ ${status} -eq 0 ]] + [[ ${lines[0]} =~ ".git/.workflows/start-work-ahead" ]] + [[ ${lines[1]} =~ ".git/.workflows/start-work-after" ]] + [[ ${lines[2]} =~ ".workflows/start-work-ahead" ]] + [[ ${lines[3]} =~ ".workflows/start-work-after" ]] +}