Skip to content

[feature/git_helper-13] Added Update Check#14

Merged
justinkumpe merged 1 commit intodevfrom
feature/git_helper-13
Dec 30, 2025
Merged

[feature/git_helper-13] Added Update Check#14
justinkumpe merged 1 commit intodevfrom
feature/git_helper-13

Conversation

@justinkumpe
Copy link
Member

@justinkumpe justinkumpe commented Dec 30, 2025

Summary by Sourcery

Add versioning and update-check functionality to the git-helper script, enhance UI tool detection with optional guided installation, and extend branch management utilities.

New Features:

  • Introduce script version metadata and display it in the UI title.
  • Add an interactive update check that compares the local script version with the latest version from GitHub and informs the user how to update.
  • Provide an option in the utilities menu to run the update check from within the script.
  • Add an interactive flow to install whiptail or dialog via the system package manager when no UI tool is available, with a persistent opt-out.
  • Extend branch management to create a new branch from a specific commit, existing branch, or tag via a new menu option.

@justinkumpe justinkumpe self-assigned this Dec 30, 2025
@justinkumpe justinkumpe added the enhancement New feature or request label Dec 30, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 30, 2025

Reviewer's Guide

Adds a versioned update-check mechanism that pulls the latest script version from GitHub, improves UI-tool detection with optional package installation and persistent opt-out, and introduces a new branch-creation flow that allows creating a branch from a commit, branch, or tag while wiring these features into the existing menus.

Sequence diagram for improved UI tool detection and optional installation

sequenceDiagram
  actor User
  participant GitHelperScript
  participant SystemPackageManager
  participant ConfigFilesystem

  User->>GitHelperScript: run git-helper.sh
  GitHelperScript->>GitHelperScript: detect_ui()
  alt whiptail installed
    GitHelperScript->>GitHelperScript: UI_TOOL = whiptail
    GitHelperScript-->>User: continue with whiptail UI
  else dialog installed
    GitHelperScript->>GitHelperScript: UI_TOOL = dialog
    GitHelperScript-->>User: continue with dialog UI
  else no UI tool installed
    GitHelperScript->>GitHelperScript: UI_TOOL = text
    GitHelperScript->>ConfigFilesystem: check NEVER_INSTALL_FILE
    alt never install recorded
      GitHelperScript-->>User: continue with text UI
    else not recorded
      GitHelperScript-->>User: prompt_ui_choice()
      alt user chooses yes
        GitHelperScript-->>User: select_ui_tool()
        User-->>GitHelperScript: choose whiptail or dialog
        GitHelperScript->>SystemPackageManager: install_ui_package(selected_tool)
        alt installation succeeds
          GitHelperScript->>GitHelperScript: UI_TOOL = selected_tool
          GitHelperScript-->>User: Successfully installed selected_tool
        else installation fails
          GitHelperScript-->>User: Installation failed, continue with text UI
        end
      else user chooses no
        GitHelperScript-->>User: continue with text UI
      else user chooses never
        GitHelperScript->>ConfigFilesystem: create NEVER_INSTALL_FILE
        GitHelperScript-->>User: continue with text UI
      end
    end
  end
Loading

Sequence diagram for the new update check command

sequenceDiagram
  actor User
  participant GitHelperScript
  participant GitHubRaw

  User->>GitHelperScript: select check_updates
  GitHelperScript->>GitHelperScript: cmd_check_updates()
  GitHelperScript->>GitHelperScript: fetch_latest_version()
  alt curl not available
    GitHelperScript-->>User: ui_message "Failed to check for updates"
  else curl available
    GitHelperScript->>GitHubRaw: GET raw git-helper.sh
    GitHubRaw-->>GitHelperScript: script contents
    GitHelperScript->>GitHelperScript: extract latest_version from SCRIPT_VERSION
    alt latest_version empty
      GitHelperScript-->>User: ui_message "Could not retrieve version information"
    else latest_version found
      GitHelperScript->>GitHelperScript: compare_versions(SCRIPT_VERSION, latest_version)
      alt versions equal
        GitHelperScript-->>User: ui_message "You are running the latest version"
      else current older
        GitHelperScript-->>User: ui_message with update instructions
      else current newer
        GitHelperScript-->>User: ui_message "development version newer than latest release"
      end
    end
  end
Loading

Sequence diagram for creating a branch from commit, branch, or tag

sequenceDiagram
  actor User
  participant GitHelperScript
  participant Git

  User->>GitHelperScript: open Branches menu
  GitHelperScript-->>User: show menu including branch_create_from
  User->>GitHelperScript: select branch_create_from
  GitHelperScript->>GitHelperScript: cmd_branch_create_from()
  GitHelperScript-->>User: ui_input "New branch name"
  User-->>GitHelperScript: enter name
  alt branch name empty
    GitHelperScript-->>User: cancel operation
  else name provided
    GitHelperScript-->>User: ui_menu "Branch from..." (commit, branch, tag, cancel)
    User-->>GitHelperScript: choose option
    alt commit selected
      GitHelperScript-->>User: ui_input "Commit hash"
      User-->>GitHelperScript: enter commit hash
      alt hash not empty
        GitHelperScript->>Git: git checkout -b name hash
        Git-->>GitHelperScript: branch created
        GitHelperScript-->>User: print_info "Created branch from commit"
      end
    else branch selected
      GitHelperScript->>GitHelperScript: pick_branch()
      GitHelperScript-->>User: branch picker UI
      User-->>GitHelperScript: select source branch
      alt source not empty
        GitHelperScript->>Git: git checkout -b name source_branch
        Git-->>GitHelperScript: branch created
        GitHelperScript-->>User: print_info "Created branch from branch"
      end
    else tag selected
      GitHelperScript-->>User: ui_input "Tag name"
      User-->>GitHelperScript: enter tag
      alt tag resolves
        GitHelperScript->>Git: git rev-parse tag
        Git-->>GitHelperScript: success
        GitHelperScript->>Git: git checkout -b name tag
        Git-->>GitHelperScript: branch created
        GitHelperScript-->>User: print_info "Created branch from tag"
      else tag missing
        GitHelperScript-->>User: ui_message "Tag not found"
      end
    else cancel selected
      GitHelperScript-->>User: return to Branches menu
    end
  end
Loading

File-Level Changes

Change Details Files
Introduce script versioning and GitHub-based update check, including semantic version comparison and a user-facing command to check for updates.
  • Add SCRIPT_VERSION and GITHUB_REPO constants and include version in the UI title string
  • Implement compare_versions helper to compare semantic version strings
  • Implement fetch_latest_version to download the latest script from GitHub and extract SCRIPT_VERSION
  • Implement cmd_check_updates to compare local and remote versions and display appropriate messages via ui_message
  • Wire the new check_updates command into the utilities menu
git_helpers/git-helper.sh
Enhance UI tool detection to optionally install whiptail/dialog via the system package manager, with a persistent opt-out configuration.
  • Add CONFIG_DIR and NEVER_INSTALL_FILE paths using XDG_CONFIG_HOME or .config fallback
  • Implement detect_package_manager to choose a supported package manager (apt-get/dnf/yum/pacman/zypper/apk)
  • Implement install_ui_package to install a chosen UI tool using sudo and the detected package manager
  • Implement prompt_ui_choice and select_ui_tool to let the user decide whether and which UI tool to install, with a persistent 'never install' flag
  • Extend detect_ui to use the new prompts and installation helpers, falling back to text mode when appropriate
git_helpers/git-helper.sh
Add a new branch creation workflow that allows creating a branch from a specific commit, existing branch, or tag, and expose it in the branches menu.
  • Implement cmd_branch_create_from to prompt for the new branch name, then source (commit, branch, or tag) and run git checkout -b accordingly
  • Integrate tag existence validation with a friendly error via ui_message
  • Add a new branch_create_from option to the branches menu and dispatch it to cmd_branch_create_from
git_helpers/git-helper.sh

Possibly linked issues

  • #feature/git_helper: PR implements SCRIPT_VERSION, shows it in the title, and adds a "Check for updates" command and menu option.

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

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `git_helpers/git-helper.sh:17` </location>
<code_context>
 HEIGHT=20
 WIDTH=78
 MENU_HEIGHT=12
+CONFIG_DIR="${XDG_CONFIG_HOME:-.config}/git-helper"
+NEVER_INSTALL_FILE="$CONFIG_DIR/never-install-ui"
+
</code_context>

<issue_to_address>
**issue (bug_risk):** CONFIG_DIR falls back to a relative directory instead of the XDG default of ~/.config when XDG_CONFIG_HOME is unset.

With `${XDG_CONFIG_HOME:-.config}` the config path becomes relative to the current working directory (e.g. `./.config/git-helper`), so state files end up wherever the script is run instead of in the standard XDG location. To follow the spec and use `$HOME/.config` as the fallback, you could do:

```bash
default_config_dir="${XDG_CONFIG_HOME:-$HOME/.config}"
CONFIG_DIR="$default_config_dir/git-helper"
```
</issue_to_address>

### Comment 2
<location> `git_helpers/git-helper.sh:406-408` </location>
<code_context>
+}
+
+# Fetch the latest version from GitHub
+fetch_latest_version() {
+  if ! command -v curl >/dev/null 2>&1; then
+    echo "curl not available for update check" >&2
+    return 1
+  fi
+  
+  local raw_url="https://raw.githubusercontent.com/$GITHUB_REPO/main/git_helpers/git-helper.sh"
+  local response
+  response=$(curl -s "$raw_url" 2>/dev/null) || return 1
+  
+  # Extract SCRIPT_VERSION from the file
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Network call for update check has no timeout, risking the script hanging indefinitely on bad networks.

Since `curl` is called without any timeout, this function can block for a long time on flaky or firewalled networks and make `cmd_check_updates` appear frozen. Consider adding connect and overall timeouts, for example:

```bash
response=$(curl -s --connect-timeout 5 --max-time 10 "$raw_url" 2>/dev/null) || return 1
```

```suggestion
  local raw_url="https://raw.githubusercontent.com/$GITHUB_REPO/main/git_helpers/git-helper.sh"
  local response
  response=$(curl -s --connect-timeout 5 --max-time 10 "$raw_url" 2>/dev/null) || return 1
```
</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.

@justinkumpe justinkumpe force-pushed the feature/git_helper-13 branch 2 times, most recently from 030d34e to 0ec01a1 Compare December 30, 2025 01:23
@justinkumpe justinkumpe changed the title [feature/git_helper-11] Added Update Check [feature/git_helper-13] Added Update Check Dec 30, 2025
@justinkumpe justinkumpe force-pushed the feature/git_helper-13 branch from 0ec01a1 to 0e4fc05 Compare December 30, 2025 01:27
@justinkumpe justinkumpe merged commit caf4b30 into dev Dec 30, 2025
3 checks passed
@justinkumpe justinkumpe deleted the feature/git_helper-13 branch December 30, 2025 01:28
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