Skip to content

#132 Add '--all' option to 'status' to list all nested subrepos. #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
29 changes: 23 additions & 6 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ main() {
command-init

# Run the command:
if $all_wanted && [[ ! $command =~ ^(help|merge-base)$ ]]; then
if $all_wanted && [[ ! $command =~ ^(help|merge-base|status)$ ]]; then
local args=( "${command_arguments[@]}" )
get-all-subrepos
get-all-top-level-subrepos
for subdir in ${subrepos[*]}; do
command-prepare
subrepo_remote=
Expand Down Expand Up @@ -855,7 +855,11 @@ subrepo:merge-base() {

subrepo:status() {
if [[ ${#command_arguments[@]} -eq 0 ]]; then
get-all-subrepos
if "$all_wanted"; then
get-all-nested-subrepos
else
get-all-top-level-subrepos
fi
local count=${#subrepos[@]}
if ! "$quiet_wanted"; then
if [[ $count -eq 0 ]]; then
Expand Down Expand Up @@ -1090,7 +1094,7 @@ options_init='branch remote'
options_merge_base='all'
options_pull='all branch remote update'
options_push='all branch force remote update'
options_status='fetch'
options_status='all fetch'
check_option() {
local var="options_${command//-/_}"
[[ ${!var} =~ $1 ]] ||
Expand Down Expand Up @@ -1352,8 +1356,21 @@ assert-subdir-empty() {
#------------------------------------------------------------------------------

# Find all the current subrepos by looking for all the subdirectories that
# contain a `.gitrepo` file.
get-all-subrepos() {
# contain a `.gitrepo` file, including nested subrepos.

get-all-nested-subrepos() {
subrepos=($(
find . -name '.gitrepo' |
grep -v '/.git/' |
grep '/.gitrepo$' |
sed 's/.gitrepo$//' |
sort
))
}

# Find all the current subrepos by looking for all the subdirectories that
# contain a `.gitrepo` file, excluding nested subrepos.
get-all-top-level-subrepos() {
local paths=(); paths=($(
find . -name '.gitrepo' |
grep -v '/.git/' |
Expand Down
33 changes: 29 additions & 4 deletions test/status.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,40 @@ use Test::More
output="$(git subrepo status)"

like "$output" "2 subrepos:" \
"Status intro ok"
"'status' intro ok"

like "$output" "Git subrepo 'ext/bashplus':" \
"bashplus is in status"
"ext/bashplus is in 'status'"

like "$output" "Git subrepo 'ext/test-more-bash':" \
"test-more-bash is in status"
"ext/test-more-bash is in 'status'"

unlike "$output" "Git subrepo 'ext/test-more-bash/ext/bashplus':" \
"ext/test-more-bash/ext/bashplus is not in 'status'"

unlike "$output" "Git subrepo 'ext/test-more-bash/ext/test-tap-bash':" \
"ext/test-more-bash/ext/test-tap-bash is not in 'status'"
}

{
output="$(git subrepo status --all)"

like "$output" "4 subrepos:" \
"'status --all' intro ok"

like "$output" "Git subrepo 'ext/bashplus':" \
"ext/bashplus is in 'status --all'"

like "$output" "Git subrepo 'ext/test-more-bash':" \
"ext/test-more-bash is in 'status --all'"

like "$output" "Git subrepo 'ext/test-more-bash/ext/bashplus':" \
"ext/test-more-bash/ext/bashplus is in 'status --all'"

like "$output" "Git subrepo 'ext/test-more-bash/ext/test-tap-bash':" \
"ext/test-more-bash/ext/test-tap-bash is in 'status --all'"
}

done_testing 3
done_testing 10

teardown