[feature/git_helper-23] Added ability for repo specific GIT_HELPER_Prefix#25
[feature/git_helper-23] Added ability for repo specific GIT_HELPER_Prefix#25justinkumpe merged 1 commit intomainfrom
Conversation
Reviewer's GuideImplements 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 utilitysequenceDiagram
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
Flow diagram for commit prefix resolution from .GIT_HELPER_PREFIX and GIT_HELPER_PREFIXflowchart 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]
Flow diagram for alias and GIT_HELPER_PREFIX synchronization across bash profilesflowchart 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]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The logic in
cmd_utils_set_prefixfor readingcurrent_prefixfrom.GIT_HELPER_PREFIXappears brittle (and the quote-stripping expansions are effectively no-ops); consider reusing the existingexpand_commit_prefixfile-reading approach or simplifying this to a straightforwardhead -n 1without the broken quote manipulation. - There is a fair amount of duplicated logic for managing
GIT_HELPER_PREFIXin shell profiles betweencmd_utils_add_aliasandcmd_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_PREFIXfile 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>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 |
There was a problem hiding this comment.
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).
Summary by Sourcery
Add repo-specific configuration for commit message prefixes and improve the git-helper UI and utilities.
New Features:
Enhancements:
Documentation: