Commit 370a7eb1 authored by Brad King's avatar Brad King

Teach our 'git-gitlab-push' script to push ExternalData content

Teach the git-gitlab-push script to push refs/data/* references
to the remote repository along with the topic.
parent 331c7814
......@@ -25,6 +25,12 @@ OPTIONS
-f,--force
Force-push the topic HEAD to rewrite the destination branch
--keep-data
Do not erase local data refs after pushing
--no-data
Do not push any data refs that may normally go with the topic
--no-default
Do not push the default branch (e.g. master)
......@@ -55,20 +61,58 @@ gitlab_pushurl=$(git config --get remote.gitlab.pushurl ||
git config --get remote.gitlab.url) &&
gitlab_configured=1
data_report_and_remove() {
data="$1" &&
if test -n "$keep_data"; then
action="kept"
else
action="removed"
if test -z "$dry_run"; then
git update-ref -d "$1" 2>/dev/null || true
fi
fi &&
echo "Pushed $data and $action local ref."
}
data_refs() {
git rev-list "$@" |
git diff-tree --no-commit-id --root -c -r --diff-filter=AM --stdin |
egrep '\.(md5)$' |
# read :srcmode dstmode srcobj dstobj status file
while read _ _ _ obj _ file; do
# Identify the hash algorithm used.
case "$file" in
*.md5) algo=MD5 ; validate="^[0-9a-fA-F]{32}$" ;;
*) continue ;;
esac
# Load and validate the hash.
if hash=$(git cat-file blob $obj 2>/dev/null) &&
echo "$hash" | egrep-q "$validate"; then
# Use this data ref if it exists.
git for-each-ref --format='%(refname)' "refs/data/$algo/$hash"
fi
done
}
#-----------------------------------------------------------------------------
remote=''
refspecs=''
force=''
keep_data=''
no_topic=''
no_default=''
no_data=''
dry_run=''
# Parse the command line options.
while test $# != 0; do
case "$1" in
-f|--force) force='+' ;;
--keep-data) keep_data=1 ;;
--no-topic) no_topic=1 ;;
--no-data) no_data=1 ;;
--dry-run) dry_run=--dry-run ;;
--no-default) no_default=1 ;;
--) shift; break ;;
......@@ -110,6 +154,16 @@ echo "Fetching $upstream_remote master"
fetch_out=$(git fetch "$upstream_remote" master 2>&1) || die "$fetch_out"
upstream_head=$(git rev-parse FETCH_HEAD) || exit
# Collect refspecs for each data object referenced by the topic.
if test -z "$no_data"; then
data_refs=$(data_refs $upstream_head..) &&
for data in $data_refs; do
refspecs="+$data:$data $refspecs"
done
else
data_refs=''
fi
# Add a refspec to keep the remote master up to date if possible.
if test -z "$no_default" &&
base=$(git merge-base "$gitlab_head" "$upstream_head") &&
......@@ -136,6 +190,13 @@ if test "$push_exit" -ne 0 && test -z "$force" &&
Add "-f" or "--force" to push a rewritten topic.'
fi
# Check if data were pushed successfully.
for data in $data_refs; do
if echo "$push_stdout" | egrep-q "^[*=+] $data"; then
data_report_and_remove "$data"
fi
done
# Tell the user what to do next with the topic in GitLab.
if test -z "$no_topic" &&
test "$push_exit" -eq 0 &&
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment