fix: address verified review findings (branches-checkout-status-1)

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 17:38:53 +02:00
1 parent 6e523d969d
commit 58f0fc4bf9
27 files changed
+281 -65

No files matched your search

+15 -3
View File
@@ -29,13 +29,25 @@ type BranchConfig struct {
// CurrentBranchConfig reads the configuration of the checked-out branch, failing with
// ErrNotOnBranch when HEAD is detached or dir is not a checkout.
func CurrentBranchConfig(ctx context.Context, runner Runner, dir string) (BranchConfig, error) {
name, err := runner.Output(ctx, dir, false, "symbolic-ref", "--short", "HEAD")
if err != nil || name == "" {
return BranchConfig{}, ErrNotOnBranch
name, err := CurrentBranch(ctx, runner, dir)
if err != nil {
return BranchConfig{}, err
}
return ReadBranchConfig(ctx, runner, dir, name), nil
}
// CurrentBranch names the checked-out branch, failing with ErrNotOnBranch when HEAD is detached
// or dir is not a checkout. It reads the full ref because --short answers heads/NAME for a branch
// that shares its name with a tag.
func CurrentBranch(ctx context.Context, runner Runner, dir string) (string, error) {
ref, err := runner.Output(ctx, dir, false, "symbolic-ref", "--quiet", "HEAD")
name := strings.TrimPrefix(ref, "refs/heads/")
if err != nil || name == "" {
return "", ErrNotOnBranch
}
return name, nil
}
// ReadBranchConfig reads branch.<name>.remote, .merge and the keys pr checkout records.
// Missing or malformed keys stay empty.
func ReadBranchConfig(ctx context.Context, runner Runner, dir, name string) BranchConfig {