mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
Linux hosts have no unprivileged immutable flag, so devvm can't lock .git there. It now warns at every launch of a VM that mounts a folder with a .git (git_unprotected), unless it's a --clone VM or the user chose devvm git-protect off (git.chosen), and it names, after the fact, the hooks and config that changed (git_changed). It sums what a lock would cover, .git/commondir, include.path targets and the folder core.hooksPath names, never through a symlink out of the project folder and within bounds (git_watch_blind names what it can't fully watch), at each launch that finds the VM stopped and at devvm stop. A check on such a host runs protect's reports without locking: git_replaced, git_commondir, stray worktrees, git dirs that appeared, core.hooksPath and delegations into the project folder, and a submodule's folder that isn't a git dir (git_gitdir_not_git), in which nothing is created and which the watch doesn't sum as a git dir. Co-Authored-By: Claude Opus 5.5 <[email protected]>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
//go:build darwin || linux
|
|
|
|
package platform
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A file's change ID moves with any change, its times set back
|
|
// included, and a FileInfo without a stat has none.
|
|
func TestChangeID(t *testing.T) {
|
|
f := filepath.Join(t.TempDir(), "f")
|
|
if err := os.WriteFile(f, []byte("one"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stat := func() string {
|
|
fi, err := os.Lstat(f)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return ChangeID(fi)
|
|
}
|
|
was := stat()
|
|
if !strings.HasPrefix(was, "ino ") || !strings.Contains(was, " ctime ") {
|
|
t.Fatalf("ChangeID %q", was)
|
|
}
|
|
time.Sleep(20 * time.Millisecond)
|
|
if err := os.WriteFile(f, []byte("two"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.Chtimes(f, time.Unix(1, 0), time.Unix(1, 0)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if now := stat(); now == was {
|
|
t.Errorf("unchanged: %q", now)
|
|
}
|
|
if id := ChangeID(fakeInfo{}); id != "" {
|
|
t.Errorf("no stat: %q", id)
|
|
}
|
|
}
|
|
|
|
// fakeInfo is a FileInfo without a stat.
|
|
type fakeInfo struct{ os.FileInfo }
|
|
|
|
func (fakeInfo) Sys() any { return nil }
|