From 444989f54cf33b8496791a98c316e97639885dfa Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 2 Oct 2024 01:37:05 -0400 Subject: [PATCH 1/2] Add omb version --- lib/cli.bash | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/cli.bash b/lib/cli.bash index 111da2a6d..ac36ba43b 100644 --- a/lib/cli.bash +++ b/lib/cli.bash @@ -24,7 +24,26 @@ function _omb_cmd_update { echo 'Not yet implemented' } function _omb_cmd_version { - echo 'Not yet implemented' + if ! _omb_util_command_exists git; then + echo "git not available to determine version" + return 1 + fi + + # Get the version name: + # 1) try tag-like version + # 2) try branch name + # 3) try name-rev (tag~ or branch~) + local version + version=$(command git -C "$OSH" describe --tags HEAD 2>/dev/null) \ + || version=$(command git -C "$OSH" symbolic-ref --quiet --short HEAD 2>/dev/null) \ + || version=$(command git -C "$OSH" name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \ + || version="" + + # Get short hash for the current HEAD + local commit=$(command git -C "$OSH" rev-parse --short HEAD 2>/dev/null) + + # Show version and commit hash + printf "%s (%s)\n" "$version" "$commit" } function omb { From 04dbf9aa1a6537db439040a394ce2a77d02bac1a Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 2 Oct 2024 01:47:07 -0400 Subject: [PATCH 2/2] Use _omb_util_print --- lib/cli.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.bash b/lib/cli.bash index ac36ba43b..37dc02df1 100644 --- a/lib/cli.bash +++ b/lib/cli.bash @@ -25,7 +25,7 @@ function _omb_cmd_update { } function _omb_cmd_version { if ! _omb_util_command_exists git; then - echo "git not available to determine version" + _omb_util_print 'git not available to determine version' return 1 fi