sync_test.go
| 1 | package gitcmd |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestConvertNonBareSkipsSymlinkedDotGit(t *testing.T) { |
| 10 | g, repo := newTestGit(t) |
| 11 | real := g.RepoPath(repo) |
| 12 | wt := filepath.Join(g.cfg.ReposDir(), "linked") |
| 13 | if err := os.Mkdir(wt, 0o755); err != nil { |
| 14 | t.Fatal(err) |
| 15 | } |
| 16 | if err := os.Symlink(real, filepath.Join(wt, ".git")); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | g.ConvertNonBareRepos() |
| 20 | if _, err := os.Stat(filepath.Join(real, "HEAD")); err != nil { |
| 21 | t.Fatalf("real git data damaged: %v", err) |
| 22 | } |
| 23 | if _, err := os.Lstat(filepath.Join(wt, ".git")); err != nil { |
| 24 | t.Fatalf("symlinked repo was touched: %v", err) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestConvertNonBareRecoversBareTmp(t *testing.T) { |
| 29 | g, repo := newTestGit(t) |
| 30 | tmp := filepath.Join(g.cfg.ReposDir(), ".x.git"+bareTmpSuffix) |
| 31 | if err := os.Rename(g.RepoPath(repo), tmp); err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | g.ConvertNonBareRepos() |
| 35 | if _, err := os.Stat(filepath.Join(g.cfg.ReposDir(), "x.git", "HEAD")); err != nil { |
| 36 | t.Fatalf("not recovered: %v", err) |
| 37 | } |
| 38 | } |
| 39 |