mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-27 03:21:25 +01:00
fix: address verified review findings (branches-checkout-status-1)
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
27 files changed
+281
-65
No files matched your search
+15
-3
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user