From 87142622018aa3b02f2b4a4be4e54e0cbbb12d7e Mon Sep 17 00:00:00 2001 From: Manuel Frischknecht Date: Mon, 31 Dec 2018 02:35:52 +0100 Subject: [PATCH] Use commit authors as committers, too If `user.name` and `user.email` are not configured in the setup kirby-autogit is used in, `$this->commit(...)` will fail, because git prints its infamous "tell me who you are" message. By explicitly providing the two config keys with each commit command, we can use the determined user as the committer and thus have the commit work anyway without needing any changes to any of git's configs. --- lib/autogit.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/autogit.php b/lib/autogit.php index 4a4df12..949fdb6 100755 --- a/lib/autogit.php +++ b/lib/autogit.php @@ -45,11 +45,16 @@ public function add($path = false) public function commit($message) { - $this->execute(sprintf( - 'commit --author %s --message %s', - escapeshellarg($this->author()), - escapeshellarg($message) - )); + $author = $this->author(); + + $command = sprintf( + '-c %s -c %s commit --author %s --message %s', + escapeshellarg("user.name={$author['name']}"), + escapeshellarg("user.email={$author['email']}"), + escapeshellarg("{$author['name']} <{$author['email']}>"), + escapeshellarg($message)); + + $this->execute($command); } public function pull() @@ -92,7 +97,7 @@ protected function author() $userEmail = $user->email(); } - return "{$userName} <{$userEmail}>"; + return [ 'name' => $userName, 'email' => $userEmail ]; } protected function getMessage($key, $params)