Skip to content

Commit

Permalink
add method 'stash'
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtARTs36 committed Aug 19, 2020
1 parent 4854e41 commit 88a2d4a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ $git = new Git('/var/web/project');
var_dump($git->add('file_name'));
```

#### git stash:

```php
use ArtARTs36\GitHandler\Git;

$git = new Git('/var/web/project');
$git->stash();
$git->stash('message');
```

#### create folder in repository:

```php
Expand Down
24 changes: 24 additions & 0 deletions src/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ public function clone(string $url): bool
return false;
}

/**
* equals: git stash
* @param string $message
* @return bool
*/
public function stash(string $message = null): bool
{
$sh = $this->executeCommand($this->newCommand()
->addParameter('stash')
->when(!empty($message), function (ShellCommand $command) use ($message) {
$command
->addParameter('save')
->addParameter('"'. $message .'"');
}));

if (Str::contains($sh, 'Saved working directory and index') ||
Str::contains($sh, 'No local changes to save')
) {
return true;
}

return false;
}

/**
* @return string
*/
Expand Down
24 changes: 23 additions & 1 deletion tests/GitTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ArtARTs36\GitHandler\Tests\Unit;
namespace ArtARTs36\GitHandler\Tests;

use ArtARTs36\GitHandler\Exceptions\BranchNotFound;
use ArtARTs36\GitHandler\Exceptions\FileNotFound;
Expand Down Expand Up @@ -129,6 +129,28 @@ public function testClone(): void
"and is not an empty directory.", $dir)->clone($url);
}

/**
* @covers \ArtARTs36\GitHandler\Git::stash
*/
public function testStash(): void
{
$git = $this->mock('');

self::assertFalse($git->stash());

//

$git = $this->mock('Saved working directory and index state WIP on master: b68fd9d test');

self::assertTrue($git->stash());

//

$git = $this->mock('No local changes to save');

self::assertTrue($git->stash());
}

/**
* @param string $shellResult
* @param string|null $dir
Expand Down

0 comments on commit 88a2d4a

Please sign in to comment.