diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/basic/main.go | 7 | ||||
-rw-r--r-- | examples/fs_implementation/main.go | 22 | ||||
-rw-r--r-- | examples/fs_implementation/main_test.go | 12 | ||||
-rw-r--r-- | examples/latest/latest.go | 14 |
4 files changed, 31 insertions, 24 deletions
diff --git a/examples/basic/main.go b/examples/basic/main.go index 6dc2ba1..fd7f82e 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -9,13 +9,14 @@ import ( ) func main() { - fmt.Printf("Retrieving %q ...\n", os.Args[1]) - r, err := git.NewRepository(os.Args[1], nil) + url := os.Args[1] + fmt.Printf("Retrieving %q ...\n", url) + r, err := git.NewMemoryRepository() if err != nil { panic(err) } - if err = r.PullDefault(); err != nil { + if err = r.Clone(&git.CloneOptions{URL: url}); err != nil { panic(err) } diff --git a/examples/fs_implementation/main.go b/examples/fs_implementation/main.go index 552a923..a9bfbe6 100644 --- a/examples/fs_implementation/main.go +++ b/examples/fs_implementation/main.go @@ -9,7 +9,7 @@ import ( "strings" "gopkg.in/src-d/go-git.v4" - gogitFS "gopkg.in/src-d/go-git.v4/utils/fs" + "gopkg.in/src-d/go-git.v4/utils/fs" ) func main() { @@ -18,9 +18,9 @@ func main() { os.Exit(1) } - fs := newFS(os.Args[1]) + fs := NewCustomFS(os.Args[1]) - repo, err := git.NewRepositoryFromFS(fs, ".git") + repo, err := git.NewFilesystemRepository(fs, ".git") if err != nil { fmt.Fprint(os.Stderr, err) os.Exit(1) @@ -57,19 +57,19 @@ func usage() { // // Example: when constructed with 'newFS("tmp")', a path like 'foo--bar' // will represent the local path "/tmp/foo/bar". -type fs struct { +type CustomFS struct { base string } const separator = "--" -func newFS(path string) *fs { - return &fs{ +func NewCustomFS(path string) *CustomFS { + return &CustomFS{ base: path, } } -func (fs *fs) Stat(path string) (info os.FileInfo, err error) { +func (fs *CustomFS) Stat(path string) (info os.FileInfo, err error) { f, err := os.Open(fs.ToReal(path)) if err != nil { return nil, err @@ -85,19 +85,19 @@ func (fs *fs) Stat(path string) (info os.FileInfo, err error) { return f.Stat() } -func (fs *fs) ToReal(path string) string { +func (fs *CustomFS) ToReal(path string) string { parts := strings.Split(path, separator) return filepath.Join(fs.base, filepath.Join(parts...)) } -func (fs *fs) Open(path string) (gogitFS.ReadSeekCloser, error) { +func (fs *CustomFS) Open(path string) (fs.ReadSeekCloser, error) { return os.Open(fs.ToReal(path)) } -func (fs *fs) ReadDir(path string) ([]os.FileInfo, error) { +func (fs *CustomFS) ReadDir(path string) ([]os.FileInfo, error) { return ioutil.ReadDir(fs.ToReal(path)) } -func (fs *fs) Join(elem ...string) string { +func (fs *CustomFS) Join(elem ...string) string { return strings.Join(elem, separator) } diff --git a/examples/fs_implementation/main_test.go b/examples/fs_implementation/main_test.go index 9683b1b..ed56cf1 100644 --- a/examples/fs_implementation/main_test.go +++ b/examples/fs_implementation/main_test.go @@ -20,7 +20,7 @@ func TestMain(m *testing.M) { func setUp() { var err error - repo, err = tgz.Extract("../../storage/filesystem/internal/gitdir/fixtures/spinnaker-gc.tgz") + repo, err = tgz.Extract("../../storage/filesystem/internal/dotgit/fixtures/spinnaker-gc.tgz") if err != nil { panic(err) } @@ -36,7 +36,7 @@ func tearDown() { } func TestJoin(t *testing.T) { - fs := newFS("") + fs := NewCustomFS("") for i, test := range [...]struct { input []string expected string @@ -64,7 +64,7 @@ func TestJoin(t *testing.T) { } func TestStat(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "index", "info--refs", @@ -98,7 +98,7 @@ func TestStat(t *testing.T) { } func TestStatErrors(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, test := range [...]struct { input string errRegExp string @@ -125,7 +125,7 @@ func TestStatErrors(t *testing.T) { } func TestOpen(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "index", "info--refs", @@ -169,7 +169,7 @@ func TestOpen(t *testing.T) { } func TestReadDir(t *testing.T) { - fs := newFS(filepath.Join(repo, ".git/")) + fs := NewCustomFS(filepath.Join(repo, ".git/")) for i, path := range [...]string{ "info", ".", diff --git a/examples/latest/latest.go b/examples/latest/latest.go index 2ccddf1..684ebb7 100644 --- a/examples/latest/latest.go +++ b/examples/latest/latest.go @@ -8,17 +8,23 @@ import ( ) func main() { - fmt.Printf("Retrieving latest commit from: %q ...\n", os.Args[1]) - r, err := git.NewRepository(os.Args[1], nil) + url := os.Args[1] + + fmt.Printf("Retrieving latest commit from: %q ...\n", url) + r, err := git.NewMemoryRepository() if err != nil { panic(err) } - if err = r.Pull(git.DefaultRemoteName, "refs/heads/master"); err != nil { + if err = r.Clone(&git.CloneOptions{URL: url}); err != nil { + panic(err) + } + + head, err := r.Head() + if err != nil { panic(err) } - head := r.Remotes[git.DefaultRemoteName].Head() commit, err := r.Commit(head.Hash()) if err != nil { panic(err) |