Skip to content

feat: color output, per-command help, and 62 new tests#120

Merged
helizaga merged 4 commits intomainfrom
ux-improvements
Feb 12, 2026
Merged

feat: color output, per-command help, and 62 new tests#120
helizaga merged 4 commits intomainfrom
ux-improvements

Conversation

@helizaga
Copy link
Collaborator

@helizaga helizaga commented Feb 12, 2026

Summary by CodeRabbit

  • New Features

    • Color output support with new gtr.ui.color setting
    • Detailed per-command help pages (git gtr help )
    • Interactive prompts for confirmations and input
  • Improvements

    • Help system enhanced with command-specific guidance and alias mapping
    • Log output uses color styling when enabled
  • Completions

    • Bash, Zsh, and Fish completions updated to include the new config key
  • Docs

    • README and configuration docs updated with UI settings and env vars
  • Tests

    • New test suites covering config, help, copy, rename, run, ui color, and related commands
  • Chores

    • Automated Homebrew formula bump workflow added

@helizaga helizaga requested a review from NatoBoram as a code owner February 12, 2026 08:08
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

Walkthrough

Adds configurable color output (gtr.ui.color), UI color scaffolding and prompts, per-command help pages and dispatcher, expanded shell completions for the new config key, extended bin/gtr initialization (extra modules, debug trap, per-command context), new tests, and a Homebrew release workflow.

Changes

Cohort / File(s) Summary
Entry point & initialization
bin/gtr
Adds debug trap when GTR_DEBUG is set, sources extra modules (hooks.sh, provider.sh, adapters.sh, launch.sh), calls _ui_apply_color_config after config load, sets _GTR_CURRENT_COMMAND, and forwards args to cmd_help "$@".
UI & color config
lib/ui.sh, lib/config.sh
Introduces color variables, enable/disable and auto-detect logic, _ui_apply_color_config, colored logging and prompt helpers; adds `gtr.ui.color
Help system
lib/commands/help.sh
Adds many per-command _help_<command> functions, updates cmd_help() to normalize aliases and dispatch to per-command help, and updates full help to reference git gtr help <command> and gtr.ui.color.
Shell completions
completions/_git-gtr, completions/git-gtr.fish, completions/gtr.bash
Adds gtr.ui.color to allowed config keys in zsh, Fish, and bash completion scripts (read and write branches), including description for allowed values.
Tests
tests/cmd_config.bats, tests/cmd_copy.bats, tests/cmd_help.bats, tests/cmd_rename.bats, tests/cmd_run.bats, tests/ui_color.bats
Adds/expands test suites covering config set/add/unset/list and scopes, copy behavior (patterns/dry-run/--all), help full/per-command and alias handling, rename scenarios and errors, run execution/exit propagation, and UI color detection/formatting.
CI / Releases & Docs
.github/workflows/homebrew.yml, README.md, docs/configuration.md
Adds Homebrew bump workflow for releases; updates README install/quick-setup (includes git gtr config set gtr.ui.color); documents new gtr.ui.color and env vars (NO_COLOR, GTR_COLOR) in configuration docs.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI Entry Point (bin/gtr)
    participant Config as Config System (config.sh)
    participant UI as UI Module (lib/ui.sh)
    participant Cmd as Command Handler (lib/commands)

    CLI->>CLI: Source core libs + hooks/provider/adapters/launch
    CLI->>UI: _ui_enable_color (auto-detect)
    CLI->>Config: Source config.sh (load .gtrconfig)
    CLI->>UI: _ui_apply_color_config
    Note over UI: Evaluate NO_COLOR / GTR_COLOR / auto
    CLI->>CLI: Set _GTR_CURRENT_COMMAND
    CLI->>Cmd: Invoke cmd_help with args
    Cmd->>Cmd: Normalize alias -> canonical command
    Cmd->>Cmd: Call _help_<command>()
    Cmd->>UI: Emit help output (uses colored logging)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Poem

🐰 I hopped through code and painted hue,

Help pages sprouted, tests grew too,
Colors tuned and prompts now bright,
Commands parade in carrot light! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the three main features introduced: color output support, per-command help functionality, and a comprehensive test suite of 62 new tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ux-improvements

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/cmd_copy.bats`:
- Around line 57-61: The test "cmd_copy for unknown branch warns but succeeds"
only checks exit status but doesn't verify the warning; update the test for
cmd_copy to assert the warning text emitted by the implementation (the log_warn
call in lib/commands/copy.sh that emits "No files copied (source and target may
be the same)") — e.g., after running run cmd_copy nonexistent -- ".env" add an
assertion that $output contains "No files copied" (or change the test name to
remove "warns" if you don't want to assert the warning).
🧹 Nitpick comments (5)
bin/gtr (1)

53-54: Consider using lowercase for the mutable context variable.

_GTR_CURRENT_COMMAND uses UPPER_CASE, but per coding guidelines, UPPER_CASE is reserved for constants. Since this value changes per command invocation, _gtr_current_command (lowercase) would be more idiomatic.

♻️ Proposed change
-  # Set for per-command help (used by show_command_help in ui.sh)
-  _GTR_CURRENT_COMMAND="$cmd"
+  # Set for per-command help (used by show_command_help in ui.sh)
+  _gtr_current_command="$cmd"

Note: Would also require updating any references in lib/ui.sh or other files that read this variable.

lib/ui.sh (2)

40-52: Phase 1 duplicates _ui_enable_color logic.

The Phase 1 auto-detection block duplicates the ANSI code assignment from _ui_enable_color(). Consider calling the helper functions instead to reduce duplication and ensure consistency.

♻️ Suggested refactor to reduce duplication
 # Phase 1: auto-detect color at source time (before config.sh is available)
-if _ui_should_color 2; then
-  _UI_GREEN=$(printf '\033[0;32m')
-  _UI_YELLOW=$(printf '\033[0;33m')
-  _UI_RED=$(printf '\033[0;31m')
-  _UI_CYAN=$(printf '\033[0;36m')
-  _UI_BOLD=$(printf '\033[1m')
-  _UI_RESET=$(printf '\033[0m')
-fi
-if _ui_should_color 1; then
-  _UI_BOLD_STDOUT=$(printf '\033[1m')
-  _UI_RESET_STDOUT=$(printf '\033[0m')
-fi
+if _ui_should_color 2 && _ui_should_color 1; then
+  _ui_enable_color
+elif _ui_should_color 2; then
+  # stderr only
+  _UI_GREEN=$(printf '\033[0;32m')
+  _UI_YELLOW=$(printf '\033[0;33m')
+  _UI_RED=$(printf '\033[0;31m')
+  _UI_CYAN=$(printf '\033[0;36m')
+  _UI_BOLD=$(printf '\033[1m')
+  _UI_RESET=$(printf '\033[0m')
+elif _ui_should_color 1; then
+  # stdout only
+  _UI_BOLD_STDOUT=$(printf '\033[1m')
+  _UI_RESET_STDOUT=$(printf '\033[0m')
+fi

142-143: Consider validating var_name before eval.

The eval usage with a caller-supplied variable name is a mild code smell. While unlikely to be exploited in this context (internal function with controlled callers), consider validating that var_name is a valid identifier to prevent unintended behavior.

🛡️ Optional: Add variable name validation
 prompt_input() {
   local question="$1"
   local var_name="$2"

   log_question "$question "
   read -r input

   if [ -n "$var_name" ]; then
+    # Validate var_name is a valid shell identifier
+    case "$var_name" in
+      [!a-zA-Z_]*|*[!a-zA-Z0-9_]*)
+        return 1
+        ;;
+    esac
     eval "$var_name=\"\$input\""
   else
     printf "%s" "$input"
   fi
 }
tests/ui_color.bats (1)

19-24: Test title is slightly misleading.

The test is titled "returns 1 when NO_COLOR is empty string (unset wins)" but it actually tests GTR_COLOR=never with NO_COLOR unset. The title suggests testing the edge case of NO_COLOR="" (set but empty), which would behave differently. Consider clarifying the title.

📝 Clarify test title
-@test "_ui_should_color returns 1 when NO_COLOR is empty string (unset wins)" {
+@test "_ui_should_color returns 1 with GTR_COLOR=never when NO_COLOR is unset" {
   _source_ui
   unset NO_COLOR
   GTR_COLOR=never run _ui_should_color 2
   [ "$status" -ne 0 ]
 }
lib/commands/help.sh (1)

392-395: Consider using declare -f instead of type for function check.

Per coding guidelines, declare -f is the recommended way to check function presence. While type works, declare -f is more explicit for functions.

♻️ Use declare -f for function check
   # Dispatch to per-command help function
   local help_func="_help_${command//-/_}"
-  if type "$help_func" >/dev/null 2>&1; then
+  if declare -f "$help_func" >/dev/null 2>&1; then
     "$help_func"
   else

As per coding guidelines: "Check function presence with declare -f create_worktree or declare -f resolve_target"

Add GitHub Actions workflow that auto-updates the Homebrew formula
in coderabbitai/homebrew-tap on each new release. Update README to
promote `brew install git-gtr` as the primary macOS install method.

Closes #92
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

319-340: ⚠️ Potential issue | 🟠 Major

Document the new gtr.ui.color config option in README.

The PR adds a new configuration key, but README’s Configuration section doesn’t mention it. Please add an example (and brief description) under “Quick Setup” or “Configuration” so users can discover it. As per coding guidelines, "README.md: Update README when adding new commands, adapters, or configuration options".

- Rename ui_color test to match what it actually tests (GTR_COLOR=never,
  not NO_COLOR empty string)
- Assert warning output in cmd_copy unknown branch test
Add color configuration to README Quick Setup and docs/configuration.md
with new UI Settings section, precedence rules, and env vars.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@docs/configuration.md`:
- Line 455: Update the prose for the GTR_PROVIDER entry so the provider name
uses the proper product branding (e.g., "GitHub" and "GitLab") while leaving the
config values lowercase; locate the table row referencing the `GTR_PROVIDER` key
and change the description from "github" or "gitlab" to use "GitHub" and
"GitLab" in the human-readable text while keeping the actual config token
examples lowercase in backticks.

@helizaga helizaga merged commit 97c1ce4 into main Feb 12, 2026
3 checks passed
@helizaga helizaga deleted the ux-improvements branch February 12, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant