Closed dafeder closed 4 years ago
I'm withdrawing this PR; too likely to break the CLI container. For now I'm adding the following as custom command code in my application; this may be a candidate for dkan-tools core in the future:
/**
* Check if user.email exists in current git config.
*
* @return bool
*/
private function gitHasConfig() {
$configEmail = $this->taskExec('git config --get "user.email"')
->printOutput(false)
->run()
->getMessage();
return ($configEmail ? true : false);
}
/**
* Configure git in current environment with user name and email.
*
* @option name
* The user name to pass to git config
* @option email
* The user email to pass to git config
*/
public function gitConfig($opts = ['name' => NULL, 'email' => NULL])
{
$this->io()->title('Configure git with your name and email');
if ($opts['name']) {
$userName = $opts['name'];
$this->io()->note("Name: $userName");
}
else {
$userName = $this->io()->ask('Name');
}
if ($opts['email']) {
$userEmail = $opts['email'];
$this->io()->note("Email: $userEmail");
}
else {
$userEmail = $this->io()->ask('Email');
}
$result = $this->taskExecStack()
->stopOnFail()
->exec("git config --global user.name '$userName'")
->exec("git config --global user.email '$userEmail'")
->run();
return $result;
}
Assuming someone has a ~/.gitconfig file, this will mount it in /root on cli allowing you to use git with your normal username.
If you don't have a ~/.gitconfig though, git will fail on cli because it will create a volume mount folder instead of mounting the existing file. Perhaps there is a better way to accomplish this.