Skip to content
Merged
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
35 changes: 35 additions & 0 deletions nix/buildkit-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
{ # https://stackoverflow.com/a/21100710

## Re-generate the buildkit.nix file - with the current 'master' branch.

set -e

if [ ! -f "nix/buildkit.nix" ]; then
echo >&2 "Must run in project root"
exit 1
fi

now=$( date -u '+%Y-%m-%d %H:%M %Z' )
commit=$( git ls-remote https://github.com/civicrm/civicrm-buildkit.git | awk '/refs\/heads\/master$/ { print $1 }' )
url="https://github.com/civicrm/civicrm-buildkit/archive/${commit}.tar.gz"
hash=$( nix-prefetch-url "$url" --type sha256 --unpack )

function render_file() {
echo "{ pkgs ? import <nixpkgs> {} }:"
echo ""
echo "## Get civicrm-buildkit from github."
echo "## Based on \"master\" branch circa $now"
echo "import (pkgs.fetchzip {"
echo " url = \"$url\";"
echo " sha256 = \"$hash\";"
echo "})"
echo
echo "## Get a local copy of civicrm-buildkit. (Useful for developing patches.)"
echo "# import ((builtins.getEnv \"HOME\") + \"/buildkit/default.nix\")"
echo "# import ((builtins.getEnv \"HOME\") + \"/bknix/default.nix\")"
}
render_file > nix/buildkit.nix

exit
}
12 changes: 12 additions & 0 deletions nix/buildkit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ pkgs ? import <nixpkgs> {} }:

## Get civicrm-buildkit from github.
## Based on "master" branch circa 2024-02-26 04:30 UTC
import (pkgs.fetchzip {
url = "https://github.com/civicrm/civicrm-buildkit/archive/d6f6b8dd2d5944c35cd78cb319fef21673214b35.tar.gz";
sha256 = "02p2yzdfgv66a2zf8i36h6pjfi78wnp92m3klij7fqbfd9mpvi5a";
})

## Get a local copy of civicrm-buildkit. (Useful for developing patches.)
# import ((builtins.getEnv "HOME") + "/buildkit/default.nix")
# import ((builtins.getEnv "HOME") + "/bknix/default.nix")
33 changes: 33 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This shell is suitable for compiling PHAR executables.... and not much else.
*
* Ex: `nix-shell --run ./scripts/build.sh`
*/

{ pkgs ? import <nixpkgs> {} }:

let

buildkit = (import ./nix/buildkit.nix) { inherit pkgs; };

in

pkgs.mkShell {
nativeBuildInputs = buildkit.profiles.base ++ [

(buildkit.pins.v2305.php82.buildEnv {
extraConfig = ''
memory_limit=-1
'';
})

buildkit.pkgs.box
buildkit.pkgs.composer
buildkit.pkgs.phpunit9

pkgs.bash-completion
];
shellHook = ''
source ${pkgs.bash-completion}/etc/profile.d/bash_completion.sh
'';
}
3 changes: 2 additions & 1 deletion src/GitScan/Command/AutoMergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function configure() {
->addOption('keep', 'K', InputOption::VALUE_NONE, 'When applying patches, keep the current branch. Preserve local changes.')
->addOption('new', 'N', InputOption::VALUE_NONE, 'When applying patches, create a new merge branch.')
->addOption('path', NULL, InputOption::VALUE_REQUIRED, 'The local base path to search', getcwd())
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addOption('url-split', NULL, InputOption::VALUE_REQUIRED, 'If listing multiple URLs in one argument, use the given delimiter', '|')
// The preflight check is optional because 'git apply --check' can be too picky sometimes (e.g. commit A adds a file; commit B renames the file)
->addOption('check', NULL, InputOption::VALUE_NONE, 'Before applying patches, do a preflight check.')
Expand All @@ -79,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getOption('path'));
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));

// array(string $absDir => TRUE)
$checkouts = array();
Expand Down
5 changes: 3 additions & 2 deletions src/GitScan/Command/BranchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected function configure() {
->setName('branch')
->setDescription('Create branches across repos')
->addOption('path', NULL, InputOption::VALUE_REQUIRED, 'The local base path to search', getcwd())
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addOption('prefix', 'p', InputOption::VALUE_NONE, 'Autodetect prefixed variations')
->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete fully merged branches')
->addOption('force-delete', 'D', InputOption::VALUE_NONE, 'Delete branch (even if not merged)')
Expand Down Expand Up @@ -60,7 +61,7 @@ protected function executeCreate(InputInterface $input, OutputInterface $output)

$helper = $this->getHelper('question');
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getOption('path'));
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
$batch = new ProcessBatch('Creating branch(es)...');
$self = $this;

Expand Down Expand Up @@ -103,7 +104,7 @@ function (GitRepo $gitRepo, $oldBranch, $newBranch) use ($input, $output, $helpe
protected function executeDelete(InputInterface $input, OutputInterface $output): int {
$helper = $this->getHelper('question');
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getOption('path'));
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
$batch = new ProcessBatch('Deleting branch(es)...');

$branchName = $input->getArgument('branchName');
Expand Down
10 changes: 6 additions & 4 deletions src/GitScan/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected function configure() {
->setHelp('Compare the commits/revisions in different source trees')
->addArgument('from', InputArgument::REQUIRED, 'Path to the project folder or JSON export')
->addArgument('to', InputArgument::REQUIRED, 'Path to the project folder or JSON export')
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addOption('format', NULL, InputOption::VALUE_REQUIRED, 'Output format (text|html|json)', 'text');
}

Expand All @@ -46,8 +47,8 @@ protected function initialize(InputInterface $input, OutputInterface $output) {
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$fromDoc = $this->getCheckoutDocument($input->getArgument('from'));
$toDoc = $this->getCheckoutDocument($input->getArgument('to'));
$fromDoc = $this->getCheckoutDocument($input->getArgument('from'), $input->getOption('max-depth'));
$toDoc = $this->getCheckoutDocument($input->getArgument('to'), $input->getOption('max-depth'));

$report = new DiffReport(
$fromDoc,
Expand Down Expand Up @@ -87,12 +88,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* @param string $path path to a directory or JSON file
* @param int $maxDepth
* @return \GitScan\CheckoutDocument
*/
protected function getCheckoutDocument($path) {
protected function getCheckoutDocument($path, $maxDepth = -1) {
if (is_dir($path)) {
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($path);
$gitRepos = $scanner->scan($path, $maxDepth);

return CheckoutDocument::create($path)
->importRepos($gitRepos);
Expand Down
4 changes: 3 additions & 1 deletion src/GitScan/Command/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use GitScan\Util\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class ExportCommand extends BaseCommand {
Expand All @@ -26,6 +27,7 @@ protected function configure() {
->setName('export')
->setDescription('Show the status of any nested git repositories')
->setHelp("Export the current checkout information to JSON format")
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()));
}

Expand All @@ -42,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$gitRepos = $scanner->scan($paths);
$gitRepos = $scanner->scan($paths, $input->getOption('max-depth'));
$output->writeln(
\GitScan\CheckoutDocument::create($paths[0])
->importRepos($gitRepos)
Expand Down
3 changes: 2 additions & 1 deletion src/GitScan/Command/ForeachCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function configure() {
. "Important: The example uses single-quotes to escape the $'s\n"
)
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()))
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addOption('command', 'c', InputOption::VALUE_REQUIRED, 'The command to execute')
->addOption('status', NULL, InputOption::VALUE_REQUIRED, 'Filter table output by repo statuses ("all","novel","boring")', 'all');
}
Expand Down Expand Up @@ -70,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("<comment>[[ Finding repositories ]]</comment>");
}
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getArgument('path'));
$gitRepos = $scanner->scan($input->getArgument('path'), $input->getOption('max-depth'));

foreach ($gitRepos as $gitRepo) {
/** @var \GitScan\GitRepo $gitRepo */
Expand Down
4 changes: 3 additions & 1 deletion src/GitScan/Command/HashCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use GitScan\Util\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class HashCommand extends BaseCommand {
Expand All @@ -26,6 +27,7 @@ protected function configure() {
->setName('hash')
->setDescription('Generate a hash')
->setHelp("Generate a cumulative hash code for the current checkouts")
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()));
}

Expand All @@ -42,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$output->writeln($scanner->hash($paths[0]));
$output->writeln($scanner->hash($paths[0], $input->getOption('max-depth')));
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion src/GitScan/Command/LsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected function configure() {
Example: git scan ls | while read dir; do ls -la $dir ; done
')
->addOption('absolute', 'A', InputOption::VALUE_NONE, 'Output absolute paths')
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()));
}

Expand All @@ -47,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$gitRepos = $scanner->scan($paths);
$gitRepos = $scanner->scan($paths, $input->getOption('max-depth'));
foreach ($gitRepos as $gitRepo) {
/** @var \GitScan\GitRepo $gitRepo */
$path = $input->getOption('absolute')
Expand Down
3 changes: 2 additions & 1 deletion src/GitScan/Command/PushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected function configure() {
->setName('push')
->setDescription('Push tags or branches on all repos')
->addOption('path', NULL, InputOption::VALUE_REQUIRED, 'The local base path to search', getcwd())
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addOption('prefix', 'p', InputOption::VALUE_NONE, 'Autodetect prefixed variations')
->addOption('dry-run', 'T', InputOption::VALUE_NONE, 'Display what would be done')
->addOption('set-upstream', 'u', InputOption::VALUE_NONE, 'Set remote branch as upstream for local branch')
Expand All @@ -42,7 +43,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) {

protected function execute(InputInterface $input, OutputInterface $output): int {
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getOption('path'));
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
$remote = $input->getArgument('remote');
$batch = new ProcessBatch('Pushing...');

Expand Down
3 changes: 2 additions & 1 deletion src/GitScan/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected function configure() {
->setDescription('Show the status of any nested git repositories')
->setHelp("Show the status of any nested git repositories.\n\nNote: This will fetch upstream repositories to help determine the status (unless you specify --offline mode).")
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()))
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addOption('status', NULL, InputOption::VALUE_REQUIRED, 'Filter table output by repo statuses ("all","novel","boring","auto")', 'auto')
->addOption('fetch', NULL, InputOption::VALUE_NONE, 'Fetch latest data about remote repositories. (Slower but more accurate statuses.)');
//->addOption('scan', 's', InputOption::VALUE_NONE, 'Force an immediate scan for new git repositories before doing anything')
Expand All @@ -48,7 +49,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$output->writeln("<comment>[[ Finding repositories ]]</comment>");
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getArgument('path'));
$gitRepos = $scanner->scan($input->getArgument('path'), $input->getOption('max-depth'));

if ($input->getOption('status') == 'auto') {
$input->setOption('status', count($gitRepos) > self::DISPLAY_ALL_THRESHOLD ? 'novel' : 'all');
Expand Down
5 changes: 3 additions & 2 deletions src/GitScan/Command/TagCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected function configure() {
->setName('tag')
->setDescription('Create tags across repos')
->addOption('path', NULL, InputOption::VALUE_REQUIRED, 'The local base path to search', getcwd())
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addOption('prefix', 'p', InputOption::VALUE_NONE, 'Autodetect prefixed variations')
->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete fully merged branches')
->addOption('dry-run', 'T', InputOption::VALUE_NONE, 'Display what would be done')
Expand Down Expand Up @@ -59,7 +60,7 @@ protected function executeCreate(InputInterface $input, OutputInterface $output)

$helper = $this->getHelper('question');
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getOption('path'));
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
$batch = new ProcessBatch('Creating tag(s)...');
$self = $this;

Expand Down Expand Up @@ -101,7 +102,7 @@ function (GitRepo $gitRepo, $oldBranch, $newTag) use ($input, $output, $helper,

protected function executeDelete(InputInterface $input, OutputInterface $output): int {
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getOption('path'));
$gitRepos = $scanner->scan($input->getOption('path'), $input->getOption('max-depth'));
$batch = new ProcessBatch('Deleting branch(es)...');

$tagName = $input->getArgument('tagName');
Expand Down
4 changes: 3 additions & 1 deletion src/GitScan/Command/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use GitScan\Util\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class UpdateCommand extends BaseCommand {
Expand All @@ -27,6 +28,7 @@ protected function configure() {
->setAliases(array('up'))
->setDescription('Execute fast-forward merges on all nested repositories')
->setHelp('Execute fast-forward merges on all nested repositories (which are already amenable to fast-forwarding)')
->addOption('max-depth', NULL, InputOption::VALUE_REQUIRED, 'Limit the depth of the search', -1)
->addArgument('path', InputArgument::IS_ARRAY, 'The local base path to search', array(getcwd()));
}

Expand All @@ -40,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln("<comment>[[ Finding repositories ]]</comment>");
$scanner = new \GitScan\GitRepoScanner();
$gitRepos = $scanner->scan($input->getArgument('path'));
$gitRepos = $scanner->scan($input->getArgument('path'), $input->getOption('max-depth'));

$output->writeln("<comment>[[ Fast-forwarding ]]</comment>");
foreach ($gitRepos as $gitRepo) {
Expand Down
13 changes: 10 additions & 3 deletions src/GitScan/GitRepoScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ public function __construct($fs = NULL, ?\GitScan\Config $config = NULL) {
* given base dir.
*
* @param string|array $basedir
* @param int $maxDepth
* Maximum number of directory-levels to traverse.
* Use -1 for unlimited.
* @return array of GitRepo
*/
public function scan($basedir) {
public function scan($basedir, $maxDepth = -1) {
$gitRepos = array();
$finder = new Finder();
if ($maxDepth >= 0) {
$finder->depth('<= ' . $maxDepth);
}
$finder->in($basedir)
->ignoreUnreadableDirs()
// Specifically looking for .git files!
Expand All @@ -55,10 +61,11 @@ public function scan($basedir) {
* within a given base dir.
*
* @param string $basedir
* @param int $maxDepth
* @return string
*/
public function hash($basedir) {
$gitRepos = $this->scan($basedir);
public function hash($basedir, $maxDepth = -1) {
$gitRepos = $this->scan($basedir, $maxDepth);
$buf = '';
foreach ($gitRepos as $gitRepo) {
$path = rtrim($this->fs->makePathRelative($gitRepo->getPath(), $basedir), '/');
Expand Down
Loading