Bug: --token file://… content is not trimmed, trailing newline breaks authentication

Open Beginner friendly
#87 0 comments 0 reactions 0 assignees View on GitHub

@linuxsuren-fs is already working on this.

Since Nov 17, 2026.

  • #93 by @linuxsuren-fs — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
cli

Research direction

The read happens in cmd/status.go around line 52, in the file:// branch of the token option handling; start by reading that block and the surrounding status option struct to see where o.token is consumed afterwards. Change the assignment to trim whitespace from the file contents and wrap the read error with the attempted path so failures name the file. Done means a token file ending in a newline authenticates, and go build ./... plus the existing tests under cmd/ still pass.

Written by the indexing model from the issue text.

Description

bug

Description

gogit status supports reading the token from a file — cmd/status.go:52:

if strings.HasPrefix(o.token, "file://") {
    tokenFile := strings.TrimPrefix(o.token, "file://")
    var data []byte
    if data, err = os.ReadFile(tokenFile); err == nil {
        o.token = string(data)
    }
}

The content is used as-is. Token files very commonly carry a trailing newline (Kubernetes secrets written via stringData, echo $TOKEN > file, editors), and then every API call fails authentication with a confusing provider error such as 401 Unauthorized, because the token sent is <token>\n.

Also note the error from a failed read is returned as-is with no context about which file was attempted.

Suggested fix

o.token = strings.TrimSpace(string(data))

plus wrap the read error with the file path. One-line fix, big usability win for the documented file:///var/token use case.

Dominant language
Go
Stars
19
Forks
3
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LinuxSuRen/gogit

All issues in LinuxSuRen/gogit

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.