Archived
Fetch in the background and follow changes in the repositories
- On startup, after the local state is shown, fetch the superproject and every initialized submodule (all remotes, prune, at most 8 at once). Fetches never prompt; failures show git's message. --no-fetch skips it, f fetches again. - The header shows "fetching n/m", then the fetch age and failures; the detail pane shows each submodule's last fetch and fetch errors. - The git provider polls each repository's metadata (refs, HEAD, index, .gitmodules) every 2 s and reports changes. The app reloads only what changed, keeping old values, expansion and cursor; loads are single-flight with coalesced reruns. Refresh is driven by the repositories, so a fetch in another shell updates the view like ours. - r reloads everything (worktree edits are not watched). - Docs: F50-F53, N1/N8 rewritten, D18-D20 (D12 superseded). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
19c6f17eb2
commit
27f0c0b5d2
@@ -4,9 +4,9 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -18,22 +18,40 @@ var gitEnv = append(os.Environ(),
|
||||
"LC_ALL=C",
|
||||
)
|
||||
|
||||
// gitError is a failed git command; Stderr is git's message.
|
||||
type gitError struct {
|
||||
Args []string
|
||||
Stderr string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *gitError) Error() string {
|
||||
msg := e.Stderr
|
||||
if msg == "" {
|
||||
msg = e.Err.Error()
|
||||
}
|
||||
return "git " + strings.Join(e.Args, " ") + ": " + msg
|
||||
}
|
||||
|
||||
func (e *gitError) Unwrap() error { return e.Err }
|
||||
|
||||
// run executes git in dir and returns stdout with the trailing newline
|
||||
// removed. The error includes git's stderr.
|
||||
func run(ctx context.Context, dir string, args ...string) (string, error) {
|
||||
return runEnv(ctx, dir, nil, args...)
|
||||
}
|
||||
|
||||
// runEnv is run with additional environment variables.
|
||||
func runEnv(ctx context.Context, dir string, env []string, args ...string) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, "git", append([]string{"-C", dir}, args...)...)
|
||||
cmd.Env = gitEnv
|
||||
cmd.Env = slices.Concat(gitEnv, env) // a fresh slice: run is called concurrently
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
if ctx.Err() != nil {
|
||||
return "", ctx.Err()
|
||||
}
|
||||
msg := strings.TrimSpace(stderr.String())
|
||||
if msg == "" {
|
||||
msg = err.Error()
|
||||
}
|
||||
return "", fmt.Errorf("git %s: %s", strings.Join(args, " "), msg)
|
||||
return "", &gitError{Args: args, Stderr: strings.TrimSpace(stderr.String()), Err: err}
|
||||
}
|
||||
return strings.TrimRight(stdout.String(), "\n"), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user