Show current branch in snip single
Reset branch automatically if trying to commit detached
This commit is contained in:
@ -7,6 +7,9 @@ use App\Git\CustomGitRepository;
|
||||
|
||||
class SnipService
|
||||
{
|
||||
private const SNIP_FILE_NAME = 'snip.txt';
|
||||
private const MASTER_BRANCH_NAME = 'master';
|
||||
|
||||
public function __construct(
|
||||
private readonly CustomGitRepository $repo,
|
||||
private readonly User $user,
|
||||
@ -26,8 +29,11 @@ class SnipService
|
||||
|
||||
public function update(string $snipContents): void
|
||||
{
|
||||
if ($this->repo->getCurrentBranchName() !== self::MASTER_BRANCH_NAME) {
|
||||
$this->repo->checkout(self::MASTER_BRANCH_NAME);
|
||||
}
|
||||
file_put_contents($this->getSnipPath(), $snipContents);
|
||||
$this->repo->addFile('snip.txt');
|
||||
$this->repo->addFile(self::SNIP_FILE_NAME);
|
||||
if ($this->repo->hasChanges()) {
|
||||
$this->repo->commit(sprintf('Updated snip at %s by %s', date('Y-m-d H:i:s'), $this->user));
|
||||
}
|
||||
|
Reference in New Issue
Block a user