Skip to content

Conversation

hansonw
Copy link

@hansonw hansonw commented May 24, 2025

Thanks for this tool! this implements #20 :)

Summary

  • Implemented a new branch sub-command that prints git branches with numbers
    • Handles edge cases (e.g. running outside a git repo, detached HEAD)
  • Added gb as an alias for scmpuff_branch in the initialization scripts
  • Created shell wrapper functions to export numbered branch names for both Bash and Fish users
  • Extended initialization to load the new branch functionality and updated the binary’s command list

Testing

  • go test ./...
  • make features (failed to find zsh during integration tests)

Example

CleanShot 2025-05-23 at 22 32 37@2x

@hansonw hansonw changed the title Add a numbered wrapper for git branch feat: add support for git branch May 24, 2025
@mroth
Copy link
Owner

mroth commented May 26, 2025

Very cool! Thanks for such a detailed PR. It might take me a little while to review this, hopefully @hansonw you might be up for a few rounds of back and forth so we can figure out how this would interface with the broader refactor of the codebase? I really appreciate this!

Copy link
Owner

@mroth mroth left a comment

Choose a reason for hiding this comment

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

Some initial thoughts/questions.

}

func gitBranchOutput() []byte {
out, err := exec.Command("git", "branch", "--color=never").Output()
Copy link
Owner

Choose a reason for hiding this comment

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

It looks like there unfortunately isn't a --porcelain (guaranteed not to change across git versions) version of git branch output like there is with git status? I'm wondering how to make the parsing resilient to multiple versions of git in the wild (including future versions). Of course, once I get around to #33 that could be a good long term solution. Another possibility while relying on CLI git, do you think it might make sense to use something like --format to specify a specific format? I'm not sure if that might be more resilient to change.

Copy link
Owner

Choose a reason for hiding this comment

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

Another edge case to consider might be whether there is a way to ensure the pager is disabled on a per command basis here, so git doesn't try to run its output through a pager if there more lines of branches than it thinks will fit on the user screen. From the git branch documentation it appears that is the default, we might want to verify if it is automatically disabled somehow based on detecting whether STDOUT is a pipe or tty.

Copy link
Author

Choose a reason for hiding this comment

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

--format w/ pager forcibly disabled makes sense to me here!

let e++
(( e++ ))
Copy link
Owner

Choose a reason for hiding this comment

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

Is this syntax fully POSIX compatible?

Copy link
Author

Choose a reason for hiding this comment

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

This was automatically flagged by the shell linter you have in the repo, can’t see the exact message any more but I believe it mentioned that this has been supported in Bash for decades

@@ -22,6 +22,28 @@ function scmpuff_status
end
end

function scmpuff_branch
scmpuff_clear_vars
set -lx scmpuff_env_char "e"
Copy link
Owner

Choose a reason for hiding this comment

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

Clobbering the existing file variable could be problematic: it might not be obvious to a user that if they list branches, the previous file shortcuts that were displayed to them would stop. working. I suspect we need a second variable here (which unfortunately does add to implementation complexity, but I don't know a great way around that).

Copy link
Author

@hansonw hansonw May 27, 2025

Choose a reason for hiding this comment

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

I was previously a very active user of scm_breeze (I definitely prefer the simplicity of scmpuff!) and fwiw it shared the same env var space between all numbered commands. It definitely wasn’t ideal but was pretty intuitive I think

@@ -0,0 +1,45 @@
Feature: branch command
Copy link
Owner

Choose a reason for hiding this comment

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

Really appreciate these integration tests!

@hansonw
Copy link
Author

hansonw commented May 27, 2025

Thanks for reviewing! If you’re in the middle of a big refactor maybe it’s easier to just wait until after that lands to make this change?

full disclosure this PR was 95% generated by OpenAI Codex (which I work on ;)) so nbd to just do it again later!

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

Successfully merging this pull request may close these issues.

2 participants