option to add all modules at once
This commit is contained in:
parent
3653671369
commit
abff01a7fe
@ -1,13 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
allatonce=
|
||||||
pushurl="gitea@gitea.opensuse.org:lnussel/core.git"
|
pushurl="gitea@gitea.opensuse.org:lnussel/core.git"
|
||||||
prsrcusr="lnussel"
|
prsrcusr="lnussel"
|
||||||
prtarget="https://gitea.opensuse.org/api/v1/repos/mold/core/pulls"
|
prtarget="https://gitea.opensuse.org/api/v1/repos/mold/core/pulls"
|
||||||
|
|
||||||
|
if [ "$1" = '--allatonce' ]; then
|
||||||
|
allatonce=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
modules=($@)
|
modules=($@)
|
||||||
origin="$(git config --get remote.origin.url)"
|
origin="$(git config --get remote.origin.url)"
|
||||||
#now="$(date "+%s %z")"
|
now="$(date "+%s %z")"
|
||||||
# FIXME: hardcoded to avoid changing commits for now
|
# FIXME: hardcoded to avoid changing commits for now
|
||||||
now="1668592380 +0100"
|
now="$(stat -c %Y token) +0100"
|
||||||
export GIT_AUTHOR_NAME="Auto"
|
export GIT_AUTHOR_NAME="Auto"
|
||||||
export GIT_AUTHOR_EMAIL="auto@suse.de"
|
export GIT_AUTHOR_EMAIL="auto@suse.de"
|
||||||
export GIT_AUTHOR_DATE="$now"
|
export GIT_AUTHOR_DATE="$now"
|
||||||
@ -22,43 +28,57 @@ cleanup()
|
|||||||
}
|
}
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
read token < token || exit 1
|
read -r token < token || exit 1
|
||||||
|
|
||||||
|
# read all submodules
|
||||||
declare -A revs
|
declare -A revs
|
||||||
while read m t cid p; do
|
while read -r m t cid p; do
|
||||||
[ "$t" = "commit" ] || continue
|
[ "$t" = "commit" ] || continue
|
||||||
revs["$p"]="$cid"
|
revs["$p"]="$cid"
|
||||||
done < <(git cat-file -p HEAD^{tree})
|
done < <(git cat-file -p "HEAD^{tree}")
|
||||||
|
|
||||||
if [ -z "$modules" ]; then
|
if [ -z "$modules" ]; then
|
||||||
modules=("${!revs[@]}")
|
modules=("${!revs[@]}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check remotes for updates
|
||||||
declare -A commits
|
declare -A commits
|
||||||
|
treetext=$(git cat-file -p "HEAD^{tree}")
|
||||||
for m in "${modules[@]}"; do
|
for m in "${modules[@]}"; do
|
||||||
path="$(git config -f .gitmodules --get "submodule.$m.path")"
|
path="$(git config -f .gitmodules --get "submodule.$m.path")"
|
||||||
url="$(git config -f .gitmodules --get "submodule.$m.url")"
|
url="$(git config -f .gitmodules --get "submodule.$m.url")"
|
||||||
branch="$(git config -f .gitmodules --get "submodule.$m.branch")"
|
branch="$(git config -f .gitmodules --get "submodule.$m.branch")"
|
||||||
if [ -z "$path" -o -z "$url" ]; then
|
if [ -z "$path" ] || [ -z "$url" ]; then
|
||||||
echo "$m unknown" >&2
|
echo "$m unknown" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
if [ "${url:0:3}" = '../' ]; then
|
if [ "${url:0:3}" = '../' ]; then
|
||||||
url="$origin/$url"
|
url="$origin/$url"
|
||||||
fi
|
fi
|
||||||
read cid _d < <(git ls-remote "$url" "${branch:-HEAD}")
|
read -r cid _d < <(git ls-remote "$url" "${branch:-HEAD}")
|
||||||
if [ -z "${revs[$path]}" ]; then
|
if [ -z "${revs[$path]}" ]; then
|
||||||
echo "$path unknown" >&2
|
echo "$path unknown" >&2
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
# create a new commit for this package
|
||||||
if [ "${revs[$path]}" != "$cid" ]; then
|
if [ "${revs[$path]}" != "$cid" ]; then
|
||||||
echo "Needs update: $path@${revs[$path]} -> $cid"
|
echo "Needs update: $path@${revs[$path]} -> $cid"
|
||||||
newtree="$(git cat-file -p HEAD^{tree} | sed -e "s/${revs[$path]}\t$path/$cid\t$path/" | git mktree)"
|
if [ "$allatonce" = 1 ]; then
|
||||||
|
treetext="${treetext/${revs[$path]} $path/$cid $path}"
|
||||||
|
else
|
||||||
|
newtree="$(git cat-file -p "HEAD^{tree}" | sed -e "s/${revs[$path]}\t$path/$cid\t$path/" | git mktree)"
|
||||||
newcid="$(git commit-tree -p HEAD -m "Update $m" "$newtree")"
|
newcid="$(git commit-tree -p HEAD -m "Update $m" "$newtree")"
|
||||||
commits["$m"]="$newcid"
|
commits["$m"]="$newcid"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [ "$allatonce" = 1 ]; then
|
||||||
|
newtree="$(echo "$treetext" | git mktree)"
|
||||||
|
newcid="$(git commit-tree -p HEAD -m "Update all" "$newtree")"
|
||||||
|
commits["all"]="$newcid"
|
||||||
|
fi
|
||||||
|
|
||||||
for m in "${!commits[@]}"; do
|
for m in "${!commits[@]}"; do
|
||||||
if git send-pack --force "$pushurl" "${commits[$m]}:refs/heads/update_$m"; then
|
if git send-pack --force "$pushurl" "${commits[$m]}:refs/heads/update_$m"; then
|
||||||
#https://github.com/go-gitea/gitea/issues/18842
|
#https://github.com/go-gitea/gitea/issues/18842
|
||||||
|
Loading…
x
Reference in New Issue
Block a user