-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement command to checkout/restore working tree
- Loading branch information
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of SebastianFeldmann\Git. | ||
* | ||
* (c) Sebastian Feldmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SebastianFeldmann\Git\Command\Checkout; | ||
|
||
use SebastianFeldmann\Git\Command\Base; | ||
|
||
/** | ||
* Class RestoreWorkingTree | ||
* | ||
* @package SebastianFeldmann\Git | ||
* @author Sebastian Feldmann <[email protected]> | ||
* @link https://github.com/sebastianfeldmann/git | ||
* @since Class available since Release 3.7.0 | ||
*/ | ||
class RestoreWorkingTree extends Base | ||
{ | ||
/** | ||
* Files and directories to restore. | ||
* | ||
* @var string[] | ||
*/ | ||
private $files = ['.']; | ||
|
||
/** | ||
* Limits the paths affected by the operation to those specified here. | ||
* | ||
* @param array $files | ||
* | ||
* @return \SebastianFeldmann\Git\Command\Checkout\RestoreWorkingTree | ||
*/ | ||
public function files(array $files): RestoreWorkingTree | ||
{ | ||
$this->files = $files; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Return the command to execute. | ||
* | ||
* @return string | ||
*/ | ||
protected function getGitCommand(): string | ||
{ | ||
return 'checkout --quiet' | ||
. ' -- ' | ||
. implode(' ', array_map('escapeshellarg', $this->files)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of SebastianFeldmann\Git. | ||
* | ||
* (c) Sebastian Feldmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SebastianFeldmann\Git\Command\Checkout; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class RestoreWorkingTreeTest | ||
* | ||
* @package SebastianFeldmann\Git | ||
* @author Sebastian Feldmann <[email protected]> | ||
* @link https://github.com/sebastianfeldmann/git | ||
* @since Class available since Release 3.7.0 | ||
*/ | ||
class RestoreWorkingTreeTest extends TestCase | ||
{ | ||
public function testDefault(): void | ||
{ | ||
$command = new RestoreWorkingTree(); | ||
|
||
$this->assertSame('git checkout --quiet -- \'.\'', $command->getCommand()); | ||
} | ||
|
||
public function testFiles(): void | ||
{ | ||
$command = new RestoreWorkingTree(); | ||
$command = $command->files([ | ||
"foo/*", | ||
"foo bar.txt", | ||
"foo' 'bar.txt", | ||
"fooBar.txt", | ||
]); | ||
|
||
$this->assertSame( | ||
"git checkout --quiet -- 'foo/*' 'foo bar.txt' 'foo'\'' '\''bar.txt' 'fooBar.txt'", | ||
$command->getCommand() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters