Files
gitea-tea/internal/app/git.go
T

39 lines
1.1 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package app
import (
"context"
"io"
"gitea.dev/tea/internal/git"
)
func (a *application) git(ctx context.Context, args ...string) (string, error) {
return a.gitIn(ctx, a.options.cwd, args...)
}
// gitIn runs Git in dir, which is relative to the process's working directory, not to --cwd.
func (a *application) gitIn(ctx context.Context, dir string, args ...string) (string, error) {
snapshot, err := a.settings()
if err != nil {
return "", err
}
return a.deps.Git.Output(ctx, dir, a.policy(snapshot).CanPrompt(a.deps.Streams), args...)
}
// currentBranch names the checked-out branch without writing Git diagnostics.
func (a *application) currentBranch(ctx context.Context) (string, error) {
return git.CurrentBranch(ctx, a.gitProbe(), a.options.cwd)
}
// gitProbe runs exploratory Git commands whose failures are expected, without Git's diagnostics.
func (a *application) gitProbe() git.Runner {
if runner, ok := a.deps.Git.(git.System); ok {
runner.ErrOut = io.Discard
return runner
}
return a.deps.Git
}