Skip to content

Add support --branch together with --all mentioned in #253 #552

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

Open
wants to merge 3 commits into
base: release/0.4.5
Choose a base branch
from
Open
Changes from 1 commit
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
16 changes: 11 additions & 5 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,13 @@ main() {
command-init

if $all_wanted && [[ ! $command =~ ^(help|status)$ ]]; then
if [[ -n $subrepo_branch ]]; then
error "options --branch and --all are not compatible"
fi

# Run the command on all subrepos
local args=( "${command_arguments[@]}" )
get-all-subrepos
for subdir in ${subrepos[*]}; do
command-prepare
subrepo_remote=
subrepo_branch=
subrepo_branch=$override_branch
command_arguments=( "$subdir" "${args[@]}" )
"command:$command"
done
Expand Down Expand Up @@ -694,6 +690,16 @@ subrepo:fetch() {
error "Can't fetch subrepo. Remote is 'none' in '$subdir/.gitrepo'."
fi

if $all_wanted && [[ -n $subrepo_branch ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't something similar be necessary in subrepo:push?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I don't think anything is missing in subrepo:push. It's works fine with --all.

o "Check if the remote branch ($subrepo_branch) exists."
OUT=true RUN git ls-remote --heads "$subrepo_remote" "$subrepo_branch"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a command for this git:branch-exists see 644 for an example

if [[ -z $output ]]; then
SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.branch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a function to read the gitrepo file read-gitrepo-file

o "Remote branch ($subrepo_branch) in '$subrepo_remote' not exists, using branch ($output) from subrepo config."
subrepo_branch="$output"
fi
fi

o "Fetch the upstream: $subrepo_remote ($subrepo_branch)."
RUN git fetch --no-tags --quiet "$subrepo_remote" "$subrepo_branch"
OK || return
Expand Down