-
Notifications
You must be signed in to change notification settings - Fork 16
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 author to commits #28
base: master
Are you sure you want to change the base?
Changes from all commits
891ffa0
dd04017
86b4d36
529f94e
7a93cf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,21 +61,50 @@ protected function commitCommand() | |
$parts = ['git']; | ||
|
||
if ($username = array_get($this->config, 'git_username')) { | ||
$parts[] = sprintf('-c "user.name=%s"', $username); | ||
$parts[] = '-c'; | ||
$parts[] = escapeshellarg('user.name=' . $username); | ||
} | ||
|
||
if ($email = array_get($this->config, 'git_email')) { | ||
$parts[] = sprintf('-c "user.email=%s"', $email); | ||
$parts[] = '-c'; | ||
$parts[] = escapeshellarg('user.email=' . $email); | ||
} | ||
|
||
$message = 'commit -m "' . $this->label(); | ||
$message .= $this->user ? ' by ' . $this->user->username() : ''; | ||
$message .= '"'; | ||
$parts[] = $message; | ||
|
||
$parts[] = 'commit'; | ||
if ($this->user) { | ||
$parts[] = escapeshellarg($this->author()); | ||
} | ||
$parts[] = '-m'; | ||
$parts[] = escapeshellarg($this->commitMessage()); | ||
return join(' ', $parts); | ||
} | ||
|
||
|
||
|
||
/** | ||
* Create a Git author parameter from the user's name and email address, | ||
* i.e, "--author=A U Thor <[email protected]>" | ||
*/ | ||
protected function author() { | ||
$user = $this->user->toArray(); | ||
return sprintf("--author=%s <%s>", $user['name'], $user['email']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use the getter methods on the User object? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I can't get |
||
} | ||
|
||
|
||
/** | ||
* Generate the commit message | ||
* | ||
* @return string | ||
*/ | ||
protected function commitMessage() { | ||
$msg = $this->label(); | ||
if ($this->user) { | ||
$msg .= ' by ' . $this->user->username(); | ||
} | ||
return $msg; | ||
} | ||
|
||
|
||
/** | ||
* Get the label of the class, which is the action name. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method could be private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it could be private, however all the other similar methods are protected, so I'd rather follow suit on that.