8000 examples: add config example back. Fixes #523 by cmiller01 · Pull Request #557 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content

examples: add config example back. Fixes #523 #557

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
examples: add config example. Fixes #523
* previously an example existed for working with `config.Config`, but changes in implementation made the example not usable. (see #75)
* this mostly puts back the original example with some modifications to
make it work with current implementation
  • Loading branch information
cmiller01 committed Jul 26, 2022
commit a12a0a2c8d2849ea6a8ba446b258b0294f91c5a8
40 changes: 40 additions & 0 deletions _examples/config/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"github.com/go-git/go-git/v5"
. "github.com/go-git/go-git/v5/_examples"

"github.com/go-git/go-git/v5/config"
)

// Example of how to:
// - Access basic local (i.e. ./.git/config) configuration params
// - Set basic local config params

func main() {
Info("git init")
r, err := git.PlainInit(".", false)
CheckIfError(err)

// Load the configuration
cfg, err := r.Config()
CheckIfError(err)

Info("worktree is %s", cfg.Core.Worktree)

// Set basic local config params
cfg.Remotes["origin"] = &config.RemoteConfig{
Name: "origin",
URLs: []string{"https://github.com/git-fixtures/basic.git"},
}

Info("origin remote: %+v", cfg.Remotes["origin"])

cfg.User.Name = "Local name"

Info("custom.name is %s", cfg.User.Name)

// In order to save the config file, you need to call SetConfig
// After calling this go to .git/config and see the custom.name added and the changes to the remote
r.Storer.SetConfig(cfg)
}
0