Skip to content

[feature/git_helper-23] Added ability for repo specific GIT_HELPER_Prefix#25

Merged
justinkumpe merged 1 commit intomainfrom
dev
Jan 7, 2026
Merged

[feature/git_helper-23] Added ability for repo specific GIT_HELPER_Prefix#25
justinkumpe merged 1 commit intomainfrom
dev

Conversation

@justinkumpe
Copy link
Member

@justinkumpe justinkumpe commented Jan 7, 2026

Summary by Sourcery

Add repo-specific configuration for commit message prefixes and improve the git-helper UI and utilities.

New Features:

  • Allow commit message prefixes to be defined per repository via a .GIT_HELPER_PREFIX file, falling back to the GIT_HELPER_PREFIX environment variable.
  • Provide a utility menu option to configure the commit message prefix either globally via shell profiles or per repository via .GIT_HELPER_PREFIX.

Enhancements:

  • Adjust dialog and menu heights dynamically based on terminal size for better UX.
  • Disable shadows in dialog/whiptail UI dialogs for a cleaner appearance.
  • Update the alias utility to manage aliases and GIT_HELPER_PREFIX in both ~/.bashrc and ~/.bash_profile and apply changes immediately.
  • Clarify and expand README documentation for commit prefix configuration and alias behavior.

Documentation:

  • Document repo-specific and environment-based commit prefix configuration, including examples and .gitignore considerations.
  • Update README to describe the new alias behavior and the utilities menu changes.

@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 and environment-based commit prefix resolution, adds an interactive prefix configuration utility, synchronizes aliases and GIT_HELPER_PREFIX across bash profiles, and improves the TUI by dynamically sizing dialogs and disabling shadows for dialog/whiptail.

Sequence diagram for interactive prefix configuration utility

sequenceDiagram
  actor User
  participant GitHelper as git-helper.sh
  participant Menu as menu_utils
  participant SetPrefix as cmd_utils_set_prefix
  participant Git as git
  participant Bashrc as bashrc_and_bash_profile
  participant Repo as Repo_root

  User->>GitHelper: Open Utilities menu
  GitHelper->>Menu: menu_utils
  Menu->>User: Show utilities options
  User-->>Menu: Select set_prefix
  Menu->>SetPrefix: cmd_utils_set_prefix

  SetPrefix->>User: ui_menu scope (local, repo, cancel)
  User-->>SetPrefix: Choose local
  SetPrefix->>Bashrc: Ensure ~/.bashrc and ~/.bash_profile exist
  SetPrefix->>User: ui_input current GIT_HELPER_PREFIX
  User-->>SetPrefix: Enter new prefix
  SetPrefix->>Bashrc: Remove existing GIT_HELPER_PREFIX lines
  SetPrefix->>Bashrc: Append export GIT_HELPER_PREFIX
  SetPrefix->>GitHelper: export GIT_HELPER_PREFIX
  SetPrefix->>User: ui_message confirmation
  Note over User,GitHelper: Alternative path
  User-->>SetPrefix: Choose repo
  SetPrefix->>Git: git rev-parse checks
  Git-->>SetPrefix: repo_root or error
  SetPrefix->>Repo: Read existing .GIT_HELPER_PREFIX (if any)
  SetPrefix->>User: ui_input repo prefix
  User-->>SetPrefix: Enter repo prefix
  SetPrefix->>Repo: Write first line to .GIT_HELPER_PREFIX
  SetPrefix->>User: ui_message repo-specific confirmation
Loading

Flow diagram for commit prefix resolution from .GIT_HELPER_PREFIX and GIT_HELPER_PREFIX

flowchart TD
  A[start expand_commit_prefix] --> B[Check if inside git work tree]
  B -->|no| C[Set prefix to empty string]
  C --> H[If prefix empty use GIT_HELPER_PREFIX env]
  B -->|yes| D[Get repo_root via git rev-parse]
  D -->|repo_root empty| C
  D -->|repo_root found| E[Check for repo_root/.GIT_HELPER_PREFIX]
  E -->|file missing| C
  E -->|file exists| F[Read first line of .GIT_HELPER_PREFIX]
  F --> G[Strip trailing CR/LF, assign to prefix]
  G --> H[If prefix empty use GIT_HELPER_PREFIX env]
  H -->|still empty| I[Echo empty string and return]
  H -->|has value| J[Get current_branch]
  J --> K[Extract ticket digits after last dash]
  K --> L[Replace {{branch}} with branch name]
  L --> M[Replace {{ticket}} with ticket number]
  M --> N[Echo expanded prefix and return]
Loading

Flow diagram for alias and GIT_HELPER_PREFIX synchronization across bash profiles

flowchart TD
  A[start cmd_utils_add_alias] --> B[Determine script_path]
  B --> C[Ensure ~/.bashrc and ~/.bash_profile exist]
  C --> D["Prompt user for alias_name (default git_helper)"]
  D --> E[Remove existing alias alias_name from both files]
  E --> F[Build alias_line alias name to script_path]
  F --> G[Append alias_line to both files]
  G --> H[eval alias_line]
  H --> I[Ask user to add or update GIT_HELPER_PREFIX in profiles]
  I -->|no| J[Source both profiles]
  I -->|yes| K[Prompt for prefix value]
  K -->|empty| L[Do not change GIT_HELPER_PREFIX]
  K -->|non-empty| M[Remove any GIT_HELPER_PREFIX from both files]
  M --> N[Append export GIT_HELPER_PREFIX to both files]
  N --> O[export GIT_HELPER_PREFIX in current session]
  L --> J
  O --> J[Source both profiles]
  J --> P[Show confirmation message and return]
Loading

File-Level Changes

Change Details Files
Make dialog/whiptail UI height and menu size dynamic and remove shadows for better terminal compatibility.
  • Introduce helper functions to calculate dialog height from terminal lines and derive menu height from dialog height with sensible minimums.
  • Replace fixed HEIGHT and MENU_HEIGHT constants with values computed at startup.
  • Add --no-shadow flag to all whiptail and dialog invocations for menus, checklists, input boxes, yes/no dialogs, and text viewers.
git_helpers/git-helper.sh
Support repo-specific commit message prefixes via .GIT_HELPER_PREFIX with fallback to GIT_HELPER_PREFIX and placeholder expansion.
  • Extend expand_commit_prefix to first look for a .GIT_HELPER_PREFIX file in the git repo root and read its first line, preserving spaces but stripping trailing newline/CR.
  • Fallback to the GIT_HELPER_PREFIX environment variable when the repo file is absent or empty, then expand {{branch}} and {{ticket}} placeholders as before.
  • Add a tracked .GIT_HELPER_PREFIX example file at repo root and document precedence and usage in README.
git_helpers/git-helper.sh
.GIT_HELPER_PREFIX
git_helpers/README.md
Add an interactive utility command to configure commit prefixes either globally in shell profiles or per repository.
  • Implement cmd_utils_set_prefix which prompts for scope (local shell profiles vs repo-specific) via ui_menu.
  • For local scope, update GIT_HELPER_PREFIX across both ~/.bashrc and ~/.bash_profile by removing existing definitions, appending a new export line, exporting to current session, and notifying the user.
  • For repo scope, validate current directory is a git repo, determine repo root, read/update .GIT_HELPER_PREFIX there, and show guidance about optionally ignoring or committing the file.
git_helpers/git-helper.sh
Update alias management to operate on both ~/.bashrc and ~/.bash_profile and keep GIT_HELPER_PREFIX synchronized.
  • Change cmd_utils_add_alias to touch, update, and source both ~/.bashrc and ~/.bash_profile instead of only ~/.bash_profile.
  • Remove any existing alias and GIT_HELPER_PREFIX entries from both profile files before appending new alias and export lines.
  • Adjust user-facing messages and menu labels to reflect shell profile (plural) behavior and clarify where alias/prefix are stored.
git_helpers/git-helper.sh
git_helpers/README.md

Possibly linked issues

  • #[feature/git_helper]: .GIT_HELPER_PREFIX file support in the PR directly implements the requested file-based GIT_HELPER_PREFIX feature.

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 enabled auto-merge (rebase) January 7, 2026 01:06
@justinkumpe justinkumpe merged commit 36872e5 into main Jan 7, 2026
2 of 3 checks passed
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 2 issues, and left some high level feedback:

  • The logic in cmd_utils_set_prefix for reading current_prefix from .GIT_HELPER_PREFIX appears brittle (and the quote-stripping expansions are effectively no-ops); consider reusing the existing expand_commit_prefix file-reading approach or simplifying this to a straightforward head -n 1 without the broken quote manipulation.
  • There is a fair amount of duplicated logic for managing GIT_HELPER_PREFIX in shell profiles between cmd_utils_add_alias and cmd_utils_set_prefix; extracting common helpers for "ensure profile files", "remove existing GIT_HELPER_PREFIX", and "write new prefix" would make the behavior easier to maintain and reason about.
  • The new .GIT_HELPER_PREFIX file added at the repository root will apply a default prefix to anyone using the tool in this repo; if this is meant only as an example, consider removing it from version control and documenting its creation instead, or clearly treating it as a shared project standard.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic in `cmd_utils_set_prefix` for reading `current_prefix` from `.GIT_HELPER_PREFIX` appears brittle (and the quote-stripping expansions are effectively no-ops); consider reusing the existing `expand_commit_prefix` file-reading approach or simplifying this to a straightforward `head -n 1` without the broken quote manipulation.
- There is a fair amount of duplicated logic for managing `GIT_HELPER_PREFIX` in shell profiles between `cmd_utils_add_alias` and `cmd_utils_set_prefix`; extracting common helpers for "ensure profile files", "remove existing GIT_HELPER_PREFIX", and "write new prefix" would make the behavior easier to maintain and reason about.
- The new `.GIT_HELPER_PREFIX` file added at the repository root will apply a default prefix to anyone using the tool in this repo; if this is meant only as an example, consider removing it from version control and documenting its creation instead, or clearly treating it as a shared project standard.

## Individual Comments

### Comment 1
<location> `git_helpers/git-helper.sh:1690-1682` </location>
<code_context>

-  if grep -Eq "^alias[[:space:]]+$alias_name=" "$profile_file" 2>/dev/null; then
-    if ui_yesno "$TITLE" "Alias '$alias_name' already exists in $profile_file. Replace it?"; then
+  # Remove existing alias from both files if present
+  for profile_file in "${profile_files[@]}"; do
+    if grep -Eq "^alias[[:space:]]+$alias_name=" "$profile_file" 2>/dev/null; then
       local tmp_alias
</code_context>

<issue_to_address>
**issue (bug_risk):** Existing aliases are now removed from profiles without any confirmation, which is a notable behavior change.

The previous behavior prompted before replacing an alias in a single profile; now matching aliases are removed from both ~/.bashrc and ~/.bash_profile without any prompt. This may override intentionally different aliases across profiles and feels unsafe. Please either reintroduce confirmation when an alias exists, or limit the change (e.g., only add if missing, or ask once before removing from all profiles).
</issue_to_address>

### Comment 2
<location> `git_helpers/git-helper.sh:1798-1803` </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:]]}\"}"
+      fi
+      
</code_context>

<issue_to_address>
**issue:** The quote/whitespace stripping logic for current_prefix is complex and likely incorrect.

These lines are difficult to follow and mix quote stripping with whitespace patterns in a way that’s likely to misbehave (e.g., prefixes containing spaces or lines without quotes). Because `.GIT_HELPER_PREFIX` is written only by this tool, consider reading the first line as-is (optionally trimming only CR/LF, like `expand_commit_prefix`) or using a simple, explicit whitespace trim. That should avoid subtle bugs and make the logic easier to understand.
</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.

touch "$profile_file"
# Update both bashrc and bash_profile
local profile_files=("$HOME/.bashrc" "$HOME/.bash_profile")
for profile_file in "${profile_files[@]}"; do
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): Existing aliases are now removed from profiles without any confirmation, which is a notable behavior change.

The previous behavior prompted before replacing an alias in a single profile; now matching aliases are removed from both ~/.bashrc and ~/.bash_profile without any prompt. This may override intentionally different aliases across profiles and feels unsafe. Please either reintroduce confirmation when an alias exists, or limit the change (e.g., only add if missing, or ask once before removing from all profiles).

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