Skip to content

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

Open
@MatejLach

Description

@MatejLach

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions