From 891ffa0e15b719e6f1f97169dc86027bf8ab59e2 Mon Sep 17 00:00:00 2001 From: Knut Forkalsrud Date: Tue, 6 Nov 2018 12:48:35 -0800 Subject: [PATCH 1/5] Add all changes instead of relying on "affected paths" --- addons/Spock/Git.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/Spock/Git.php b/addons/Spock/Git.php index 0a8a8f1..4f910b3 100644 --- a/addons/Spock/Git.php +++ b/addons/Spock/Git.php @@ -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(); From dd040178270505a12df80b8b7a50cefb7bcf41f2 Mon Sep 17 00:00:00 2001 From: Knut Forkalsrud Date: Tue, 6 Nov 2018 12:49:31 -0800 Subject: [PATCH 2/5] Add --author and escape commit cmdline parameters --- addons/Spock/Git.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/addons/Spock/Git.php b/addons/Spock/Git.php index 4f910b3..1c267fe 100644 --- a/addons/Spock/Git.php +++ b/addons/Spock/Git.php @@ -59,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 " + */ + protected function author() { + $user = $this->user->toArray(); + return sprintf("--author=%s <%s>", $user['name'], $user['email']); + } + + /** * Get the label of the class, which is the action name. * From 86b4d3633009027d3017db815197d233e12a9e3b Mon Sep 17 00:00:00 2001 From: Knut Forkalsrud Date: Mon, 31 Dec 2018 13:35:06 -0800 Subject: [PATCH 3/5] Code style --- addons/Spock/Git.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/addons/Spock/Git.php b/addons/Spock/Git.php index 1c267fe..49a10f8 100644 --- a/addons/Spock/Git.php +++ b/addons/Spock/Git.php @@ -60,12 +60,12 @@ protected function commitCommand() if ($username = array_get($this->config, 'git_username')) { $parts[] = '-c'; - $parts[] = escapeshellarg("user.name=" . $username); + $parts[] = escapeshellarg('user.name=' . $username); } if ($email = array_get($this->config, 'git_email')) { $parts[] = '-c'; - $parts[] = escapeshellarg("user.email=" . $email); + $parts[] = escapeshellarg('user.email=' . $email); } $parts[] = 'commit'; @@ -73,7 +73,7 @@ protected function commitCommand() $parts[] = escapeshellarg($this->author()); } $parts[] = '-m'; - $parts[] = escapeshellarg(sprintf("%s%s", $this->label(), $this->user ? ' by ' . $this->user->username() : '')); + $parts[] = escapeshellarg($this->commitMessage()); return join(' ', $parts); } @@ -84,8 +84,21 @@ protected function commitCommand() * i.e, "--author=A U Thor " */ protected function author() { - $user = $this->user->toArray(); - return sprintf("--author=%s <%s>", $user['name'], $user['email']); + return sprintf('--author=%s <%s>', $this->user->name(), $this->user->email()); + } + + + /** + * Generate the commit message + * + * @return string + */ + protected function commitMessage() { + $msg = $this->label(); + if ($this->user) { + $msg .= ' by ' . $this->user->username(); + } + return $msg; } From 529f94e066b319b3563f556d935fa6a470aba689 Mon Sep 17 00:00:00 2001 From: Knut Forkalsrud Date: Mon, 31 Dec 2018 13:35:17 -0800 Subject: [PATCH 4/5] Revert "Add all changes instead of relying on "affected paths"" This reverts commit 891ffa0e15b719e6f1f97169dc86027bf8ab59e2. --- addons/Spock/Git.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/Spock/Git.php b/addons/Spock/Git.php index 49a10f8..d4d5b53 100644 --- a/addons/Spock/Git.php +++ b/addons/Spock/Git.php @@ -32,7 +32,9 @@ public function commands() { $commands = array_get($this->config, 'commands_before', []); - $commands[] = "git add --all"; + foreach ($this->event->affectedPaths() as $path) { + $commands[] = "git add {$path}"; + } $commands[] = $this->commitCommand(); From 7a93cf78ffa643c969aa83c2de74591c920f4006 Mon Sep 17 00:00:00 2001 From: Knut Forkalsrud Date: Mon, 7 Jan 2019 22:17:58 -0800 Subject: [PATCH 5/5] Go back to $this->user->toArray() As I can't make $this->user->email() work. --- addons/Spock/Git.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/Spock/Git.php b/addons/Spock/Git.php index d4d5b53..bbab826 100644 --- a/addons/Spock/Git.php +++ b/addons/Spock/Git.php @@ -86,7 +86,8 @@ protected function commitCommand() * i.e, "--author=A U Thor " */ protected function author() { - return sprintf('--author=%s <%s>', $this->user->name(), $this->user->email()); + $user = $this->user->toArray(); + return sprintf("--author=%s <%s>", $user['name'], $user['email']); }