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

Add Rugged::Config#add #834

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

codenamev
Copy link

This method allows you to set multiple values for the same key in a
particular config, similar to git config --add "include.path" some/path.

For example, I have a git config with an existing include.path value:

$ cat ~/src/opensource/rugged/.git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = [email protected]:codenamev/rugged.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[submodule "vendor/libgit2"]
        active = true
        url = https://github.com/libgit2/libgit2.git
[include]
        path = /Users/codenamev/.gitconfig.reflow

With Rugged::Config#add I can set another value for include.path
without overwriting the existing value:

ruby -I lib -rrugged -e'\
config = Rugged::Repository.new("/Users/codenamev/src/opensource/rugged").config;
config.add("include.path", "/Users/codenamev/.gitconfig.extras");
p config.get_all("include.path")'
["/Users/codenamev/.gitconfig.reflow", "/Users/codenamev/.gitconfig.extras"]

References #725

} else if (RB_TYPE_P(rb_val, T_TRUE) || RB_TYPE_P(rb_val, T_FALSE)) {
error = git_config_set_multivar(config, key, "$^", (rb_val == Qtrue) ? "true" : "false");
} else if (FIXNUM_P(rb_val)) {
char str_value[32];
Copy link
Author

@codenamev codenamev Mar 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took this snippet from the libgit2 source. I'm not entirely sure this is the best way to do this conversion, but I figured I'd at least mimic the behavior. There are some performance enhancements related to windows systems for snprintf that were not ported over (because I have no idea how that works).

This method allows you to set multiple values for the same key in a
particular config, similar to `git config --add "include.path" some/path`.

For example, I have a git config with an existing `include.path` value:

```
$ cat ~/src/opensource/rugged/.git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = [email protected]:codenamev/rugged.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[submodule "vendor/libgit2"]
        active = true
        url = https://github.com/libgit2/libgit2.git
[include]
        path = /Users/codenamev/.gitconfig.reflow
```

With `Rugged::Config#add` I can set another value for `include.path`
without overwriting the existing value:

```
ruby -I lib -rrugged -e'\
config = Rugged::Repository.new("/Users/codenamev/src/opensource/rugged").config;
config.add("include.path", "/Users/codenamev/.gitconfig.extras");
p config.get_all("include.path")'
["/Users/codenamev/.gitconfig.reflow", "/Users/codenamev/.gitconfig.extras"]
```

References libgit2#725
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

Successfully merging this pull request may close these issues.

1 participant