-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add a test. Man, this took forever to implement.
- Loading branch information
Showing
14 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ztrue/tracerr" | ||
"gopkg.in/src-d/go-git.v4" | ||
) | ||
|
||
func fetch(repoPath string) error { | ||
r, err := git.PlainOpen(repoPath) | ||
if err != nil { | ||
return tracerr.Wrap(err) | ||
} | ||
|
||
remotes, err := r.Remotes() | ||
if err != nil { | ||
return tracerr.Wrap(err) | ||
} | ||
|
||
for _, remote := range remotes { | ||
remoteName := remote.Config().Name | ||
|
||
err, _, errB := GitCommand(repoPath, []string{"fetch", remoteName}) | ||
if err != nil { | ||
return tracerr.Errorf("Remote: %s %s %w", remoteName, errB.Bytes(), err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
cp "github.com/otiai10/copy" | ||
"gopkg.in/src-d/go-git.v4" | ||
"gopkg.in/src-d/go-git.v4/plumbing" | ||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func PrepareMultiFixtures(t *testing.T, name string, deps []string) string { | ||
newTestDataPath, err := ioutil.TempDir(os.TempDir(), "mutli_fixture") | ||
assert.NilError(t, err) | ||
|
||
for _, name := range deps { | ||
fixturePath := filepath.Join("testdata", name) | ||
newPath := filepath.Join(newTestDataPath, name) | ||
err = cp.Copy(fixturePath, newPath) | ||
assert.NilError(t, err) | ||
|
||
err = os.Rename(filepath.Join(newPath, ".gitted"), filepath.Join(newPath, ".git")) | ||
assert.NilError(t, err) | ||
} | ||
|
||
newRepoPath := PrepareFixture(t, name) | ||
FixFixtureGitConfig(t, newRepoPath, newTestDataPath) | ||
|
||
return newRepoPath | ||
} | ||
|
||
func FixFixtureGitConfig(t *testing.T, newRepoPath string, testDataPath string) { | ||
// Fix remote paths | ||
dotGitPath := filepath.Join(newRepoPath, ".git") | ||
gitConfigFilePath := filepath.Join(dotGitPath, "config") | ||
input, err := ioutil.ReadFile(gitConfigFilePath) | ||
assert.NilError(t, err) | ||
|
||
output := bytes.Replace(input, []byte("$TESTDATA$"), []byte(testDataPath), -1) | ||
|
||
err = ioutil.WriteFile(gitConfigFilePath, output, 0666) | ||
assert.NilError(t, err) | ||
} | ||
|
||
func Test_SimpleFetch(t *testing.T) { | ||
repoPath := PrepareMultiFixtures(t, "simple_fetch", []string{"multiple_file_change"}) | ||
fmt.Println(repoPath) | ||
|
||
err := fetch(repoPath) | ||
assert.NilError(t, err) | ||
|
||
r, err := git.PlainOpen(repoPath) | ||
assert.NilError(t, err) | ||
|
||
head, err := r.Head() | ||
assert.NilError(t, err) | ||
|
||
assert.Equal(t, head.Hash(), plumbing.NewHash("28cc969d97ddb7640f5e1428bbc8f2947d1ffd57")) | ||
|
||
ref, err := r.Reference(plumbing.NewRemoteReferenceName("origin1", "master"), true) | ||
assert.NilError(t, err) | ||
|
||
assert.Equal(t, ref.Hash(), plumbing.NewHash("7058b6b292ee3d1382670334b5f29570a1117ef1")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ref: refs/heads/master |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[core] | ||
repositoryformatversion = 0 | ||
filemode = true | ||
bare = false | ||
logallrefupdates = true | ||
[remote "origin1"] | ||
url = file://$TESTDATA$/multiple_file_change/.git | ||
fetch = +refs/heads/*:refs/remotes/origin1/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Unnamed repository; edit this file 'description' to name the repository. |
Binary file not shown.
Binary file added
BIN
+1.13 KB
testdata/simple_fetch/.gitted/objects/pack/pack-64633f8b9e2cb3a97cffd48edac3655d0fe90419.idx
Binary file not shown.
Binary file added
BIN
+206 Bytes
...data/simple_fetch/.gitted/objects/pack/pack-64633f8b9e2cb3a97cffd48edac3655d0fe90419.pack
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# pack-refs with: peeled fully-peeled sorted | ||
28cc969d97ddb7640f5e1428bbc8f2947d1ffd57 refs/heads/master |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |