MCPcopy Index your code
hub / github.com/docker/docker-agent / Status

Method Status

pkg/worktree/worktree.go:271–297  ·  view source on GitHub ↗

Status inspects the worktree and reports whether it holds uncommitted changes, untracked files, or commits added since creation.

(ctx context.Context)

Source from the content-addressed store, hash-verified

269// Status inspects the worktree and reports whether it holds uncommitted
270// changes, untracked files, or commits added since creation.
271func (wt *Worktree) Status(ctx context.Context) (Status, error) {
272 out, err := gitOutput(ctx, wt.Dir, "status", "--porcelain")
273 if err != nil {
274 return Status{}, fmt.Errorf("inspecting worktree: %w", err)
275 }
276
277 var st Status
278 for line := range strings.SplitSeq(out, "\n") {
279 if line == "" {
280 continue
281 }
282 if strings.HasPrefix(line, "??") {
283 st.Untracked = true
284 } else {
285 st.Modified = true
286 }
287 }
288
289 // HEAD moving away from the recorded branch point means the session
290 // committed something. When BaseCommit is empty (worktree created in a
291 // repo without commits) any resolvable HEAD counts as new work.
292 if head, err := gitOutput(ctx, wt.Dir, "rev-parse", "HEAD"); err == nil {
293 st.NewCommits = head != wt.BaseCommit
294 }
295
296 return st, nil
297}
298
299// Remove deletes the worktree's directory and its branch, discarding any
300// uncommitted changes, untracked files, and commits. Callers decide when

Callers 5

TestStatusCleanFunction · 0.80
cleanupWorktreeMethod · 0.80

Calls 1

gitOutputFunction · 0.70

Tested by 4

TestStatusCleanFunction · 0.64