-
Notifications
You must be signed in to change notification settings - Fork 534
Fetching into a bare repo doesn't work #518
Description
I'm trying to use go-git
(v4) to fetch from a remote into a bare repo, and I'm getting back an "already up-to-date" error even though I know for sure that the remote has new commits.
I was writing a test to see what happens when doing a non-fast-forwardable fetch (inspecting the code, I think there's a bug there too as it doesn't appear to check the fast-forward +
in the refspec at all), but it seems there's a bigger issue fetching at all.
Here is a shell script to set up a repro (run it in a new test directory):
#!/usr/bin/env bash
# Make bare repo
mkdir repo
cd repo
git init --bare
cd ..
# Make checkout and initialize remote repo
mkdir checkout
cd checkout
echo test > test
git init
git add test
git commit -m "test"
git remote add r ../repo
git push r master:master
cd ..
# Make a 2nd commit that's not pushed yet
cd checkout
echo test2 > test2
git add test2
git commit -m "test2"
cd ..
# Make a remote in the bare repo
cd repo
git remote add c $PWD/../checkout
Then, compile and run this Go program in the same directory:
package main
import (
"fmt"
"gopkg.in/src-d/go-billy.v3/osfs"
gogit "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
)
func main() {
bare := osfs.New("./repo/")
s, err := filesystem.NewStorage(bare)
if err != nil {
panic(err)
}
repo, err := gogit.Open(s, nil)
if err != nil {
panic(err)
}
o := &gogit.FetchOptions{
RemoteName: "c",
RefSpecs: []config.RefSpec{"master:master"},
}
err = repo.Fetch(o)
if err != nil {
fmt.Printf("Couldn't fetch from remote (non-force): %+v\n", err)
}
o = &gogit.FetchOptions{
RemoteName: "c",
RefSpecs: []config.RefSpec{"+master:master"},
}
err = repo.Fetch(o)
if err != nil {
fmt.Printf("Couldn't fetch from remote (force): %+v\n", err)
}
}
I get the output:
$ go build -o fetch main.go && ./fetch
Couldn't fetch from remote (non-force): already up-to-date
Couldn't fetch from remote (force): already up-to-date
However, if you try it on the command line, this is the behavior:
repo$ git fetch c master:master
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From /tmp/gogittest/repo/../checkout
93e4174..b66c535 master -> master
* [new branch] master -> c/master
Is go-git intended to be used to access bare repos? Am I doing something wrong? Thanks! And thanks for the great project.