Files
devvm/internal/cli/gitprotect.go
T
w3cjandClaude Opus 5.5 5f9e2e2408 fix(rm, git-protect): messages whose advice looped now name what works
- rm_export_failed names devvm rm --no-export, the flag that skips the
  export, in place of devvm rm -f.
- devvm rm --no-clone-check deletes a --clone VM without checking its
  clone, after warning that its unfetched commits and uncommitted changes
  go with it (clone_check_skipped). clone_check_failed names it.
- devvm git-protect on, strict or off on a running VM (macOS) is saved
  in the VM's state (git_protect_next) and applied the next time devvm
  finds the VM stopped: devvm stop, devvm restart, or the next launch of
  a VM stopped some other way, before it starts (git_protect_next_stop).
  So git_protect_flag_ignored's advice, devvm git-protect off, works on a
  running VM, and git_protect_running is gone. gitprotect owns the key
  (Next, SetNext; Set drops it); vm's checkGit applies it, then the
  .git check and set-id files, for devvm stop and every launch.

Tests: TestSetNext (internal/gitprotect); git_protect.txtar (a running
VM's choice saved, replaced, applied by devvm stop and by the next
launch); clone.txtar (clone_check_failed, then --no-clone-check);
e2e project's git-protect check and clone's rm check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-01 18:16:47 -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.",
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
}