Files
devvm/internal/cli/gitprotect.go
T
w3cjandClaude Opus 5.5 5a9f1b71c2 feat(cli): changes that apply at the next start ask to restart now
devvm size, devvm network on and off, devvm ssh-agent and devvm
git-protect (macOS) on a running VM ask in a terminal, without
--no-input, whether to restart it now ([Y/n]): yes restarts it as devvm
restart does, no or no question (no terminal, --no-input) keeps today's
message (size_next_start, net_set_running, agent_set_running,
git_protect_next_stop). Agents' mounts ask the same question.

- one owner: Env.restartNow (Env.CanAsk, then restart_now) and
  Env.restartOr (yes: Launch.Restart; else the later message), in
  internal/vm/existing.go; UpdateAgentDirs uses restartNow
- restart_now replaces update_mounts (AnswerFor: devvm restart)
- tests: TestRestartToApply (each command: yes, no, no terminal,
  --no-input), TestUpdateAgentDirs's --no-input case
- e2e: network's no-terminal on and off say net_set_running
- docs: commands.md's restarting note and answers table, ports-size,
  ssh, safety/network, git-protection, coding-agents; CLI reference

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 15:43:41 -07:00

48 lines
1.5 KiB
Go

package cli
import (
"github.com/spf13/cobra"
"github.com/w3cj/devvm/internal/gitprotect"
"github.com/w3cj/devvm/internal/msg"
"github.com/w3cj/devvm/internal/ui"
"github.com/w3cj/devvm/internal/vm"
)
// newGitProtectCmd is devvm git-protect [on|strict|off].
func newGitProtectCmd(u *ui.UI) *cobra.Command {
var asJSON bool
cmd := &cobra.Command{
Use: "git-protect [on|strict|off]",
Short: "Show or change .git protection for this folder's VM",
Long: "Show this folder's VM's .git protection, which locks the git hooks and config that run code on this machine, " +
"as on, strict, off, or clone for a --clone VM. " +
"devvm git-protect on, strict or off changes it at once on a stopped VM, and on a running one when it next stops, so in a terminal devvm offers to restart it now.",
Example: examples(
"devvm git-protect", "show the VM's .git protection",
"devvm git-protect off", "unlock .git, once the VM is stopped",
"devvm git-protect on", "lock .git again as it is then",
),
Args: showsOnly(maxArgs(1)),
ValidArgs: gitprotect.Modes,
RunE: func(cmd *cobra.Command, args []string) error {
var mode string
withEnv(u, func(env *vm.Env) error {
s := vm.Settings{Env: env}
if len(args) == 1 {
return s.SetGitProtect(cmd.Context(), args[0])
}
var err error
mode, err = s.GitProtect(cmd.Context())
return err
}, msg.GitProtectFailed)
if len(args) == 1 {
return nil
}
return printValue(u, asJSON, "mode", mode)
},
}
jsonFlag(cmd, &asJSON)
return cmd
}