twosigma / git-meta

Repository for the git-meta project -- build your own monorepo using Git submodules
http://twosigma.github.io/git-meta
BSD 3-Clause "New" or "Revised" License
216 stars 50 forks source link

Add 'submodule foreach' command by forwarding to vanilla git #795

Closed kaaniboy closed 3 years ago

kaaniboy commented 3 years ago

As noted in issue #409, git meta does not yet support the submodule foreach command. This PR adds the foreach command by forwarding to vanilla git. It exposes the following command line interface, which supports all arguments available in vanilla git:

▶ gm submodule foreach --help
usage: git-meta submodule foreach [-h] [--recursive] [--quiet] foreach-command

Evaluate a shell command in each open sub-repo. Any sub-repo in the meta-repo
that is not opened is ignored by this command.

Positional arguments:
  foreach-command  shell command to execute for each open sub-repo

Optional arguments:
  -h, --help       Show this help message and exit.
  --recursive      sub-repos are traversed recursively
  --quiet          only print error messages

An example execution of the command to print the working directory of each open sub-repo is as follows:

Entering 'bn/yx/wga'
/Users/kaan/Desktop/gm-clone/bn/yx/wga
Entering 'cz/zn/epj'
/Users/kaan/Desktop/gm-clone/cz/zn/epj
Entering 'dy/an/rth'
/Users/kaan/Desktop/gm-clone/dy/an/rth

Note: Forwarding is not done directly in git-meta.js, but rather cmd/submodule.js. This is because there are subcommands under git meta submodule that are not forwarded to vanilla git.