rust-lang / rust-lang/git2-rs

Config object is always live - get_str() fails

Open
#474 8 comments 3 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.