@@ -18,6 +18,8 @@ import (
1818 "golang.org/x/crypto/ssh"
1919)
2020
21+ const TestGitRepoUri = "https://github.com/libgit2/TestGitRepository"
22+
2123func TestListRemotes(t *testing.T) {
2224 t.Parallel()
2325 repo := createTestRepo(t)
@@ -51,7 +53,7 @@ func TestCertificateCheck(t *testing.T) {
5153 repo := createTestRepo(t)
5254 defer cleanupTestRepo(t, repo)
5355
54- remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository" )
56+ remote, err := repo.Remotes.Create("origin", TestGitRepoUri )
5557 checkFatal(t, err)
5658 defer remote.Free()
5759
@@ -72,7 +74,7 @@ func TestRemoteConnect(t *testing.T) {
7274 repo := createTestRepo(t)
7375 defer cleanupTestRepo(t, repo)
7476
75- remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository" )
77+ remote, err := repo.Remotes.Create("origin", TestGitRepoUri )
7678 checkFatal(t, err)
7779 defer remote.Free()
7880
@@ -95,7 +97,7 @@ func TestRemoteConnectOption(t *testing.T) {
9597 option.Name = "origin"
9698 option.Flags = RemoteCreateSkipInsteadof
9799
98- remote, err := repo.Remotes.CreateWithOptions("https://github.com/libgit2/TestGitRepository" , option)
100+ remote, err := repo.Remotes.CreateWithOptions(TestGitRepoUri , option)
99101 checkFatal(t, err)
100102
101103 err = remote.ConnectFetch(nil, nil, nil)
@@ -107,7 +109,7 @@ func TestRemoteLs(t *testing.T) {
107109 repo := createTestRepo(t)
108110 defer cleanupTestRepo(t, repo)
109111
110- remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository" )
112+ remote, err := repo.Remotes.Create("origin", TestGitRepoUri )
111113 checkFatal(t, err)
112114 defer remote.Free()
113115
@@ -127,7 +129,7 @@ func TestRemoteLsFiltering(t *testing.T) {
127129 repo := createTestRepo(t)
128130 defer cleanupTestRepo(t, repo)
129131
130- remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository" )
132+ remote, err := repo.Remotes.Create("origin", TestGitRepoUri )
131133 checkFatal(t, err)
132134 defer remote.Free()
133135
@@ -162,7 +164,7 @@ func TestRemotePruneRefs(t *testing.T) {
162164 err = config.SetBool("remote.origin.prune", true)
163165 checkFatal(t, err)
164166
165- remote, err := repo.Remotes.Create("origin", "https://github.com/libgit2/TestGitRepository" )
167+ remote, err := repo.Remotes.Create("origin", TestGitRepoUri )
166168 checkFatal(t, err)
167169 defer remote.Free()
168170
@@ -493,3 +495,40 @@ func TestRemoteSSH(t *testing.T) {
493495 t.Error("Expected remote heads")
494496 }
495497}
498+
499+ func TestNewRemoteDetached(t *testing.T) {
500+ _, err := NewRemoteDetached(TestGitRepoUri)
501+ if err != nil {
502+ t.Fatalf("error %v", err)
503+ }
504+ }
505+
506+ func TestRemoteDetached_LsDetached(t *testing.T) {
507+ r, _ := NewRemoteDetached(TestGitRepoUri)
508+
509+ t.Run("NoInput", func(t *testing.T) {
510+ rh, err := r.LsDetached(FetchOptions{})
511+ if err != nil {
512+ t.Fatalf("error %v", err)
513+ }
514+
515+ if len(rh) == 0 {
516+ t.Fatalf("Not listing all references")
517+ }
518+ })
519+
520+ t.Run("Filters", func(t *testing.T) {
521+ rh, err := r.LsDetached(FetchOptions{}, "HEAD")
522+ if err != nil {
523+ t.Fatalf("error %v", err)
524+ }
525+
526+ if len(rh) == 0 {
527+ t.Fatalf("Not listing all references")
528+ }
529+
530+ if rh[0].Name != "HEAD" {
531+ t.Fatalf("Not listing all references")
532+ }
533+ })
534+ }
0 commit comments