Config object is always live - get_str() fails
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 450
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
When attempting to
let cfg = repo.config().expect("Failed to obtain config struct");
let name = cfg.get_str("user.name").unwrap(); // <<< fails here
let email = cfg.get_str("user.email").unwrap();
it always fails with:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { code: -1, klass: 7, message: "get_string called on a live config object" }', src/libcore/result.rs:999:5
stack backtrace:
which I backtraced down to is_readonly returning 1.
int git_config_get_string(
const char **out, const git_config *cfg, const char *name)
{
git_config_entry *entry;
int ret;
if (!is_readonly(cfg)) { // <<<< always fails
git_error_set(GIT_ERROR_CONFIG, "get_string called on a live config object");
return -1;
}
ret = get_entry(&entry, cfg, name, true, GET_ALL_ERRORS);
*out = !ret ? (entry->value ? entry->value : "") : NULL;
git_config_entry_free(entry);
return ret;
}
Minimal fully runnable demo of the issue: https://github.com/drahnr/gitconfigtest/
$ git config user.name
Bernhard
works fine
(Or maybe I do not understand the meaning of this error and it's a layer 8 problem)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked minimal demo and tracing repo.config(), get_str(), and the underlying git_config_get_string call, especially the is_readonly check. Compare the live config behavior with the read-only lookup path; done means user.name and user.email can be retrieved without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100