From 2e90b233c2235b3ea405c54a3043e190d733275d Mon Sep 17 00:00:00 2001 From: B Tasker Date: Mon, 26 Sep 2016 11:30:59 +0100 Subject: [PATCH 1/2] Implemented ability to revert a file back to a specified revision --- Git.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Git.php b/Git.php index 864e1ed..c2590ee 100755 --- a/Git.php +++ b/Git.php @@ -552,6 +552,26 @@ public function checkout($branch) { return $this->run("checkout $branch"); } + + /** + * Runs a `git checkout` call against a specific file + * + * Allows you to revert a named file to a specific revision + * + * Accepts a name for the branch + * + * @access public + * @param string branch name + * @return string + */ + public function checkoutFile($revision,$file) { + $this->run("checkout $revision $file"); + // We don't need to do an Add as git + return $this->commit("Reverted $file to revision $revision"); + } + + + /** * Runs a `git merge` call @@ -646,11 +666,16 @@ public function pull($remote, $branch) { * @param strgin $format * @return string */ - public function log($format = null) { + public function log($format = null, $fulldiff=false, $filepath=null) { + + if ($fulldiff){ + $diff = "--full-diff -p "; + } + if ($format === null) - return $this->run('log'); + return $this->run('log ' . $diff . $filepath); else - return $this->run('log --pretty=format:"' . $format . '"'); + return $this->run('log --pretty=format:"' . $format . '" ' . $diff .$filepath); } /** From 9973ec95397f8cbc8a1266e1aed2658c79257f60 Mon Sep 17 00:00:00 2001 From: B Tasker Date: Mon, 26 Sep 2016 12:00:24 +0100 Subject: [PATCH 2/2] Added ability to specify message when reverting file --- Git.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Git.php b/Git.php index c2590ee..6f710db 100755 --- a/Git.php +++ b/Git.php @@ -564,10 +564,15 @@ public function checkout($branch) { * @param string branch name * @return string */ - public function checkoutFile($revision,$file) { + public function checkoutFile($revision,$file,$message=null) { $this->run("checkout $revision $file"); // We don't need to do an Add as git - return $this->commit("Reverted $file to revision $revision"); + + if ($message == null){ + $message = "Reverted $file to revision $revision"; + } + + return $this->commit($message); }