Skip to content

[feature/git_helper-23] Added ability for repo specific GIT_HELPER_PREFIX#24

Merged
justinkumpe merged 1 commit intodevfrom
feature/git_helper-23
Jan 7, 2026
Merged

[feature/git_helper-23] Added ability for repo specific GIT_HELPER_PREFIX#24
justinkumpe merged 1 commit intodevfrom
feature/git_helper-23

Conversation

@justinkumpe
Copy link
Member

@justinkumpe justinkumpe commented Jan 7, 2026

Summary by Sourcery

Support repo-specific commit message prefixes and improve git-helper usability

New Features:

  • Allow configuring commit message prefix via a .GIT_HELPER_PREFIX file in the repository root, falling back to the GIT_HELPER_PREFIX environment variable
  • Add a utilities menu action to interactively set the commit message prefix either globally in shell profiles or per-repository via .GIT_HELPER_PREFIX

Enhancements:

  • Dynamically size dialog and menu heights based on terminal dimensions and disable shadows in dialog/whiptail UIs for better display
  • Update alias management to write the git-helper alias and optional GIT_HELPER_PREFIX to both ~/.bashrc and ~/.bash_profile, and source both profiles after changes
  • Clarify utilities, commit prefix behavior, and alias setup in the README, including guidance on ignoring or committing .GIT_HELPER_PREFIX

Documentation:

  • Document repo-specific .GIT_HELPER_PREFIX usage, environment variable fallback, and updated alias behavior in the README

@justinkumpe justinkumpe self-assigned this Jan 7, 2026
@justinkumpe justinkumpe added the enhancement New feature or request label Jan 7, 2026
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 7, 2026

Reviewer's Guide

Implements repo-specific commit message prefixes via a .GIT_HELPER_PREFIX file (with fallback to GIT_HELPER_PREFIX env var), adds a UI-driven command to configure prefixes either globally or per-repo, updates alias creation to touch both bashrc and bash_profile, and improves the TUI sizing and appearance for dialog/whiptail-based interactions.

Sequence diagram for configuring commit prefix via utilities menu

sequenceDiagram
  actor User
  participant TUI as git_helper_TUI
  participant Utils as menu_utils
  participant Cmd as cmd_utils_set_prefix
  participant Git as git
  participant FS as filesystem

  User->>TUI: Open Utilities menu
  TUI->>Utils: menu_utils
  Utils->>TUI: ui_menu("Utilities")
  TUI-->>User: Show options
  User-->>TUI: Select set_prefix
  TUI->>Utils: choice set_prefix
  Utils->>Cmd: cmd_utils_set_prefix

  Cmd->>TUI: ui_menu("Set Prefix scope")
  TUI-->>User: Choose local or repo
  alt Local scope
    User-->>TUI: Select local
    TUI->>Cmd: scope local
    Cmd->>FS: touch ~/.bashrc, ~/.bash_profile
    Cmd->>TUI: ui_input("Enter GIT_HELPER_PREFIX")
    TUI-->>User: Prompt for prefix
    User-->>TUI: Enter prefix
    TUI->>Cmd: prefix value
    Cmd->>FS: Remove existing GIT_HELPER_PREFIX from profiles
    Cmd->>FS: Append export GIT_HELPER_PREFIX
    Cmd->>Cmd: export GIT_HELPER_PREFIX
    Cmd->>TUI: ui_message("Prefix set, saved to profiles")
  else Repo scope
    User-->>TUI: Select repo
    TUI->>Cmd: scope repo
    Cmd->>Git: git rev-parse --is-inside-work-tree
    Git-->>Cmd: is repo?
    alt Not in repo
      Cmd->>TUI: ui_message("Not in a git repository")
    else In repo
      Cmd->>Git: git rev-parse --show-toplevel
      Git-->>Cmd: repo_root
      Cmd->>FS: Read repo_root/.GIT_HELPER_PREFIX (if exists)
      Cmd->>TUI: ui_input("Enter GIT_HELPER_PREFIX", current_prefix)
      TUI-->>User: Prompt for repo prefix
      User-->>TUI: Enter prefix
      TUI->>Cmd: prefix value
      Cmd->>FS: Write prefix to repo_root/.GIT_HELPER_PREFIX
      Cmd->>Git: git check-ignore .GIT_HELPER_PREFIX
      Git-->>Cmd: ignored or not
      Cmd->>TUI: ui_message("Repo-specific prefix saved")
    end
  end
Loading

File-Level Changes

Change Details Files
Make dialog/whiptail UI height dynamic and add no-shadow styling for all dialog screens.
  • Replace fixed HEIGHT and MENU_HEIGHT values with functions that compute them from terminal size using tput lines, enforcing minimum heights.
  • Initialize HEIGHT and MENU_HEIGHT from the new helper functions at startup.
  • Add --no-shadow flag to all whiptail and dialog invocations in menu, checklist, input, yes/no, and text viewer helpers to standardize appearance.
git_helpers/git-helper.sh
Allow commit message prefixes to be configured per repository via a .GIT_HELPER_PREFIX file, with environment variable fallback.
  • Extend expand_commit_prefix to first look for a .GIT_HELPER_PREFIX file in the git repo root and read its first line, trimming newline characters but preserving spaces.
  • Fall back to the GIT_HELPER_PREFIX environment variable only if no repo file exists or it is empty.
  • Keep existing {{branch}} and {{ticket}} placeholder expansion behavior intact.
git_helpers/git-helper.sh
.GIT_HELPER_PREFIX
Improve alias creation so it targets both ~/.bashrc and ~/.bash_profile and generalize wording away from bash_profile-only.
  • Update cmd_utils_add_alias to touch and manage both ~/.bashrc and ~/.bash_profile instead of a single profile file.
  • Remove any existing alias definition for the chosen alias name from both profile files before appending the new alias line.
  • Offer to set GIT_HELPER_PREFIX across both profile files, removing previous definitions and exporting it for the current session, then source both files and adjust user messages accordingly.
  • Adjust UI copy to speak about shell profiles rather than just bash_profile.
git_helpers/git-helper.sh
git_helpers/README.md
Add a new utility command to configure commit message prefix either globally or per-repo via the UI.
  • Introduce cmd_utils_set_prefix, which prompts the user to choose between local (shell profiles) and repo-specific prefix configuration or cancel.
  • For local scope, mirror the profile update logic used in cmd_utils_add_alias to write an export GIT_HELPER_PREFIX line to both ~/.bashrc and ~/.bash_profile, removing existing entries and exporting for the current shell.
  • For repo scope, ensure the user is inside a git repository, locate the repo root, read any existing .GIT_HELPER_PREFIX first line as default, then overwrite the file with the new prefix if provided.
  • Emit guidance about optionally git-ignoring .GIT_HELPER_PREFIX or committing it for shared team settings.
  • Wire cmd_utils_set_prefix into the Utilities menu as a new set_prefix option with updated menu labels.
git_helpers/git-helper.sh
git_helpers/README.md
Update documentation to describe repo-specific prefixes, dual-profile alias configuration, and new behavior.
  • Document that commit message prefixes are loaded from .GIT_HELPER_PREFIX in the repo root (first line) or fall back to GIT_HELPER_PREFIX env var, and reiterate placeholder support.
  • Add examples for creating .GIT_HELPER_PREFIX and for using the environment variable, plus guidance on adding .GIT_HELPER_PREFIX to .gitignore vs committing it.
  • Update alias documentation to mention the Utilities → Add alias to shell profile option, dual writes to ~/.bashrc and ~/.bash_profile, and sourcing either profile to activate changes.
git_helpers/README.md

Possibly linked issues

  • #unknown: PR implements reading GIT_HELPER_PREFIX from .GIT_HELPER_PREFIX in repo root, matching the file-based prefix feature request.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@justinkumpe justinkumpe merged commit 7196847 into dev Jan 7, 2026
2 of 3 checks passed
@justinkumpe justinkumpe deleted the feature/git_helper-23 branch January 7, 2026 01:06
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • In cmd_utils_add_alias, the previous behavior prompted before replacing an existing alias, but the new implementation silently removes any existing alias definitions in both ~/.bashrc and ~/.bash_profile; consider re-introducing a confirmation step or at least scoping replacement to the file where the alias was originally found to avoid surprising users.
  • The quote/whitespace stripping logic for current_prefix in the repo-specific branch of cmd_utils_set_prefix looks fragile (${current_prefix#"${current_prefix%%[![:space:]]*}"} etc.) and hard to reason about; consider replacing it with a simpler, more explicit approach (e.g., using a single sed or well-scoped parameter expansion) that doesn’t reuse the variable inside its own pattern.
  • Sourcing both ~/.bashrc and ~/.bash_profile unconditionally in cmd_utils_add_alias and cmd_utils_set_prefix may introduce side effects or duplicated initialization for some setups; you might want to check which file is actually used for interactive shells and only source that, or at least gate sourcing behind a confirmation prompt.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `cmd_utils_add_alias`, the previous behavior prompted before replacing an existing alias, but the new implementation silently removes any existing alias definitions in both `~/.bashrc` and `~/.bash_profile`; consider re-introducing a confirmation step or at least scoping replacement to the file where the alias was originally found to avoid surprising users.
- The quote/whitespace stripping logic for `current_prefix` in the repo-specific branch of `cmd_utils_set_prefix` looks fragile (`${current_prefix#"${current_prefix%%[![:space:]]*}"}` etc.) and hard to reason about; consider replacing it with a simpler, more explicit approach (e.g., using a single `sed` or well-scoped parameter expansion) that doesn’t reuse the variable inside its own pattern.
- Sourcing both `~/.bashrc` and `~/.bash_profile` unconditionally in `cmd_utils_add_alias` and `cmd_utils_set_prefix` may introduce side effects or duplicated initialization for some setups; you might want to check which file is actually used for interactive shells and only source that, or at least gate sourcing behind a confirmation prompt.

## Individual Comments

### Comment 1
<location> `git_helpers/git-helper.sh:750-751` </location>
<code_context>
+    local repo_root
+    repo_root=$(git rev-parse --show-toplevel 2>/dev/null || true)
+    if [[ -n "$repo_root" && -f "$repo_root/.GIT_HELPER_PREFIX" ]]; then
+      # Read first line and remove only trailing newline/carriage return (preserve spaces)
+      prefix=$(head -n 1 "$repo_root/.GIT_HELPER_PREFIX" 2>/dev/null | sed 's/[\r\n]*$//' || true)
+    fi
+  fi
</code_context>

<issue_to_address>
**issue (bug_risk):** The sed pattern for stripping CRLF may not reliably remove Windows-style carriage returns.

`sed 's/[\r\n]*$//'` depends on `\r` being treated as a carriage-return escape in basic regex, which isn’t portable across all `sed` implementations (some treat it as literal `r`). To make CRLF handling robust, prefer something like `sed 's/\r\?$//'` or `tr -d '\r' | head -n1`, and keep this consistent with `cmd_utils_set_prefix` so both paths parse the file the same way.
</issue_to_address>

### Comment 2
<location> `git_helpers/git-helper.sh:1798-1801` </location>
<code_context>
+        return
+      fi
+      
+      local prefix_file="$repo_root/.GIT_HELPER_PREFIX"
+      local current_prefix=""
+      if [[ -f "$prefix_file" ]]; then
+        current_prefix=$(cat "$prefix_file" 2>/dev/null | head -n 1 || true)
+        current_prefix="${current_prefix#\"${current_prefix%%[![:space:]]*}\"}"
+        current_prefix="${current_prefix%\"${current_prefix##*[![:space:]]}\"}"
</code_context>

<issue_to_address>
**issue (bug_risk):** The logic for stripping quotes/whitespace from the existing prefix is complex and likely not doing what is intended.

These two parameter expansion lines are extremely hard to reason about and may not reliably “strip optional surrounding quotes/whitespace” as intended; they can also corrupt valid prefixes that legitimately contain quotes or spaces. Since you already read just the first line, consider reusing the simpler CRLF‑stripping approach from `expand_commit_prefix` (e.g., `head -n1 | sed 's/…$//'`) and avoid quote munging altogether, or replace this with a much simpler, clearly correct pattern if outer quotes truly need to be removed.
</issue_to_address>

### Comment 3
<location> `git_helpers/git-helper.sh:1733-1736` </location>
<code_context>

-  # Source the profile to apply changes immediately
-  source "$profile_file" 2>/dev/null || true
+  # Source both profiles to apply changes immediately
+  for profile_file in "${profile_files[@]}"; do
+    source "$profile_file" 2>/dev/null || true
+  done
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Sourcing both ~/.bashrc and ~/.bash_profile from a non-interactive script can introduce side effects.

This may trigger interactive-only setup (e.g., prompts, keybindings, long‑running commands) in a non-interactive context, leading to slowness or unexpected behavior. Consider either not sourcing and asking the user to open a new shell, sourcing only when an interactive shell is detected (e.g., `[[ $- == *i* ]]` or `[[ -n "$PS1" ]]`), or adding an explicit opt‑in flag to source profiles immediately.

```suggestion
  # Source profiles only in interactive shells to avoid side effects in non-interactive contexts.
  if [[ $- == *i* ]] || [[ -n "$PS1" ]]; then
    for profile_file in "${profile_files[@]}"; do
      # shellcheck source=/dev/null
      source "$profile_file" 2>/dev/null || true
    done
  else
    msg+=$'\nOpen a new shell or run the following to apply changes immediately:'
    for profile_file in "${profile_files[@]}"; do
      msg+=$'\n  source '"$profile_file"
    done
  fi
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +750 to +751
# Read first line and remove only trailing newline/carriage return (preserve spaces)
prefix=$(head -n 1 "$repo_root/.GIT_HELPER_PREFIX" 2>/dev/null | sed 's/[\r\n]*$//' || true)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The sed pattern for stripping CRLF may not reliably remove Windows-style carriage returns.

sed 's/[\r\n]*$//' depends on \r being treated as a carriage-return escape in basic regex, which isn’t portable across all sed implementations (some treat it as literal r). To make CRLF handling robust, prefer something like sed 's/\r\?$//' or tr -d '\r' | head -n1, and keep this consistent with cmd_utils_set_prefix so both paths parse the file the same way.

Comment on lines +1798 to +1801
local prefix_file="$repo_root/.GIT_HELPER_PREFIX"
local current_prefix=""
if [[ -f "$prefix_file" ]]; then
current_prefix=$(cat "$prefix_file" 2>/dev/null | head -n 1 || true)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The logic for stripping quotes/whitespace from the existing prefix is complex and likely not doing what is intended.

These two parameter expansion lines are extremely hard to reason about and may not reliably “strip optional surrounding quotes/whitespace” as intended; they can also corrupt valid prefixes that legitimately contain quotes or spaces. Since you already read just the first line, consider reusing the simpler CRLF‑stripping approach from expand_commit_prefix (e.g., head -n1 | sed 's/…$//') and avoid quote munging altogether, or replace this with a much simpler, clearly correct pattern if outer quotes truly need to be removed.

Comment on lines +1733 to +1736
# Source both profiles to apply changes immediately
for profile_file in "${profile_files[@]}"; do
source "$profile_file" 2>/dev/null || true
done
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Sourcing both ~/.bashrc and ~/.bash_profile from a non-interactive script can introduce side effects.

This may trigger interactive-only setup (e.g., prompts, keybindings, long‑running commands) in a non-interactive context, leading to slowness or unexpected behavior. Consider either not sourcing and asking the user to open a new shell, sourcing only when an interactive shell is detected (e.g., [[ $- == *i* ]] or [[ -n "$PS1" ]]), or adding an explicit opt‑in flag to source profiles immediately.

Suggested change
# Source both profiles to apply changes immediately
for profile_file in "${profile_files[@]}"; do
source "$profile_file" 2>/dev/null || true
done
# Source profiles only in interactive shells to avoid side effects in non-interactive contexts.
if [[ $- == *i* ]] || [[ -n "$PS1" ]]; then
for profile_file in "${profile_files[@]}"; do
# shellcheck source=/dev/null
source "$profile_file" 2>/dev/null || true
done
else
msg+=$'\nOpen a new shell or run the following to apply changes immediately:'
for profile_file in "${profile_files[@]}"; do
msg+=$'\n source '"$profile_file"
done
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant