Show current branch in snip single
Reset branch automatically if trying to commit detached
This commit is contained in:
parent
4e56fed76d
commit
1f464220ee
@ -35,10 +35,11 @@ class SnipController extends AbstractController
|
|||||||
public function single(Snip $snip): Response
|
public function single(Snip $snip): Response
|
||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
|
$this->denyAccessUnlessGranted(SnipVoter::VIEW, $snip);
|
||||||
|
$snipService = $this->snipServiceFactory->create($snip);
|
||||||
return $this->render('snip/single.html.twig', [
|
return $this->render('snip/single.html.twig', [
|
||||||
'snip' => $snip,
|
'snip' => $snip,
|
||||||
'content' => $this->snipServiceFactory->create($snip)->get(),
|
'content' => $snipService->get(),
|
||||||
|
'branch' => $snipService->getRepo()->getCurrentBranchName(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@ use App\Git\CustomGitRepository;
|
|||||||
|
|
||||||
class SnipService
|
class SnipService
|
||||||
{
|
{
|
||||||
|
private const SNIP_FILE_NAME = 'snip.txt';
|
||||||
|
private const MASTER_BRANCH_NAME = 'master';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly CustomGitRepository $repo,
|
private readonly CustomGitRepository $repo,
|
||||||
private readonly User $user,
|
private readonly User $user,
|
||||||
@ -26,8 +29,11 @@ class SnipService
|
|||||||
|
|
||||||
public function update(string $snipContents): void
|
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);
|
file_put_contents($this->getSnipPath(), $snipContents);
|
||||||
$this->repo->addFile('snip.txt');
|
$this->repo->addFile(self::SNIP_FILE_NAME);
|
||||||
if ($this->repo->hasChanges()) {
|
if ($this->repo->hasChanges()) {
|
||||||
$this->repo->commit(sprintf('Updated snip at %s by %s', date('Y-m-d H:i:s'), $this->user));
|
$this->repo->commit(sprintf('Updated snip at %s by %s', date('Y-m-d H:i:s'), $this->user));
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
{{ include('snip/badge.html.twig', {snip: snip}) }}
|
{{ include('snip/badge.html.twig', {snip: snip}) }}
|
||||||
{{ snip }}
|
{{ snip }}
|
||||||
</h4>
|
</h4>
|
||||||
|
<div class="card-header">
|
||||||
|
<p class="card-text">Current branch: {{ branch }}</p>
|
||||||
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<p class="card-text">{{ content|nl2br }}</p>
|
<p class="card-text">{{ content|nl2br }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user