Code Monkey home page Code Monkey logo

go-git's Introduction

WE CONTINUE THE DEVELOPMENT AT go-git/go-git. This repository is abandoned, and no further updates will be done on the code base, nor issue/prs will be answered or attended.

go-git logo GoDoc Build Status Build status codecov.io Go Report Card

go-git is a highly extensible git implementation library written in pure Go.

It can be used to manipulate git repositories at low level (plumbing) or high level (porcelain), through an idiomatic Go API. It also supports several types of storage, such as in-memory filesystems, or custom implementations thanks to the Storer interface.

It's being actively developed since 2015 and is being used extensively by source{d} and Keybase, and by many other libraries and tools.

Comparison with git

go-git aims to be fully compatible with git, all the porcelain operations are implemented to work exactly as git does.

git is a humongous project with years of development by thousands of contributors, making it challenging for go-git to implement all the features. You can find a comparison of go-git vs git in the compatibility documentation.

Installation

The recommended way to install go-git is:

go get -u gopkg.in/src-d/go-git.v4/...

We use gopkg.in to version the API, this means that when go get clones the package, it's the latest tag matching v4.* that is cloned and not the master branch.

Examples

Please note that the CheckIfError and Info functions used in the examples are from the examples package just to be used in the examples.

Basic example

A basic example that mimics the standard git clone command

// Clone the given repository to the given directory
Info("git clone https://github.com/src-d/go-git")

_, err := git.PlainClone("/tmp/foo", false, &git.CloneOptions{
    URL:      "https://github.com/src-d/go-git",
    Progress: os.Stdout,
})

CheckIfError(err)

Outputs:

Counting objects: 4924, done.
Compressing objects: 100% (1333/1333), done.
Total 4924 (delta 530), reused 6 (delta 6), pack-reused 3533

In-memory example

Cloning a repository into memory and printing the history of HEAD, just like git log does

// Clones the given repository in memory, creating the remote, the local
// branches and fetching the objects, exactly as:
Info("git clone https://github.com/src-d/go-siva")

r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
    URL: "https://github.com/src-d/go-siva",
})

CheckIfError(err)

// Gets the HEAD history from HEAD, just like this command:
Info("git log")

// ... retrieves the branch pointed by HEAD
ref, err := r.Head()
CheckIfError(err)


// ... retrieves the commit history
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
CheckIfError(err)

// ... just iterates over the commits, printing it
err = cIter.ForEach(func(c *object.Commit) error {
	fmt.Println(c)
	return nil
})
CheckIfError(err)

Outputs:

commit ded8054fd0c3994453e9c8aacaf48d118d42991e
Author: Santiago M. Mola <[email protected]>
Date:   Sat Nov 12 21:18:41 2016 +0100

    index: ReadFrom/WriteTo returns IndexReadError/IndexWriteError. (#9)

commit df707095626f384ce2dc1a83b30f9a21d69b9dfc
Author: Santiago M. Mola <[email protected]>
Date:   Fri Nov 11 13:23:22 2016 +0100

    readwriter: fix bug when writing index. (#10)

    When using ReadWriter on an existing siva file, absolute offset for
    index entries was not being calculated correctly.
...

You can find this example and many others in the examples folder.

Contribute

Contributions are more than welcome, if you are interested please take a look to our Contributing Guidelines.

License

Apache License Version 2.0, see LICENSE

go-git's People

Contributors

ajnavarro avatar alcortesm avatar darkowlzz avatar dpordomingo avatar erizocosmico avatar ferhatelmas avatar filipnavara avatar ilius avatar jfontan avatar joshuasjoding avatar klaidliadon avatar knqyf263 avatar maguro avatar mcarmonaa avatar mcuadros avatar muesli avatar mvdan avatar niukuo avatar orirawlings avatar orisano avatar saracen avatar serabe avatar shawnps avatar smola avatar strib avatar taralx avatar taruti avatar toqueteos avatar vancluever avatar vmarkovtsev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-git's Issues

clone remote repo via provided commit hash

Can you explain me how to clone repo if i kow sha commit hash?
In case of branches - i need to pull repo... but what in case of commit hash?

Also what is the best way to detect what user specify - branch, tag or commit ?

Diff between commits

First and foremost, this it an awesome package, just what I was looking for! I came across this and spent some time reading the docs, but couldn't find reference to how git-diff can be done, similar to https://godoc.org/github.com/libgit2/git2go#Diff. I noticed that there's https://godoc.org/gopkg.in/src-d/go-git.v3/diff, but this is more for comparison of the contents between a src and dst, which is different from retrieving a list of the diff files between two commits. Is functionality not available in go-git, or did I miss it in the docs?

Crawl all files currently of HEAD of a Repository

I've scoured all the included tests and searched for other projects which use this library - for an example of this very simple use case:

I simply want to clone a repository and look at the current HEAD and iterate through the files in the repo.

r, err := git.NewRepository("https://github.com/ben174/bugben", nil)

if err := r.Pull("origin", "refs/heads/master"); err != nil {
    panic(err)
}

tree := r.Tree() // Can't call without a HASH. Tried "HEAD" but that didn't work                                                  

All of the included tests in this repo seem to have a baked-in hash. I wouldn't want to include a hash since that would change over time.

Sorry, if this is better posed for Stack Overflow, say the word. But in this case I feel like it's something that's missing from the documentation.

AWS CodeCommit

Hi,

For checking out from AWS CodeCommit, I had to:

  • Remove lines 45-47 from clients/common/common.go (that adds the .git suffix)
  • Modify DefaultBranch in remote.go to return branch = "refs/heads/master" when SymbolicReference("HEAD") returns the empty string.

Need a way to delete a repository

Is there a way to delete a Repository?

When a Repository is loaded into memory, it would be nice if there was a way to remove it from memory without waiting first for garbage collection.

When a Repository is loaded into the filesystem, it would be nice if there was a way to remove it from the filesystem programmatically.

If there is a way to do this, I haven't been able to find it in the documentation.

Basic git functionalities needed

Is it possible to implement "git checkout" and "git commit" in the next stage? I'm developing a automating deploying tool using go-git. However, I find that some of the essential git methods are not implemented yet so that I have to use command line instead. And the second thing is that the Clone method does not function as "git clone", and I have to use "git checkout master" to retrieve the files. Would you enhance these aspect of go-git? Thanks.

Annotated Tags support

This is a request to support annotated tags in a similar way Commits are supported. Currently there doesn't seem to be a straightforward way to pull the tag annotations(unless I'm wrong). Below are my attempts. The first one hangs (it seems there is a leak/channel blocking indefinitely) before I can do anything useful. The second one errors out with unexpected client error: EOF

package main

import (
    "flag"
    "fmt"
    log "github.com/golang/glog"
    git "gopkg.in/src-d/go-git.v2"
    "gopkg.in/src-d/go-git.v2/clients/http"
    "io"
)

func main() {
    flag.Parse()
    defer log.Flush()
    auth := http.NewBasicAuth("myuser", ";xag]")
    r, err := git.NewRepository("https://bitbucket.org/myuser/tools", auth)
    if err != nil {
        log.Error(err)
        return
    }

    if err := r.Pull("origin", "refs/tags/0.0.1^{}"); err != nil {
        log.Error(err)
        return
    }
    triter := git.NewTreeIter(r)
    defer triter.Close()
    for {
        tree, err := triter.Next()
        if err != nil {
            if err == io.EOF {
                break
            }

            log.Error(err)
            return
        }
        log.Errorf("new tree %v", tree)
        return
    }

}
...

        req := &common.GitUploadPackRequest{}
        req.Have(previousTagSHA)
        req.Want(latestTagSHA)

        rc, err := repo.Fetch(req)
        if err != nil {
            log.Error(cx, err) 
            return nil, err
        }

How to count objects?

Hi,
I would like to compute git count-objects for a remote git repo. How can I do that?

Thanks.

reference not found errors when using bitbucket server

Hey there

First and foremost thank you for the library.

I've been trying to clone repos from my private bitbucket server and I constantly run into
"reference not found" errors. I was able to find out that its due to go-git requiring a HEAD reference which bitbucket server doesn't provide by default. Can you explain why HEAD is expected? Ignoring HEAD allows cloning of the particular repo.

Thanks a lot
-Alessandro

Add support for ref storage

The current implementation of Repository doesn't provide a way to persist branch, remote, and tag references to storage. I've been thinking about the best way to do this, and here is my proposal:

  1. Add a core.RefStorage interface with the necessary methods (the interface should be fairly simple)
  2. Add a core.Storage struct that composes both ObjectStorage and RefStorage
  3. Add a memory.RefStorage struct that implements core.RefStorage, along with a memory.NewRefStorage function
  4. Add a memory.NewStorage function
  5. Modify Repository to include a core.Storage interface instead of core.ObjectStorage

The definition of core.Storage would be something like this:

type Storage struct {
    Object ObjectStorage
    Ref    RefStorage
}

If this approach seems reasonable, I'll go ahead and put together a pull request.

Is there any common.Auth example?

I'm trying to find out how the authentication works. It looks to be a common.Auth interface but I'm wondering, how can Name() and String() authenticate a request?

    type AuthMethod interface {
    Name() string
    String() string
}

Digging through the source code I've found that actually clients/http.HTTPAuthMethod is required which defeats the purpose of interface based design. Even so setAuth(r *http.Request) is private so I still can't figure out how I'm supposed to construct a http.HTTPAuthMethod.

Is there any reason why the auth type is not a http.RoundTripper? I think it became a standard method to proxy client requests just like ServeHTTP does on the server server-side. E.g. NewAuthRemote(url string, auth http.RoundTripper) (*Remote, error).

I would also complain about the lack of a context.Context but might be a bit too much.

Panic in the example to print commits

Trying to run the example code seems to give an error.
It appears that the remote.upInfo isn't getting set.
This can be resolved by inserting a Connect call on the default remote.
This can also be resolved by modifying the Pull PullDefault code.
Options are in referenced pull requests.

FYI: I'm not sure how to run tests locally (they are failing) so I hope your CI works...

$ cd $GOPATH
$ go get -u github.com/src-d/go-git
$ go install github.com/src-d/go-git/examples/basic
$ ./bin/basic 'https://github.com/src-d/go-git'
Retrieving "https://github.com/src-d/go-git" ...
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x464005]

goroutine 1 [running]:
gopkg.in/src-d/go-git%2ev3.(*Remote).DefaultBranch(0xc20803a140, 0x0, 0x0)
    /home/tripledogdare/go/src/gopkg.in/src-d/go-git.v3/remote.go:81 +0x35
gopkg.in/src-d/go-git%2ev3.(*Repository).PullDefault(0xc20803d530, 0x0, 0x0)
    /home/tripledogdare/go/src/gopkg.in/src-d/go-git.v3/repository.go:101 +0x1a6
main.main()
    /home/tripledogdare/go/src/github.com/src-d/go-git/examples/basic/main.go:18 +0x1aa

goroutine 2 [runnable]:
runtime.forcegchelper()
    /home/tripledogdare/repositories/go/src/runtime/proc.go:90
runtime.goexit()
    /home/tripledogdare/repositories/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 3 [runnable]:
runtime.bgsweep()
    /home/tripledogdare/repositories/go/src/runtime/mgc0.go:82
runtime.goexit()
    /home/tripledogdare/repositories/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 4 [runnable]:
runtime.runfinq()
    /home/tripledogdare/repositories/go/src/runtime/malloc.go:712
runtime.goexit()
    /home/tripledogdare/repositories/go/src/runtime/asm_amd64.s:2232 +0x1

Add support for file-based object storage

The go-git library currently relies on in-memory storage of objects. I am interested in adding support for file-based object storage. My long term goal is to use this as a lightweight library for cloning and pulling repositories to local disk.

Right now RAWObjectStorage is the only implementation of the ObjectStorage interface. I would like to contribute by adding a FileObjectStorage implementation that reads and writes objects to the file system.

Is this something that the developers are amenable to?

To meet my goal there would of course be a number of other required features, such as index file support, but those can be tracked as separate issues.

assigment count mismatch error when go get

When go get in current HEAD, occured assigment count mismatch error.

> go get -t -v
github.com/src-d/go-git
# github.com/src-d/go-git
./commit.go:60: assignment count mismatch: 2 = 1
./objects.go:37: undefined: core.ObjectReader
./tag.go:39: assignment count mismatch: 2 = 1
./tree.go:144: assignment count mismatch: 2 = 1

each .go file error line.

> go version
go version devel +c8579e5 Fri Feb 26 03:58:58 2016 +0000 darwin/amd64

V3 is not a valid version

The master branch has v3 imports but gopkg complains that there is no such version. Can someone point me to the correct way to fetch the latest version (v3)?

go get -u -v gopkg.in/src-d/go-git.v3/core
Fetching https://gopkg.in/src-d/go-git.v3/core?go-get=1 Parsing meta tags from https://gopkg.in/src-d/go-git.v3/core?go-get=1 (status code 404) package gopkg.in/src-d/go-git.v3/core: unrecognized import path "gopkg.in/src-d/go-git.v3/core" (parse https://gopkg.in/src-d/go-git.v3/core?go-get=1: no go-import meta tags)

checkout symlink

How can i checkout symlink? Does it target name can be get via objectreader (blob contents)?

packp: AdvRefs is not encoded correctly when missing Head pointer

From https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt

If HEAD is a valid ref, HEAD MUST appear as the first advertised
ref.  If HEAD is not a valid ref, HEAD MUST NOT appear in the
advertisement list at all, but other refs may still appear.

So HEAD, if present, should be the first reference. Otherwise, the first reference is encoded as usual.

This is different from our current implementation, which encodes a zero hash instead:

func (s *AdvRefsEncodeSuite) TestRefs(c *C) {
	references := map[string]plumbing.Hash{
		"refs/heads/master":      plumbing.NewHash("a6930aaee06755d1bdcfd943fbf614e4d92bb0c7"),
		"refs/tags/v2.6.12-tree": plumbing.NewHash("1111111111111111111111111111111111111111"),
		"refs/tags/v2.7.13-tree": plumbing.NewHash("3333333333333333333333333333333333333333"),
		"refs/tags/v2.6.13-tree": plumbing.NewHash("2222222222222222222222222222222222222222"),
		"refs/tags/v2.6.11-tree": plumbing.NewHash("5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c"),
	}
	ar := &AdvRefs{
		References: references,
	}

	expected := pktlines(c,
		"0000000000000000000000000000000000000000 capabilities^{}\x00\n",
		"a6930aaee06755d1bdcfd943fbf614e4d92bb0c7 refs/heads/master\n",
		"5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11-tree\n",
		"1111111111111111111111111111111111111111 refs/tags/v2.6.12-tree\n",
		"2222222222222222222222222222222222222222 refs/tags/v2.6.13-tree\n",
		"3333333333333333333333333333333333333333 refs/tags/v2.7.13-tree\n",
		pktline.FlushString,
	)

	testEncode(c, ar, expected)
}

problems install v4

Trying to install go-git.v4, I get this error:

$ go get -u gopkg.in/src-d/go-git.v4/...
# gopkg.in/src-d/go-git.v4/formats/packfile
../../../gopkg.in/src-d/go-git.v4/formats/packfile/scanner.go:168: undefined: io.SeekCurrent
../../../gopkg.in/src-d/go-git.v4/formats/packfile/scanner.go:311: undefined: io.SeekCurrent
../../../gopkg.in/src-d/go-git.v4/formats/packfile/scanner.go:316: undefined: io.SeekStart
../../../gopkg.in/src-d/go-git.v4/formats/packfile/scanner.go:434: undefined: io.SeekCurrent
../../../gopkg.in/src-d/go-git.v4/formats/packfile/scanner.go:454: undefined: io.SeekCurrent

Error: unknown channel ACK

I sometime get a unknown channel ACK error while pulling from a repo with the git:// protocol.

I did not find a way to reproduce this case every time, but I work on a unstable connection (which may be the reason).

I guess it is from this part of the code:

return nil, fmt.Errorf("unknown channel %s", content)

Tell me if I can help.

client: ssh communication broken while fetching

----------------------------------------------------------------------
FAIL: git_upload_pack_test.go:114: RemoteSuite.TestFetch
git_upload_pack_test.go:129:
    //this is failling randomly, should be fixed ASAP
    c.Check(len(b), Equals, 85585)
... obtained int = 73727
... expected int = 85585
OOPS: 20 passed, 1 FAILED
--- FAIL: Test (0.72s)

Panic on packfile decode

I am seeing the panic below when trying to decode a packfile. It looks like it's related to #130. Would someone be able to confirm?

Here's the calling snippet:

       packdec, err := packfile.NewDecoder(packfile.NewScanner(r.Body), objstore)
	if err != nil {
		return
	}
        // This is where it panics
	if _, err = packdec.Decode(); err != nil {
		return
	}

Here's the panic:

goroutine 82 [running]:
net/http.(*conn).serve.func1(0xc420212400)
	/Users/abs/.gvm/gos/go1.7.3/src/net/http/server.go:1491 +0x12a
panic(0x4d1c00, 0xc4200100d0)
	/Users/abs/.gvm/gos/go1.7.3/src/runtime/panic.go:458 +0x243
gopkg.in/src-d/go-git.v4/plumbing/format/packfile.(*Decoder).recallByOffset(0xc4205cd9d0, 0x15ee, 0xc420214070, 0x60, 0xc47cb1f940, 0x0)
	/Users/abs/.gvm/pkgsets/go1.7.3/global/src/gopkg.in/src-d/go-git.v4/plumbing/format/packfile/decoder.go:266 +0xce
gopkg.in/src-d/go-git.v4/plumbing/format/packfile.(*Decoder).fillOFSDeltaObjectContent(0xc4205cd9d0, 0x7aa880, 0xc4202b8080, 0x15ee, 0x47fff8b4, 0x14, 0xc4207f9200)
	/Users/abs/.gvm/pkgsets/go1.7.3/global/src/gopkg.in/src-d/go-git.v4/plumbing/format/packfile/decoder.go:242 +0xd9
gopkg.in/src-d/go-git.v4/plumbing/format/packfile.(*Decoder).ReadObject(0xc4205cd9d0, 0x7aa880, 0xc4202b81c0, 0xce53f3af6349178b, 0xc5b353bb8b4c4f09)
	/Users/abs/.gvm/pkgsets/go1.7.3/global/src/gopkg.in/src-d/go-git.v4/plumbing/format/packfile/decoder.go:164 +0x4ac
gopkg.in/src-d/go-git.v4/plumbing/format/packfile.(*Decoder).readObjectsWithObjectStorer(0xc4205cd9d0, 0x61, 0xc4201ee010, 0x0)
	/Users/abs/.gvm/pkgsets/go1.7.3/global/src/gopkg.in/src-d/go-git.v4/plumbing/format/packfile/decoder.go:110 +0x40
gopkg.in/src-d/go-git.v4/plumbing/format/packfile.(*Decoder).doDecode(0xc4205cd9d0, 0x4a39c0, 0xc420014201)
	/Users/abs/.gvm/pkgsets/go1.7.3/global/src/gopkg.in/src-d/go-git.v4/plumbing/format/packfile/decoder.go:94 +0xda
gopkg.in/src-d/go-git.v4/plumbing/format/packfile.(*Decoder).Decode(0xc4205cd9d0, 0x0, 0x0, 0x0, 0xc4202049f0, 0x1000)
	/Users/abs/.gvm/pkgsets/go1.7.3/global/src/gopkg.in/src-d/go-git.v4/plumbing/format/packfile/decoder.go:74 +0x4a
github.com/euforia/gitchord/services.(*GitServer).ReceivePack(0xc4201fa000, 0x7a7180, 0xc42021c0d0, 0xc4200d23c0)
	/Users/abs/workbench/golang/src/github.com/euforia/gitchord/services/git.go:136 +0x8e0
github.com/euforia/gitchord/services.(*GitServer).ReceivePack-fm(0x7a7180, 0xc42021c0d0, 0xc4200d23c0)
	/Users/abs/workbench/golang/src/github.com/euforia/gitchord/cmd/gitchord/gitchord.go:99 +0x48
github.com/euforia/gitchord/services.(*Router).ServeHTTP(0xc420204000, 0x7a7180, 0xc42021c0d0, 0xc4200d22d0)
	/Users/abs/workbench/golang/src/github.com/euforia/gitchord/services/router.go:47 +0x755
net/http.serverHandler.ServeHTTP(0xc420212080, 0x7a7180, 0xc42021c0d0, 0xc4200d22d0)
	/Users/abs/.gvm/gos/go1.7.3/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc420212400, 0x7a7a40, 0xc4202cc380)
	/Users/abs/.gvm/gos/go1.7.3/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
	/Users/abs/.gvm/gos/go1.7.3/src/net/http/server.go:2293 +0x44d

Memory Leak

Hi,

I've tried using this library to clone and analysis some git repositories. I've tried using both Filesystem and Memory repositories. And with both I appear to have memory leaks. I took two profiles while using the memory repositories two minutes apart. (See below) With an increase in memory of over 1GB while the repositories were less than 100MB. I've tried turning the repositories to nil (including everything the repository was passed to) and running garbage collection manually. This hasn't really helped. I've had a look through your code quickly and I've not seen anything. Do you guys think this is an issue on my side or your side?

Memory Heap
Memory Heap

Add support for Smart HTTP (git://) protocol

We should add support for the Smart HTTP protocol (git://).

See "Smart HTTP" here:
https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols

Smart HTTP

The “smart” HTTP protocol operates very similarly to the SSH or Git protocols but runs over standard HTTP/S ports and can use various HTTP authentication mechanisms, meaning it’s often easier on the user than something like SSH, since you can use things like username/password basic authentication rather than having to set up SSH keys.

It has probably become the most popular way to use Git now, since it can be set up to both serve anonymously like the git:// protocol, and can also be pushed over with authentication and encryption like the SSH protocol. Instead of having to set up different URLs for these things, you can now use a single URL for both. If you try to push and the repository requires authentication (which it normally should), the server can prompt for a username and password. The same goes for read access.

In fact, for services like GitHub, the URL you use to view the repository online (for example, “https://github.com/schacon/simplegit”) is the same URL you can use to clone and, if you have access, push over.

v2.0.0: CommitIter panics when Close is called

If we add the following test to repository_test.go we can see this in action:

func (s *SuiteRepository) TestCommitIterClosePanic(c *C) {
    r, err := NewRepository(RepositoryFixture)
    r.Remotes["origin"].upSrv = &MockGitUploadPackService{}

    c.Assert(err, IsNil)
    c.Assert(r.Pull("origin", "refs/heads/master"), IsNil)

    commits := r.Commits()
    commits.Close()
}

This is due to https://github.com/src-d/go-git/blob/v2.0.0/repository.go#L98, it seems commit iteration needs a small rework.

Possible solutions

  • Make iter.Add and iter.Close private. Consecuences: We can't stop iterators anymore unless they reach the end.
  • Rework how iterators work all over the repo.
  • Add a check on Close to avoid more than once calls to it.

Clone private, ssh based repo

I'm having issues establishing a connection to a private ssh-based git repo, on a non-standard port. I'm using URL in the form of ssh://git@hostname:522/repositoryname.git and I'm getting this as the output:

2016/12/13 22:40:28 Process exited with status 128
exit status 1

I've put a debug statement after the ssh.Dial method call and this apparently succeeds. Not really sure how to troubleshoot further, but I've verified that:

  • ssh link to access github works (err := r.Clone(&git.CloneOptions{URL: "ssh://[email protected]/src-d/go-siva"}))
  • ssh link with port specified works too (err := r.Clone(&git.CloneOptions{URL: "ssh://[email protected]:22/src-d/go-siva"}))

On the server, I see that the ssh session has been established:

Dec 13 22:53:08 linux sshd[21974]: Accepted publickey for git from [redacted] port 47324 ssh2: RSA [redacted]
Dec 13 22:53:08 linux sshd[21974]: pam_unix(sshd:session): session opened for user git by (uid=0)
Dec 13 22:53:08 linux systemd-logind[499]: Removed session 218.
Dec 13 22:53:08 linux systemd-logind[499]: New session 220 of user git.
Dec 13 22:53:09 linux sshd[21974]: pam_unix(sshd:session): session closed for user git

The git ls-remote with that URL returns:

$ git ls-remote ssh://git@hostname:522/repository
a8092e8bd7e46bb5152af0a2b0035e7e53682c31	HEAD
a8092e8bd7e46bb5152af0a2b0035e7e53682c31	refs/heads/master

I tried with MemoryRepository and FileRepository. With the FileRepository, I get a config file in the specified directory (not in the .git subdirectory!) with the following contents:

[remote "origin"]
	url = ssh://git@hostname:522/repository.git
	fetch = +refs/heads/*:refs/remotes/origin/*

So it is obviously doing something right, but trips somewhere... just don't know where exactly.

How to identify branches and get their files

I'm having troubles identifying branches. Is there a specific way I can identify remote branches and "check them out" locally?

I.e., I would like to know which remote refs are branches and how to check them out locally, so I can get their files.

While iterating through Repository.References, I see the following refs:

2017/01/03 16:00:54 Ref:8a7363b0912adafb89cb947a9ea5a95780bb4ec7 refs/heads/master
2017/01/03 16:00:54 Ref:e5cd2c000f1ab71d999af0eb993f0f9d191a53d8 refs/remotes/origin/develop
2017/01/03 16:00:54 Ref:8a7363b0912adafb89cb947a9ea5a95780bb4ec7 refs/remotes/origin/master
2017/01/03 16:00:54 Ref:e9a1a207b2d7cc0de898750df2df92f703f38aef refs/tags/testtag
2017/01/03 16:00:54 Ref:ref: refs/heads/master HEAD

Only refs/heads/master has the IsBranch() "flag" set to true. Others are false. I doubt that the only way to identify branches is to search for string prefix refs/remotes/origin (where origin should not be special at all, and is just the default remote name, right)? (options.go, line 13)

Perhaps we could write an example? (I can write a few examples once this is clarified)

Pull after Fetch does not update HEAD

When running Pull or Fetch on a FileSystemRepository, they both return an error when there is nothing new to fetch. (should this be a separate issue?)

Also, when doing Fetch to update repository and then Pull, I would expect to update my references, but the HEAD does not get updated.

In other words, I see that Pull is also performing a Fetch operation, but Fetch is not updating my head. And it is strange that Fetch and Pull return errors when nothing is to be pulled/fetched.

Steps to reproduce:

  1. Clone a repo using go-git
  2. Print Head: (i.e.: 3897b83b17306309fa8bb570c0404e1403d503bf)
  3. Using the git tool, push a new commit to the repo
  4. Perform Fetch followed by Pull
  5. Print Head (the result will be the same as in step 2)

If I don't perform a fetch, the head gets updated to the latest commit. I am calling Fetch and Pull methods on a *Repository instance.

After playing with it for some time, I managed to get it into a state, where it would not update the HEAD ref anymore: 2017/01/03 15:37:57 unknown channel ACK a0b3bee218aefd7f10ea45b12efd169edd128cab

Now, even though I perform just a Pull operation, the HEAD stays at some earlier commit. If I list the commits, I don't see all of them (the newer ones are missing). Note that the current HEAD is at the value in the error above (a0b3bee218aefd7f10ea45b12efd169edd128cab).

I was testing this on a master branch.

return value of read not checked

There are a couple of places in the code where we are not checking the return value of Read, this is quite dangerous, as in #64, for example.

feat(receive-pack) read-only

This is a feature request to support receive-pack and basically a git server in read-only mode. The implementation could be used to "mirror" an existing repository(and perhaps apply a different ACL) or create and serve in-memory repositories on the fly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.