Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions addons/Spock/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public function commands()
{
$commands = array_get($this->config, 'commands_before', []);

foreach ($this->event->affectedPaths() as $path) {
$commands[] = "git add {$path}";
}
$commands[] = "git add --all";

$commands[] = $this->commitCommand();

Expand All @@ -61,21 +59,36 @@ 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(sprintf("%s%s", $this->label(), $this->user ? ' by ' . $this->user->username() : ''));
return join(' ', $parts);
}



/**
* Create a Git author parameter from the user's name and email address,
* i.e, "--author=A U Thor <author@example.com>"
*/
protected function author() {
Copy link
Contributor

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

Copy link
Author

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.

$user = $this->user->toArray();
return sprintf("--author=%s <%s>", $user['name'], $user['email']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the getter methods on the User object?
Like $this->user->email()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I can't get $this->user->email() to work... Maybe I'm being dense, but PHP claim there is no such function. I'll go back to the toArray() approach.

}


/**
* Get the label of the class, which is the action name.
*
Expand Down