diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2020-05-24 16:53:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 16:53:30 +0200 |
commit | e7f544844d6d736acfd9d75ee0d4a9d37f450103 (patch) | |
tree | dc44247231e6603bf10acaee91af5523120b4b84 /_examples | |
parent | 6d8103df45ce09ffd5323b4ef46d26440400a54f (diff) | |
parent | baf8c2761217cd457ef672972d5c1fb4d066e95a (diff) | |
download | go-git-e7f544844d6d736acfd9d75ee0d4a9d37f450103.tar.gz |
Merge pull request #75 from mcuadros/scope-config
repository.ConfigScoped and worktree.Commit with empty CommitOptions
Diffstat (limited to '_examples')
-rw-r--r-- | _examples/README.md | 35 | ||||
-rw-r--r-- | _examples/commit/main.go | 3 | ||||
-rw-r--r-- | _examples/config/main.go | 73 |
3 files changed, 20 insertions, 91 deletions
diff --git a/_examples/README.md b/_examples/README.md index 6c17941..1d82fbd 100644 --- a/_examples/README.md +++ b/_examples/README.md @@ -3,26 +3,27 @@ Here you can find a list of annotated _go-git_ examples: ### Basic -- [showcase](showcase/main.go) - A small showcase of the capabilities of _go-git_ -- [open](open/main.go) - Opening a existing repository cloned by _git_ -- [clone](clone/main.go) - Cloning a repository +- [showcase](showcase/main.go) - A small showcase of the capabilities of _go-git_. +- [open](open/main.go) - Opening a existing repository cloned by _git_. +- [clone](clone/main.go) - Cloning a repository. - [username and password](clone/auth/basic/username_password/main.go) - Cloning a repository - using a username and password + using a username and password. - [personal access token](clone/auth/basic/access_token/main.go) - Cloning - a repository using a GitHub personal access token -- [commit](commit/main.go) - Commit changes to the current branch to an existent repository -- [push](push/main.go) - Push repository to default remote (origin) -- [pull](pull/main.go) - Pull changes from a remote repository -- [checkout](checkout/main.go) - Check out a specific commit from a repository -- [log](log/main.go) - Emulate `git log` command output iterating all the commit history from HEAD reference + a repository using a GitHub personal access token. +- [commit](commit/main.go) - Commit changes to the current branch to an existent repository. +- [push](push/main.go) - Push repository to default remote (origin). +- [pull](pull/main.go) - Pull changes from a remote repository. +- [checkout](checkout/main.go) - Check out a specific commit from a repository. +- [log](log/main.go) - Emulate `git log` command output iterating all the commit history from HEAD reference. - [branch](branch/main.go) - How to create and remove branches or any other kind of reference. -- [tag](tag/main.go) - List/print repository tags -- [remotes](remotes/main.go) - Working with remotes: adding, removing, etc -- [progress](progress/main.go) - Printing the progress information from the sideband -- [revision](revision/main.go) - Solve a revision into a commit -- [submodule](submodule/main.go) - Submodule update remote +- [tag](tag/main.go) - List/print repository tags. +- [remotes](remotes/main.go) - Working with remotes: adding, removing, etc. +- [progress](progress/main.go) - Printing the progress information from the sideband. +- [revision](revision/main.go) - Solve a revision into a commit. +- [config](config/main.go) - Explains how to work with config files. +- [submodule](submodule/main.go) - Submodule update remote. ### Advanced -- [custom_http](custom_http/main.go) - Replacing the HTTP client using a custom one +- [custom_http](custom_http/main.go) - Replacing the HTTP client using a custom one. - [clone with context](context/main.go) - Cloning a repository with graceful cancellation. -- [storage](storage/README.md) - Implementing a custom storage system +- [storage](storage/README.md) - Implementing a custom storage system. diff --git a/_examples/commit/main.go b/_examples/commit/main.go index c83dc98..4529c84 100644 --- a/_examples/commit/main.go +++ b/_examples/commit/main.go @@ -46,7 +46,8 @@ func main() { // Commits the current staging area to the repository, with the new file // just created. We should provide the object.Signature of Author of the - // commit. + // commit Since version 5.0.1, we can omit the Author signature, being read + // from the git config files. Info("git commit -m \"example go-git commit\"") commit, err := w.Commit("example go-git commit", &git.CommitOptions{ Author: &object.Signature{ diff --git a/_examples/config/main.go b/_examples/config/main.go deleted file mode 100644 index 7c5592f..0000000 --- a/_examples/config/main.go +++ /dev/null @@ -1,73 +0,0 @@ -package main - -import ( - "github.com/go-git/go-git/v5" - . "github.com/go-git/go-git/v5/_examples" - format "github.com/go-git/go-git/v5/plumbing/format/config" - - "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 -// - Set custom local config params -// - Access custom local config params -// - Set global config params -// - Access global & system config params - -func main() { - // Open this repository - // Info("git init") - // r, err := git.Init(memory.NewStorage(), nil) - Info("open local git repo") - r, err := git.PlainOpen(".") - CheckIfError(err) - - // Load the configuration - cfg, err := r.Config() - CheckIfError(err) - - // Get core local config params - if cfg.Core.IsBare { - Info("repo is bare") - } else { - Info("repo is not bare") - } - - Info("worktree is %s", cfg.Core.Worktree) - - // Set basic local config params - cfg.Remotes["origin"] = &config.RemoteConfig{ - Name: "origin", - URLs: []string{"git@github.com:mcuadros/go-git.git"}, - } - - Info("origin remote: %+v", cfg.Remotes["origin"]) - - // NOTE: The examples below show advanced usage of the config.Merged system, which should - // only be used as a last resort if the basic data defined on the Config struct don't - // suffice for what you're trying to do. - - // Set local custom config param - cfg.Merged.AddOption(format.LocalScope, "custom", format.NoSubsection, "name", "Local Name") - - // Set global config param (~/.gitconfig) - cfg.Merged.AddOption(format.GlobalScope, "custom", format.NoSubsection, "name", "Global Name") - - // Get custom config param (merged in the same way git does: system -> global -> local) - Info("custom.name is %s", cfg.Merged.Section("custom").Option("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) - - // Get system config params (/etc/gitconfig) - systemSections := cfg.Merged.SystemConfig().Sections - for _, ss := range systemSections { - Info("System section: %s", ss.Name) - for _, o := range ss.Options { - Info("\tOption: %s = %s", o.Key, o.Value) - } - } -} |