fork of https://github.com/sourcegraph/zoekt
1// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package gitindex
16
17import (
18 "os/exec"
19 "testing"
20
21 git "github.com/go-git/go-git/v5"
22)
23
24func TestSetRemote(t *testing.T) {
25 dir := t.TempDir()
26
27 script := `mkdir orig
28cd orig
29git init -b master
30cd ..
31git clone orig/.git clone.git
32`
33
34 cmd := exec.Command("/bin/sh", "-euxc", script)
35 cmd.Dir = dir
36
37 if out, err := cmd.CombinedOutput(); err != nil {
38 t.Fatalf("execution error: %v, output %s", err, out)
39 }
40
41 r := dir + "/clone.git"
42 if err := setFetch(r, "origin", "+refs/heads/*:refs/heads/*"); err != nil {
43 t.Fatalf("addFetch: %v", err)
44 }
45
46 repo, err := git.PlainOpen(r)
47 if err != nil {
48 t.Fatal("PlainOpen", err)
49 }
50
51 rm, err := repo.Remote("origin")
52 if err != nil {
53 t.Fatal("Remote", err)
54 }
55 if got, want := rm.Config().Fetch[0].String(), "+refs/heads/*:refs/heads/*"; got != want {
56 t.Fatalf("got %q want %q", got, want)
57 }
58}