支持Git提交导入及未提交源码叠加,APK原名下载和完成通知。新增服务端设备安装与按工程维护的私有文件清单,修复Wrapper预检查、布局及IDE读锁和保存状态问题。更新协议、测试和部署记录;服务端0.7.0,插件0.7.1。
115 lines
4.5 KiB
Go
115 lines
4.5 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCheckoutAdvancedWithManagedUntrackedFiles(t *testing.T) {
|
|
if _, e := exec.LookPath("git"); e != nil {
|
|
t.Skip("Git unavailable")
|
|
}
|
|
s := testServer(t)
|
|
s.workspaceRoot = t.TempDir()
|
|
work := filepath.Join(s.workspaceRoot, "checkout")
|
|
os.MkdirAll(work, 0700)
|
|
git := func(args ...string) {
|
|
t.Helper()
|
|
if out, e := exec.Command("git", append([]string{"-C", work}, args...)...).CombinedOutput(); e != nil {
|
|
t.Fatalf("git %v: %v %s", args, e, out)
|
|
}
|
|
}
|
|
put := func(path, text string) { t.Helper(); writeFixture(t, filepath.Join(work, path), text) }
|
|
snapshot := func() *GitSnapshot {
|
|
t.Helper()
|
|
g, e := gitSnapshot(work)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
return g
|
|
}
|
|
git("init", "-q")
|
|
git("config", "core.autocrlf", "false")
|
|
put("a.txt", "old\n")
|
|
put("gone.txt", "removed in next commit\n")
|
|
put("restored.txt", "tracked\n")
|
|
git("add", ".")
|
|
git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "old")
|
|
old := snapshot()
|
|
response := call(t, s, "POST", "/projects", WorkspaceRequest{WorkspacePath: work, Git: old})
|
|
if response.Code != 200 {
|
|
t.Fatal(response.Body.String())
|
|
}
|
|
var project map[string]string
|
|
json.Unmarshal(response.Body.Bytes(), &project)
|
|
p := project["id"]
|
|
response = call(t, s, "POST", "/projects/"+p+"/sync", SyncRequest{Revision: "old", Git: old, Files: map[string]File{"a.txt": file("old\n"), "gone.txt": file("removed in next commit\n"), "notes.docx": file("managed untracked document")}})
|
|
if response.Code != 200 {
|
|
t.Fatal(response.Body.String())
|
|
}
|
|
// 两边更新到新提交,未跟踪文档使仓库整体仍为 dirty。
|
|
git("restore", "--worktree", "--", "restored.txt")
|
|
put("a.txt", "new committed content\n")
|
|
os.Remove(filepath.Join(work, "gone.txt"))
|
|
put("added.txt", "new tracked file\n")
|
|
git("add", "a.txt", "gone.txt", "restored.txt", "added.txt")
|
|
git("-c", "user.name=Test", "-c", "user.email=test@example.invalid", "commit", "-qm", "new")
|
|
git("config", "core.autocrlf", "true")
|
|
put("a.txt", "new committed content\r\n")
|
|
current := snapshot()
|
|
if !current.Dirty || current.Head == old.Head {
|
|
t.Fatal("fixture must have advanced HEAD and untracked document")
|
|
}
|
|
if e := s.checkGit(p, current); e != nil {
|
|
t.Fatal("pristine tracked files blocked by unrelated untracked file", e)
|
|
}
|
|
manifest := s.manifest(p)
|
|
if manifest.Git == nil || manifest.Git.Head != current.Head || manifest.Revision != "" || manifest.Files["a.txt"].Hash != digest([]byte("new committed content\r\n")) || manifest.Files["added.txt"].Hash == "" || manifest.Files["restored.txt"].Hash == "" {
|
|
t.Fatal("manifest omitted current checkout", manifest)
|
|
}
|
|
if s.projects[p].Revision != "old" || len(s.projects[p].Files) != 3 {
|
|
t.Fatal("read-only check modified baseline")
|
|
}
|
|
response = call(t, s, "POST", "/projects/"+p+"/builds", map[string]string{"task": ":app:assembleDebug", "revision": "old"})
|
|
if response.Code != 409 {
|
|
t.Fatal("stale snapshot was accepted", response.Body.String())
|
|
}
|
|
// 索引有真实暂存修改时,即使工作文件被恢复为HEAD,也不能放行。
|
|
put("a.txt", "staged change\n")
|
|
git("add", "a.txt")
|
|
put("a.txt", "new committed content\r\n")
|
|
if e := s.checkGit(p, current); e == nil {
|
|
t.Fatal("staged change silently accepted")
|
|
}
|
|
git("reset", "--", "a.txt")
|
|
// 新增、修改未跟踪文件仍需保护。
|
|
put("surprise.txt", "remote new file\n")
|
|
if e := s.checkGit(p, current); e == nil {
|
|
t.Fatal("untracked remote addition accepted")
|
|
}
|
|
os.Remove(filepath.Join(work, "surprise.txt"))
|
|
put("notes.docx", "remote document edit")
|
|
if e := s.checkGit(p, current); e == nil {
|
|
t.Fatal("untracked remote edit accepted")
|
|
}
|
|
put("notes.docx", "managed untracked document")
|
|
response = call(t, s, "POST", "/projects/"+p+"/sync", SyncRequest{Revision: "new", Git: current, Files: map[string]File{"a.txt": {Hash: manifest.Files["a.txt"].Hash}, "notes.docx": {Hash: manifest.Files["notes.docx"].Hash}}})
|
|
if response.Code != 200 {
|
|
t.Fatal("new snapshot sync failed", response.Body.String())
|
|
}
|
|
for _, path := range []string{"added.txt", "restored.txt", "gone.txt"} {
|
|
if _, e := os.Stat(filepath.Join(work, path)); !os.IsNotExist(e) {
|
|
t.Fatal("tracked local deletion was not applied", path)
|
|
}
|
|
}
|
|
// assume-unchanged 不得掩盖实际服务端改动。
|
|
git("update-index", "--assume-unchanged", "a.txt")
|
|
put("a.txt", "real remote change\n")
|
|
if e := s.checkGit(p, current); e == nil {
|
|
t.Fatal("hidden real remote edit accepted")
|
|
}
|
|
}
|