Skip to content

fix: Var() should trim the trailing newline of git var output - #92

Open
mokshupadhyay wants to merge 1 commit into
gookit:mainfrom
mokshupadhyay:fix/var-trim-newline
Open

mokshupadhyay wants to merge 1 commit into
gookit:mainfrom
mokshupadhyay:fix/var-trim-newline

Conversation

@mokshupadhyay

@mokshupadhyay mokshupadhyay commented Dec 3, 2026 •

Copy link
Copy Markdown

gitw.Var(name) runs git var <name> and returned the command output as it is, including the trailing newline. Editor() uses Var("GIT_EDITOR") as its fallback, so it can return an editor value that is just a newline.

Real results of Var("GIT_EDITOR") and Editor() with the GIT_EDITOR, VISUAL and EDITOR environment variables set to empty (so Editor() has to fall back to git var), on master and with this change:

Var("GIT_EDITOR")   master: "\n"     after: ""
Editor()            master: "\n"     after: "/usr/bin/vim"   (Editor() now falls through to its search for vim, vi, emacs or nano)

The fix trims the trailing \r and \n from the output of git var.

Test: TestVar_noTrailingNewline in util_test.go checks that Var("GIT_DEFAULT_BRANCH") (git always prints a name for it) is not empty and has no trailing newline; it fails on master and passes now. go test ./... passes in every package, go vet ./... reports nothing and the changed files are gofmt-clean. I did not run golangci-lint.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant