Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass the equivalent of git push -o <string>? #953

Open
MatejLach opened this issue Jun 17, 2023 · 0 comments
Open

How to pass the equivalent of git push -o <string>? #953

MatejLach opened this issue Jun 17, 2023 · 0 comments

Comments

@MatejLach
Copy link

MatejLach commented Jun 17, 2023

On the Git CLI, I can use git push -o <option> for example git push -o merge_request.create to supply string options with push that are then processed on the server by i.e. the post-receive hook to perform additional actions, like create a pull request automatically after the push etc. See GitLab's options as an example.

My failed attempt to recreate this with git2go :

package main

import (
	git "github.com/libgit2/git2go/v34"
	log "github.com/sirupsen/logrus"
)

func main() {
	repo, err := git.OpenRepository("/home/ml/Projects/demo")
	if err != nil {
		log.Fatal(err)
	}
	remote, err := repo.Remotes.Lookup("origin")
	if err != nil {
		remote, err = repo.Remotes.Create("origin", repo.Path())
		if err != nil {
			log.Fatal(err)
		}
	}

	// ref
	ref, err := repo.Head()
	if err != nil {
		log.Fatal(err)
	}

	// Get the name
	branch := ref.Branch()
	branchName, err := branch.Name()
	if err != nil {
		log.Fatal(err)
	}

	if err := remote.Push([]string{"refs/heads/" + branchName}, &git.PushOptions{
		RemoteCallbacks: git.RemoteCallbacks{
			CredentialsCallback: func(url string, username_from_url string, allowed_types git.CredentialType) (*git.Credential, error) {
				return git.NewCredentialUserpassPlaintext("username", "pass")
			},
		},
		Headers: []string{"merge_request.create:true"},
	}); err != nil {
		log.Fatal(err)
	}
}

Is there a way to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant