Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
592 changes: 592 additions & 0 deletions docs/GIT_COMMANDS.md

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions src/Console/Command/GitClone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Dingo\Api\Console\Command;

use Dingo\Api\Contract\Git\Service;
use Illuminate\Console\Command;

class GitClone extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
public $signature = 'api:git:clone
{repository : The repository URL to clone}
{destination : The destination path}
{--branch= : Branch to clone}
{--depth= : Create a shallow clone with a history truncated to the specified number of commits}
{--single-branch : Clone only one branch}
{--recursive : Clone submodules recursively}';

/**
* The console command description.
*
* @var string
*/
public $description = 'Clone a git repository';

/**
* Git service instance.
*
* @var \Dingo\Api\Contract\Git\Service
*/
protected $git;

/**
* Create a new git clone command instance.
*
* @param \Dingo\Api\Contract\Git\Service $git
*
* @return void
*/
public function __construct(Service $git)
{
$this->git = $git;

parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$repository = $this->argument('repository');
$destination = $this->argument('destination');

$this->info("Cloning repository: {$repository}");
$this->info("Destination: {$destination}");

$options = array_filter([
'branch' => $this->option('branch'),
'depth' => $this->option('depth'),
'single-branch' => $this->option('single-branch'),
'recursive' => $this->option('recursive'),
]);

if (!empty($options)) {
$this->line('Options: ' . json_encode($options));
}

$result = $this->git->clone($repository, $destination, $options);

if ($result['success']) {
$this->info('Repository cloned successfully!');

if (!empty($result['output'])) {
$this->line($result['output']);
}

return 0;
} else {
$this->error('Failed to clone repository.');

if (!empty($result['error'])) {
$this->error($result['error']);
}

if (isset($result['exception'])) {
$this->error($result['exception']);
}

return 1;
}
}
}
108 changes: 108 additions & 0 deletions src/Console/Command/GitCommit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Dingo\Api\Console\Command;

use Dingo\Api\Contract\Git\Service;
use Illuminate\Console\Command;

class GitCommit extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
public $signature = 'api:git:commit
{path : The repository path}
{message : Commit message}
{--all : Automatically stage all modified and deleted files}
{--amend : Amend the previous commit}
{--no-verify : Bypass pre-commit and commit-msg hooks}
{--author= : Override the commit author}';

/**
* The console command description.
*
* @var string
*/
public $description = 'Commit changes in a git repository';

/**
* Git service instance.
*
* @var \Dingo\Api\Contract\Git\Service
*/
protected $git;

/**
* Create a new git commit command instance.
*
* @param \Dingo\Api\Contract\Git\Service $git
*
* @return void
*/
public function __construct(Service $git)
{
$this->git = $git;

parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$path = $this->argument('path');
$message = $this->argument('message');

if (!$this->git->isRepository($path)) {
$this->error("The path [{$path}] is not a git repository.");
return 1;
}

$this->info("Committing changes in repository: {$path}");
$this->line("Message: {$message}");

$options = array_filter([
'all' => $this->option('all'),
'amend' => $this->option('amend'),
'no-verify' => $this->option('no-verify'),
'author' => $this->option('author'),
]);

if (!empty($options)) {
$this->line('Options: ' . json_encode($options));
}

$result = $this->git->commit($path, $message, $options);

if ($result['success']) {
$this->info('Commit created successfully!');

if (!empty($result['output'])) {
$this->line($result['output']);
}

if (!empty($result['error'])) {
$this->line($result['error']);
}

return 0;
} else {
$this->error('Failed to create commit.');

if (!empty($result['error'])) {
$this->error($result['error']);
}

if (isset($result['exception'])) {
$this->error($result['exception']);
}

return 1;
}
}
}
105 changes: 105 additions & 0 deletions src/Console/Command/GitFetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace Dingo\Api\Console\Command;

use Dingo\Api\Contract\Git\Service;
use Illuminate\Console\Command;

class GitFetch extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
public $signature = 'api:git:fetch
{path : The repository path}
{--remote= : Remote to fetch from}
{--branch= : Branch to fetch}
{--prune : Remove remote-tracking references that no longer exist on remote}
{--all : Fetch all remotes}';

/**
* The console command description.
*
* @var string
*/
public $description = 'Fetch from a git repository';

/**
* Git service instance.
*
* @var \Dingo\Api\Contract\Git\Service
*/
protected $git;

/**
* Create a new git fetch command instance.
*
* @param \Dingo\Api\Contract\Git\Service $git
*
* @return void
*/
public function __construct(Service $git)
{
$this->git = $git;

parent::__construct();
}

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$path = $this->argument('path');

if (!$this->git->isRepository($path)) {
$this->error("The path [{$path}] is not a git repository.");
return 1;
}

$this->info("Fetching from repository: {$path}");

$options = array_filter([
'remote' => $this->option('remote'),
'branch' => $this->option('branch'),
'prune' => $this->option('prune'),
'all' => $this->option('all'),
]);

if (!empty($options)) {
$this->line('Options: ' . json_encode($options));
}

$result = $this->git->fetch($path, $options);

if ($result['success']) {
$this->info('Fetch completed successfully!');

if (!empty($result['output'])) {
$this->line($result['output']);
}

if (!empty($result['error'])) {
$this->line($result['error']);
}

return 0;
} else {
$this->error('Failed to fetch from repository.');

if (!empty($result['error'])) {
$this->error($result['error']);
}

if (isset($result['exception'])) {
$this->error($result['exception']);
}

return 1;
}
}
}
Loading