- git submodule subcommand parsing modified.
commitc1e8be5d4d86532d8a634056acdb1606d93c21c6
authorImran M Yousuf <imyousuf@smartitengineering.com>
Mon, 14 Jan 2008 09:56:38 +0000 (14 15:56 +0600)
committerImran M Yousuf <imyousuf@smartitengineering.com>
Mon, 14 Jan 2008 09:56:38 +0000 (14 15:56 +0600)
tree6770ae7b48832d0723fddbb90f8172b6a2d388ea
parent2db2f2980b2f584a48da297157b78805a55a0422
- git submodule subcommand parsing modified.

- manual page of git-submodule and usage mentioned in git-subcommand.sh
were not same, thus synchronized them. In doing so also had to change the
way the subcommands were parsed.

- Previous version did not allow commands such as
git-submodule add init update
as the command parser incorrectly made subcommand names reserve.
Thus refusing them to be used as parameters to subcommands. As a result it
was impossible to add a submodule whose (symbolic) name is "init" and that
resides at path "update" was refused. For more details the following case
can be considered -

mkdir g; mkdir f; cd g/
touch g.txt; echo "sample text for g.txt" >> ./g.txt; git-init;
git-add g.txt; git-commit -a -m "First commit on g"
cd ../f/; ln -s ../g/ init
git-init; git-submodule add init update;
git-commit -a -m "With module update"
mkdir ../test; cd ../test
git-clone ../f/; cd f
git-submodule init update; git-submodule update update
cd ../..; rm -rf ./f/ ./test/ ./g/

This patch fixes this issue and allows it as well.

- Status currently is implemented to show list only but later
implementation might change and list and status could coexists. Thus
status module is introduced. The module is also used to parse its
arguments

- Subcommands will also parse their own commands; thus enabling command
specific arguments to be passed after the command. For example,
git-submodule -q add -b master module_a
git-submodule -q status -c
It is to be noted that -q or --quiet is specified before the subcommand
since it is for the submodule command in general rather than the
subcommand. It is mention worthy that backward compatibility exists and
thus commands like git submodule --cached status will also work as expected

- Subcommands that currently do not take any arguments (init and update)
has a case which is introduced just to ensure that no argument is
deliberately sent as the first argument and also to serve the purpose of
providing a future extension point for its arguments.

- Though ther was short and long version for quiet (-q or --quiet and
branch (-b or --branch) but there was no short version for cached. Thus
it is now introduced (-c or --cached).

- Added 3 specific messages for usage error related to branch and cached

- Simplified subcommand action invocation by simply invoking the action if
all conditions are fulfilled. Excepting for parsing command line arguments
case statements are avoided and instead more direct if statement is
introduced.

- Introduced 'recurse' command for git-submodule

- The purpose of the recurse command in the git submodule is to recurse
a command in its submodule. For example if one wants to do a diff on its
project with submodules at once, one can simply do
git-submodule recurse diff HEAD
and would see the diff for all the modules it contains.

- The recurse commands behavior can be customized with several arguments
that it accepts. The synopsis for the recurse command is:

git-submodule [-q|--quiet] recurse [-i|--initialize]
[-e|--exit-after-error] [-d|--depth <recursion depth>]
[-df|--depth-first] [-ca|--customized-argument] [-p|--pre-command]
<command> [<arguments> ...]

- When traversing modules, a module could be uninitialized that is git
submodule init and update has not been called for it; if [-i|--initialize]
option is specified, it will initialize any module that is not initialized;
else if the module is not initialized it will simply skip it.

- There are commands that can fail for a certain submodule but succeed for
others; if one wants to stop execution once the top level module's execution
fails, one can specify [-e|--exit-after-error]. It will ensure that once
execution of git <command> fails in the top level module it will not recurse
into its submodules.

- If the project has submodule hierarchy upto n depth and we want to restrict
recursion to (n-p) depth; we can use the [-d|--depth <recursion depth>] option.
Value has to be greater than 0 and command will at least recurse into the first
depth. If depth is specified to p than all depths <= p will be recursed over.

- While discussion on the recurse command one thing which was put forward
in several occassions is that there might be scenario where a command should be
executed over the child module before the parent module. For such scenario
[-df|--depth-first] option can be used; one use case in particualar presented
as an example is git commit; where almost everybody mentioned that they prefer
to commit the child module before the parent and -df will enable just that.
E.g. p -> a, b, c, e; a ->d is a module structure. If the following command is
used,
git submodule recurse -df commit -a
it will execute git commit -a in the following sequence - d, a, b, c, e, p.

- There is also another scenario which has been put forward several times in
discussion over the recurse command and it is that commands chould have
different arguments for different modules. For example for the same example
mentioned above, one wants to check a_1 for submdoule a, while it wants to
checkout d_2 for d. It can be achieved by using [-ca|--customized-argument].
This results the script to prompt for user input, which will be passed as
argument to the command for that module.
git submodule recurse -ca checkout
Working in mod a .......
Please provide arguments for this module: a_1
Working in mod d .......
Please provide arguments for this module: a_1

- I usually found that when typing a command being able to see some options
come in handy. For example if I can see the available branches before checking
out a branch that would be useful, IOW, if I could git branch before git
checkout; it is now possible using the [-p|--pre-command] option. Using this
command you can actually execute other git commands before specifying the
arguments to the original command. E.g. if the above command is changed to,
git submodule recurse -ca -p checkout
it will prompt the user for the pre command until one is satisfied and later
the user can actually use them in the argument.

Signed-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>
git-submodule