Bug: gogit checkout robustness: remotes[0] panic, wrong error message, empty version output, non-idempotent 0444 writes

Open Beginner friendly
#86 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
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
git, go
Domain
cli, tooling

Research direction

Start by reading cmd/checkout.go around the quoted lines: the remote lookup at line 100, the --pr error at line 151, the version assignment block at 108-155 and the two os.WriteFile calls at 159 and 167. Check whether existing tests under cmd/ cover checkout, and add cases for an empty remotes/URLs config, the PR error text, no branch flag, and re-running against an existing output file. Done when all four paths return a message or file instead of panicking, misreporting or failing on re-run.

Written by the indexing model from the issue text.

Description

bug

Description

A group of robustness problems in cmd/checkout.go (master 198a18f):

1. Potential index-out-of-range panics — line 100:

remoteURL := remotes[0].Config().URLs[0]

remotes can be empty for a locally-created .git (no remote configured), and URLs can be empty in a broken config; both panic instead of producing an error message.

2. Wrong variable in the PR checkout error — line 151:

err = fmt.Errorf("unable to checkout git branch: %s, error: %v", o.tag, err)

This is the --pr path but the message prints o.tag. It should report pr-%d.

3. Empty --version-output — version is only set when --branch/--tag/--pr is given (lines 108–155). With none of them set, line 159 happily writes an empty file, which downstream builds then consume as an empty version. It should either default to the checked-out branch/HEAD or fail explicitly.

4. Non-idempotent output files — lines 159 and 167 write with mode 0444:

err = os.WriteFile(o.versionOutput, ..., 0444)

On a re-run (same workspace, e.g. a retried CI step) the write fails with permission denied because the previous file is read-only and owned by the same user. 0644 (or remove-then-write) keeps re-runs working.

Each item is small and independently testable; happy to split into separate PRs if preferred.

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.