Questions tagged [go-git]

Highly extensible implementation of Git protocol and storage format in Golang

go-git is is highly extensible implementation of Git protocol and storage format in Go.

It aims to reach the completeness of libgit2 or jgit, and nowadays covers the majority of the plumbing read operations and some of the main write ones, but lacks the main porcelain operations such as merges.

In its design, it has been following the open/close principle to facilitate extensions, mainly focusing the efforts on the persistence of the objects.

57 questions
13
votes
6 answers

docker multi-stage build Go image - x509: certificate signed by unknown authority

I try to build go images in private corp network use docker-multi-stage-build: FROM golang:latest as builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN GO111MODULE="on" CGO_ENABLED=0 GOOS=linux go build -o main…
kozmo
  • 4,024
  • 3
  • 30
  • 48
9
votes
2 answers

How do I mimic `git --work-tree ...` with `go-git` in go?

I have a bare repository in which I need to add and commit a set of files. As far as I understand it, adding files to the index requires a worktree. Using git on the command line, I would set the git-dir option to point to the bare directory along…
Emil Walser
  • 615
  • 2
  • 7
  • 14
8
votes
2 answers

go-git: Correct way to create a local branch, emulating behavior of "git branch "?

As the title suggests, I'm trying to figure out how to create a local branch using go-git in a way that gives the same result as the Git CLI command git branch . As far as I've been able to tell, git branch (without an…
Hephaestus
  • 1,982
  • 3
  • 27
  • 35
6
votes
0 answers

How to merge using go-git?

Since merge and rebase are currently not implemented, what's the recommended way to merge changes from another branch into your active branch using go-git? For example, suppose our master branch had two commits (m1 and m2). master m1 -- m2 -- m3 …
l3x
  • 30,760
  • 1
  • 55
  • 36
6
votes
2 answers

Can git fetch pack be instructed to fetch a single tree object?

In short, is there a way for me to efficiently (space wise) specify the exact objects I want from a git server that only supports the smart protocol but not the filter-spec? More context: For GitHub's lack of filter-spec support in the pack…
edaniels
  • 708
  • 5
  • 23
5
votes
2 answers

Clone a repository from GitHub Enterprise with go-git

I'm trying to use go-git to clone a repository from GitHub Enterprise. To do that, I'm using the HTTPS protocol with an access token with appropriate permissions for my repos (verified on the command line). go-git fails when making the…
Björn Marschollek
  • 9,899
  • 9
  • 40
  • 66
4
votes
1 answer

Is it possible to git diff equivalent with go-git

I'm pulling a repo every 10 seconds and need to check what files have changed after each pull. Is it possible to do this with go-git?
ecl0
  • 385
  • 1
  • 3
  • 13
4
votes
2 answers

go-git: How to authenticate at remote server?

I'm using the go project go-git as a git-client and want to fetch from a private git-repository hosted via gitea. The appropiate function to do that is func (r *Remote) Fetch(o *FetchOptions) error, which expects an transport.AuthMethod object for…
maja
  • 17,250
  • 17
  • 82
  • 125
3
votes
1 answer

How to push specific branch to remote with go-git

What is the canonical way to push specific single local branch to specific remote with go-git? I have a local repository checked out and opened with go-git repo, err := git.PlainOpen("my-repo") The repo has default origin remote. I'm trying to sync…
David Lukac
  • 728
  • 7
  • 20
3
votes
1 answer

How to checkout a new local branch using go-git?

When i try to use worktree checkout; it doesn't work and the code returns error err = worktree.Checkout(&git.CheckoutOptions{ Create: true, Branch: "main", }) if err != nil { log.Fatal("Cannot create 'main' branch\n" +…
capsci
  • 65
  • 1
  • 5
3
votes
2 answers

Use go-git to check if branch has been pushed to remote

Using go-git, is there any way to check if I have made a commit, but have not yet pushed it to a remote? For instance: $ echo "Hello" > hello.txt $ git add -A $ git commit -am "Add hello" $ git status On branch master Your branch is ahead of…
SteveCoffman
  • 983
  • 1
  • 8
  • 22
2
votes
1 answer

go-git checkout failing with reference not found

I'm just starting to use the go-git library and so far it looks very promising. However, I'm trying to do a basic checkout of an existing branch and it is failing with "reference not found". I have a simple repository, with several branches but one…
Brooksy
  • 23
  • 2
2
votes
2 answers

go-git diff between branches

It's possible with go-git to get the differences between two branches, or, for instance, current branch and master? With GIT you can get diff between current branch and master: $ git diff master And between two branches: $ git diff master…
p3quod
  • 1,449
  • 3
  • 13
  • 15
2
votes
1 answer

Using go-git to get flat list of files

I am working on an application that lists all files in a .git repository. I have a working way to turn a tree into a flat list but it is very slow (300ms) This is the source code for a Tree object…
Jilles
  • 21
  • 3
2
votes
1 answer

deleting local branch in go-git: branch not found

I'm trying to delete a local branch using go-git, but getting an error branch not found when I run branch := "refs/heads/template/test" err = repo.DeleteBranch(branch) or err = repo.DeleteBranch(plumbing.ReferenceName(branch)) Using just the name…
lawful_neutral
  • 633
  • 8
  • 29
1
2 3 4