|
5 | 5 | "io/ioutil"
|
6 | 6 | "os"
|
7 | 7 | "path/filepath"
|
| 8 | + "runtime" |
8 | 9 | "strings"
|
9 | 10 | "testing"
|
10 | 11 |
|
@@ -635,19 +636,35 @@ func (s *SuiteDotGit) TestAlternates(c *C) {
|
635 | 636 | c.Assert(err, IsNil)
|
636 | 637 |
|
637 | 638 | // Multiple alternates.
|
638 |
| - content := []byte("/Users/username/rep1//.git/objects\n../../../rep2//.git/objects") |
| 639 | + var strContent string |
| 640 | + if runtime.GOOS == "windows" { |
| 641 | + strContent = "C:\\Users\\username\\repo1\\.git\\objects\r\n..\\..\\..\\rep2\\.git\\objects" |
| 642 | + } else { |
| 643 | + strContent = "/Users/username/rep1//.git/objects\n../../../rep2//.git/objects" |
| 644 | + } |
| 645 | + content := []byte(strContent) |
639 | 646 | f.Write(content)
|
640 | 647 | f.Close()
|
641 | 648 |
|
642 | 649 | dotgits, err := dir.Alternates()
|
643 | 650 | c.Assert(err, IsNil)
|
644 |
| - c.Assert(dotgits[0].fs.Root(), Equals, "/Users/username/rep1/.git") |
| 651 | + if runtime.GOOS == "windows" { |
| 652 | + c.Assert(dotgits[0].fs.Root(), Equals, "C:\\Users\\username\\repo1\\.git") |
| 653 | + } else { |
| 654 | + c.Assert(dotgits[0].fs.Root(), Equals, "/Users/username/rep1/.git") |
| 655 | + } |
645 | 656 |
|
646 | 657 | // For relative path:
|
647 | 658 | // /some/absolute/path/to/dot-git -> /some/absolute/path
|
648 |
| - pathx := strings.Split(tmp, "/") |
| 659 | + pathx := strings.Split(tmp, string(filepath.Separator)) |
649 | 660 | pathx = pathx[:len(pathx)-2]
|
650 |
| - resolvedPath := filepath.Join(pathx...) |
| 661 | + // Use string.Join() to avoid malformed absolutepath on windows |
| 662 | + // C:Users\\User\\... instead of C:\\Users\\appveyor\\... . |
| 663 | + resolvedPath := strings.Join(pathx, string(filepath.Separator)) |
651 | 664 | // Append the alternate path to the resolvedPath
|
652 |
| - c.Assert(dotgits[1].fs.Root(), Equals, filepath.Join("/", resolvedPath, "rep2", ".git")) |
| 665 | + expectedPath := filepath.Join(string(filepath.Separator), resolvedPath, "rep2", ".git") |
| 666 | + if runtime.GOOS == "windows" { |
| 667 | + expectedPath = filepath.Join(resolvedPath, "rep2", ".git") |
| 668 | + } |
| 669 | + c.Assert(dotgits[1].fs.Root(), Equals, expectedPath) |
653 | 670 | }
|
0 commit comments