mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Any work that can take noticeable time now runs under the UI's status line: a Reporter's Status with a label message, or a LoggedCmd step. The UI: - status lines are a stack: a Status or LoggedCmd inside another shows its own line, then the outer one is drawn again, where before it ended the outer one for good - a message (Info, Warn, Note, Say, data on Stdout/Stderr) clears the line, prints and draws it again below; an unended line holds it - a question (Ask, Confirm, Answer, Secret), the picker and ui.Terminal hold it until they're done - no status line starts once the run is interrupted, as nothing would clear it - the run log's path is read without the log's lock, as the status line reads it under outMu Covered, by site and label: - finder.target: finding_vm; Lima's limactl --version: checking_backend - bringUp's checks (seeds, instance, recordFolder, hostChecks, ssh, requirements) and a running VM's go-on (proxy, pins, mount check): checking_vm; startOnce after the agent: starting; the self-check's probes: checking_network; pinHostKeys: reading_host_keys - setUpVM (sync, ssh config, links, clone seed): setting_up_vm; each devcontainer command: running_script; makeMachine: creating; buildOnce: checking_image; paste's count and rm: reading_pasted - volumeOf's lookup (diskutil), for launch, adopt, move, ls and rm: looking_up_volume - vm.ListAll (devvm ls): reading_vms; devvm doctor's checks: doctor_checking - devvm agent import: agent_import_reading (walk, links, opencode), agent_store_saving (copy, marketplace git checks, tmutil); devvm agent save: agent_save_reading, agent_save_comparing, agent_store_saving - devvm stop (from its pins check on): checking_vm; a delete, an orphan's teardown and Lima's DeleteImage: deleting; devvm git-protect and clone on/off's .git work (leftBehind, mountFolder, unmountFolder): git_protecting; git-protect's re-read: finding_vm - devvm clone add: clone_reading, clone_adding; clone fetch: clone_fetching; planClone: clone_planning; the clone check before rm or a remake: clone_checking; history export and import: history_exporting, history_importing; a remake's home: saving_home, restoring_home - devvm upgrade's install: upgrade_installing; the shared tools' step back and .NET's downloads: resolving_tools; gc's caches: reading_space; the retention settings (daily and in gc): retaining Work that takes the terminal stays off: the shell, ssh-add's passphrase (checkAgent, Agent.Ensure, reloadAgent) and an agent's login. Tests and guard: - msg.Fake: OnStatus and Showing; its LoggedCmd shows its step - backendtest.Fake: OnCall - TestLaunchStatusLines: every backend call of a new, running and stopped VM's launch runs under a status line but the shell's and Running's (pid files) - TestSSHAddOffStatusLine: ssh-add, on the user's agent or devvm's, never runs under one; chflagsCalls fails a .git lock or unlock with none - the structure test's status-lines rule (statusSites, statusFree) - TestStatusLinesNest, TestMessagesClearTheStatusLine, TestQuestionsHoldTheStatusLine, TestSecretAndPickerHoldTheStatusLine, TestTerminalHoldsTheStatusLine, TestNoStatusLineOnceInterrupted, TestFakeStatus, TestAgentImportStatus, TestAgentSaveStatus, TestDoctorReport, TestProblems, TestList, TestListLooksUpVolumesOnce, TestVolumeOfCache, TestWithSDKDownloads, TestRetainStatus, TestSetCloneOn, TestTeardownLeavesNothing The rule is written in the cli skill (rule 14, checklist, review), the codebase-standards skill (Show what devvm waits for, its checklist line and rules.md's row), Contributing's CLI page (Status lines), its tests and structure pages, and the troubleshooting page. Co-Authored-By: Claude Opus 5.5 <[email protected]>
112 lines
3.5 KiB
Go
112 lines
3.5 KiB
Go
package vm
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/devvmhq/devvm/internal/backend"
|
|
"github.com/devvmhq/devvm/internal/gitprotect"
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
)
|
|
|
|
// Settings shows and changes the folder's VM's settings: its .git
|
|
// protection (here), its size (size.go), its ports (ports.go), its SSH
|
|
// agent forwarding (sshagent.go) and its transparent mode
|
|
// (transparent.go).
|
|
type Settings struct{ *Env }
|
|
|
|
// GitProtect returns the folder's VM's .git protection: on, off, or
|
|
// clone for a --clone VM, which mounts no .git (gitprotect.Mode, as
|
|
// devvm ls shows it).
|
|
func (e Settings) GitProtect(ctx context.Context) (string, error) {
|
|
t, err := e.finder.target(ctx, need{has: hasMade, noVM: msg.NoVMGitProtect})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return gitprotect.Mode(t.st), nil
|
|
}
|
|
|
|
// Clone returns whether the folder's VM has its own clone of the repo,
|
|
// CloneOn, or mounts the folder, CloneOff (devvm clone).
|
|
func (e Settings) Clone(ctx context.Context) (string, error) {
|
|
t, err := e.finder.target(ctx, need{has: hasMade})
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if isClone(t.st) {
|
|
return CloneOn, nil
|
|
}
|
|
return CloneOff, nil
|
|
}
|
|
|
|
// SetGitProtect turns the folder's VM's .git protection on or off. Locks
|
|
// change only while the VM is stopped, so nothing in it can race them: a
|
|
// running VM's choice is saved, and set when devvm next finds it stopped
|
|
// (starter.hostChecks), which a restart the user agrees to does now
|
|
// (restartOr). On locks .git as it is then.
|
|
func (e Settings) SetGitProtect(ctx context.Context, mode string) error {
|
|
t, err := e.finder.target(ctx, need{has: hasMade, noVM: msg.NoVMGitProtect})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
vm := t.f.Name
|
|
if isClone(t.st) {
|
|
return msg.GitProtectClone(vm)
|
|
}
|
|
p := e.Protector(t.f.Dir)
|
|
if mode == gitprotect.Off && gitprotect.Mode(t.st) != gitprotect.Off {
|
|
if ok, err := t.widen("devvm git-protect off"); !ok {
|
|
return err
|
|
}
|
|
}
|
|
// Elsewhere there are no locks to race. It's read again, as it may
|
|
// have started while widen asked.
|
|
if p.Locker.Locks() {
|
|
// Only the read under a status line: restartOr's start may ask
|
|
// for a key's passphrase.
|
|
stop := e.Status(msg.FindingVM())
|
|
err := t.refresh(ctx)
|
|
stop()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if t.in.Status == backend.StatusRunning {
|
|
if err := gitprotect.SetNext(ctx, t.st, mode); err != nil {
|
|
return err
|
|
}
|
|
return e.restartOr(ctx, vm, e.Info, msg.GitProtectNextStop(mode, vm))
|
|
}
|
|
}
|
|
// The VM is stopped, or the host has no locks to race: on names the
|
|
// nested repos the protection doesn't cover. The folder's walk and
|
|
// its locks run under a status line.
|
|
defer e.Status(msg.GitProtecting(vm))()
|
|
if mode != gitprotect.Off {
|
|
found := e.starter.walk(t.f.Dir, false)
|
|
p.Nested = &found.Repos
|
|
}
|
|
return setGitProtect(ctx, e.Env, p, t, mode)
|
|
}
|
|
|
|
// setGitProtect sets a stopped VM's .git protection, and says what it
|
|
// did: on a host without locks, off quiets the launches' warning.
|
|
func setGitProtect(ctx context.Context, e *Env, p *gitprotect.Protector, t *target, mode string) error {
|
|
vm := t.f.Name
|
|
if err := p.Set(ctx, t.st, mode); err != nil {
|
|
return err
|
|
}
|
|
g, _ := gitprotect.Of(t.st)
|
|
switch _, err := os.Lstat(filepath.Join(t.f.Dir, ".git")); {
|
|
case mode == gitprotect.Off && !p.Locker.Locks():
|
|
e.Info(msg.GitUnprotectedQuiet(vm))
|
|
case mode == gitprotect.Off:
|
|
e.Info(msg.GitUnlocked(vm))
|
|
case err != nil && len(g.Made.Repos) == 0:
|
|
e.Info(msg.GitLockLater(vm))
|
|
default:
|
|
e.Info(msg.GitLocked(vm))
|
|
}
|
|
return nil
|
|
}
|