Skip to content

Commit

Permalink
#5662: Fill in the user name and email from git's config store
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 18, 2021
1 parent 64bedf4 commit 7dfe9e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
26 changes: 26 additions & 0 deletions plugins/vcs/Repository.cpp
Expand Up @@ -310,6 +310,32 @@ void Repository::createCommit(const CommitMetadata& metadata)

}

std::string Repository::getConfigValue(const std::string& key)
{
git_config* config;
auto error = git_repository_config_snapshot(&config, _repository);
GitException::ThrowOnError(error);

try
{
const char* value;
auto error = git_config_get_string(&value, config, key.c_str());
GitException::ThrowOnError(error);

// Copy the value before free-ing the config
std::string returnValue(value);

git_config_free(config);

return returnValue;
}
catch (const GitException& ex)
{
git_config_free(config);
throw ex;
}
}

bool Repository::isReadyForMerge()
{
auto state = git_repository_state(_repository);
Expand Down
2 changes: 2 additions & 0 deletions plugins/vcs/Repository.h
Expand Up @@ -83,6 +83,8 @@ class Repository final

void createCommit(const CommitMetadata& metadata);

std::string getConfigValue(const std::string& key);

// Creates a new instance of this repository, not sharing any libgit2 handles with the original
std::shared_ptr<Repository> clone();

Expand Down
23 changes: 14 additions & 9 deletions plugins/vcs/ui/VcsStatus.cpp
Expand Up @@ -310,19 +310,24 @@ void VcsStatus::performCommit()
_taskInProgress = true;
}

git::CommitMetadata metadata;
metadata = CommitDialog::RunDialog(metadata);

if (metadata.isValid())
try
{
try
git::CommitMetadata metadata;

metadata.name = _repository->getConfigValue("user.name");
metadata.email = _repository->getConfigValue("user.email");

metadata = CommitDialog::RunDialog(metadata);

if (metadata.isValid())
{

_repository->createCommit(metadata);
}
catch (const git::GitException& ex)
{
wxutil::Messagebox::ShowError(ex.what());
}
}
catch (const git::GitException& ex)
{
wxutil::Messagebox::ShowError(ex.what());
}

{
Expand Down

0 comments on commit 7dfe9e2

Please sign in to comment.