totten/git-scan

用于扫描/更新git仓库的命令行工具

2022-07-15 2022-07-16 06:45 UTC

README

Git-scan是为拥有大量重叠git仓库的用户设计的——例如,使用"composer"或"drush-make"的开发者可能会构建包含五六或更多仓库的工作目录。主要功能

  • 零配置
  • 与深度嵌套的仓库兼容
  • 根据状态("git scan status")过滤并显示仓库
  • 在有效时对仓库执行安全(快速前进)更新("git scan update")
  • 执行自定义命令("git scan foreach -c '...'”)
  • 对构建系统无感知(例如,与"composer"、"drush-make"以及手动编写的构建脚本兼容性良好)
  • 对分支/提交/审查流程无感知(例如,可以与个人读写仓库以及需要拉取请求的GitHub仓库兼容)

限制

  • IO密集型——执行文件系统扫描且不缓存结果

在博客文章中有更详细的描述,请参阅开发者提示:管理多个Git仓库

下载

git-scan以PHAR格式分发,这是一个可移植的可执行文件(用于PHP)。它应该在已安装PHP 7.2+的大多数类Unix系统上运行。

只需将git-scan下载到您的PATH中的某个位置,并使其可执行,例如。

cd /usr/local/bin  # or wherever else you want it to go, such as ~/bin
sudo curl -LsS https://download.civicrm.org/git-scan/git-scan.phar -o git-scan
sudo chmod +x git-scan

示例

me@localhost:~/drupal-demo$ git scan st
[[ Finding repositories ]]
[[ Checking statuses ]]
 5/5 [============================] 100%
[[ Results ]]

+--------+---------------------------------------------------------+--------------+---------------------+
| Status | Path                                                    | Local Branch | Remote Branch       |
+--------+---------------------------------------------------------+--------------+---------------------+
|     S  | drupal-demo/sites/all/modules/civicrm                   | master       | upstream/master     |
|        | drupal-demo/sites/all/modules/civicrm/drupal            | 7.x-master   | upstream/7.x-master |
|  FMN   | drupal-demo/sites/all/modules/civicrm/packages          | master       | upstream/master     |
|        | drupal-demo/sites/all/modules/contrib/civicrm_developer | master       | origin/master       |
+--------+---------------------------------------------------------+--------------+---------------------+
[F] Fast-forwards are not possible
[M] Modifications have not been committed
[N] New files have not been committed
[S] Stash contains data


me@localhost:~/drupal-demo$ git scan up 
[[ Finding repositories ]]
[[ Fast-forwarding ]]
Fast-forward drupal-demo/sites/all/modules/civicrm (master <= upstream/master)...
Fast-forward drupal-demo/sites/all/modules/civicrm/drupal (7.x-master <= upstream/7.x-master)...
Skip drupal-demo/sites/all/modules/civicrm/packages: Cannot be fast-forwarded
Fast-forward drupal-demo/sites/all/modules/contrib/civicrm_developer (master <= origin/master)...


me@localhost:~/drupal-demo$ git scan foreach -c 'echo "This is $(pwd)."; echo "The relative path is $path."; echo'
This is /home/me/drupal-demo/sites/all/modules/civicrm.
The relative path is sites/all/modules/civicrm/.

This is /home/me/drupal-demo/sites/all/modules/civicrm/drupal.
The relative path is sites/all/modules/civicrm/drupal/.

This is /home/me/drupal-demo/sites/all/modules/civicrm/packages.
The relative path is sites/all/modules/civicrm/packages/.

This is /home/me/drupal-demo/sites/all/modules/contrib/civicrm_developer.
The relative path is sites/all/modules/contrib/civicrm_developer/.


me@localhost:~/drupal-demo$ git scan foreach -c 'git pull --rebase' -v
[[ Finding repositories ]]
[[ /home/me/drupal-demo/sites/all/modules/civicrm ]]
STDOUT Current branch master is up to date.
[[ /home/me/drupal-demo/sites/all/modules/civicrm/drupal ]]
STDOUT Current branch 7.x-master is up to date.
[[ /home/me/drupal-demo/sites/all/modules/civicrm/packages ]]
STDERR Cannot pull with rebase: You have unstaged changes.
STDERR Please commit or stash them.                       
[[ /home/me/drupal-demo/sites/all/modules/civicrm/packages: exit code = 1 ]]
[[ /home/me/drupal-demo/sites/all/modules/contrib/civicrm_developer ]]
STDOUT Current branch master is up to date.

me@localhost:~/drupal-demo$ git scan am https://github.com/example/mymodule/pull/1234
In "sites/all/modules/mymodule/", the current branch is "master" based on "origin/master". What would you like to do it?
  [keep   ] Keep the current branch "master" along with any local changes. Apply patches on top.
  [rebuild] Rebuild the branch "master" based on "origin/master". Destroy any local changes. Apply changes on top.
  [new    ] Create a new branch "merge-master-20160411152732" based on "origin/master". Apply changes on top.
  [abort  ] Abort the auto-merge process. (default)
> new

配置

您可以创建一个文件,~/.git-scan.json,来自定义行为。支持选项

  • excludes:跳过扫描时要排除的路径名数组(例如,.svn.hg)。

开发:单元测试

如果您有phpunit 8.x / 9.x,则可以运行测试套件。例如

$ composer create-project totten/git-scan
$ cd git-scan
$ phpunit
PHPUnit 8.5.15 by Sebastian Bergmann.

Configuration read from /home/me/src/git-scan/phpunit.xml.dist

.................................................

Time: 2 seconds, Memory: 6.50Mb

OK (49 tests, 121 assertions)

辅助程序./scripts/test.sh是一个小型包装器,它将下载并执行适合版本的phpunit

开发:构建(PHAR)

如果您正在开发对git-scan的新更改,并希望从源创建新的git-scan.phar构建,那么您应该有gitcomposerbox

$ git clone https://github.com/totten/git-scan
$ cd git-scan
$ composer install
$ which box
/usr/local/bin/box
$ php -dphar.readonly=0 /usr/local/bin/box build

辅助程序./scripts/build.sh是一个小型包装器,它将下载并执行适合版本的box