Skip to content
Open
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
52 changes: 47 additions & 5 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ main() {

local subrepo_remote= # Remote url for subrepo's upstream repo
local subrepo_branch= # Upstream branch to clone/push/pull
local subrepo_branch_commit= # Upstream branch commit to clone
local subrepo_commit= # Upstream HEAD from previous clone/pull
local subrepo_parent= # Local commit from before previous clone/pull
local subrepo_former= # A retired gitrepo key that might still exist
Expand Down Expand Up @@ -205,7 +206,11 @@ command:clone() {
local re=
$force_wanted && re=re
local remote=$subrepo_remote
say "Subrepo '$remote' ($subrepo_branch) ${re}cloned into '$subdir'."
local bc=$subrepo_branch
if [ -n "$subrepo_branch_commit" ]; then
bc=$subrepo_branch@$subrepo_branch_commit
fi
say "Subrepo '$remote' ($bc) ${re}cloned into '$subdir'."
}

# `git subrepo init <subdir>` command:
Expand Down Expand Up @@ -236,7 +241,11 @@ command:pull() {

subrepo:pull
if OK; then
say "Subrepo '$subdir' pulled from '$subrepo_remote' ($subrepo_branch)."
local bc=$subrepo_branch
if [ -n "$subrepo_branch_commit" ]; then
bc=$subrepo_branch@$subrepo_branch_commit
fi
say "Subrepo '$subdir' pulled from '$subrepo_remote' ($bc)."
elif [[ $CODE -eq -1 ]]; then
say "Subrepo '$subdir' is up to date."
elif [[ $CODE -eq 1 ]]; then
Expand Down Expand Up @@ -274,7 +283,11 @@ command:fetch() {
say "Ignored '$subdir', no remote."
else
subrepo:fetch
say "Fetched '$subdir' from '$subrepo_remote' ($subrepo_branch)."
local bc=$subrepo_branch
if [ -n "$subrepo_branch_commit" ]; then
bc=$subrepo_branch@$subrepo_branch_commit
fi
say "Fetched '$subdir' from '$subrepo_remote' ($bc)."
fi
}

Expand Down Expand Up @@ -727,6 +740,13 @@ subrepo:fetch() {
RUN git fetch --no-tags --quiet "$subrepo_remote" "$subrepo_branch"
OK || return

if [[ -n "$subrepo_branch_commit" ]]; then
reset-upstream-subrepo-branch-commit
o "Re-fetch the upstream: $subrepo_remote ($subrepo_branch@$subrepo_branch_commit)."
RUN git fetch --no-tags --quiet "$subrepo_remote" "$subrepo_branch_commit"
OK || return
fi

o "Get the upstream subrepo HEAD commit."
OUT=true RUN git rev-parse FETCH_HEAD^0
upstream_head_commit=$output
Expand Down Expand Up @@ -1093,8 +1113,11 @@ get-command-options() {
-a) all_wanted=true ;;
-A) ALL_wanted=true
all_wanted=true ;;
-b) subrepo_branch=$1
override_branch=$1
-b) subrepo_branch=${1%%@*}
override_branch=${1%%@*}
if [ "${subrepo_branch}" != "${1}" ]; then
subrepo_branch_commit=${1#*@}
fi
commit_msg_args+=("--branch=$1")
shift ;;
-e) edit_wanted=true ;;
Expand Down Expand Up @@ -1650,6 +1673,25 @@ add-subrepo() {
subrepos+=("$1")
}

# Determine and set real commit behind branch@commit request
reset-upstream-subrepo-branch-commit() {
local branch_commit
OUT=true RUN git rev-parse FETCH_HEAD^0
branch_commit=$output
[[ -n "$branch_commit" ]] ||
error "Problem finding head commit in upstream branch '${subrepo_branch}'."

if [[ ! "${branch_commit}" =~ ^$subrepo_branch_commit ]]; then
OUT=true FAIL=false RUN git rev-list --parents "$subrepo_branch_commit".."$branch_commit"
branch_commit=$(
echo "$output" | sed -e '$!d' -e 's/.* //'
)
[[ -n "$branch_commit" ]] ||
error "Problem finding '${subrepo_branch_commit}' commit in upstream branch '${subrepo_branch}'."
fi
subrepo_branch_commit=$branch_commit
}

# Determine the upstream's default head branch:
get-upstream-head-branch() {
local remotes branch
Expand Down
Loading
Loading