|
#!/bin/sh
|
|
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
|
|
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
|
|
#
|
|
# Filename: bin/sde-update-manifest
|
|
# Copyright (C) 2010 The OpenSDE Project
|
|
#
|
|
# More information can be found in the files COPYING and README.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; version 2 of the License. A copy of the
|
|
# GNU General Public License can be found in the file COPYING.
|
|
# --- SDE-COPYRIGHT-NOTE-END ---
|
|
|
|
[ -n "$SDEROOT" ] ||
|
|
export SDEROOT="$(cd "${0%/*}/.."; pwd -P)"
|
|
|
|
. "$SDEROOT/lib/libsde.in"
|
|
|
|
WORKTREENAME="${SDEROOT##*/}"
|
|
MANIFEST="$SDEROOT/etc/manifest.ini"
|
|
|
|
manifest_update_git() {
|
|
local dir="$SDEROOT/$1" dirname="$WORKTREENAME/$1" GIT_DIR="$SDEROOT/$1/.git"
|
|
local repo="$2" branch="$3"
|
|
|
|
if [ -d "$GIT_DIR" ]; then
|
|
local cur=$(git --git-dir="$GIT_DIR" branch | grep ^* | cut -c3-)
|
|
local remote0=$(git --git-dir="$GIT_DIR" config --get "branch.$cur.remote")
|
|
local branch0=$(git --git-dir="$GIT_DIR" config --get "branch.$cur.merge" | cut -d/ -f3-)
|
|
local repo0=$(git --git-dir="$GIT_DIR" config --get "remote.$remote0.url")
|
|
|
|
if [ "${repo#git+}" = "${repo0#git+}" -a "$branch" = "$branch0" ]; then
|
|
# same repo, same branch... update
|
|
echo_info "$dirname:"
|
|
git "--work-tree=$dir" pull --rebase
|
|
elif ! git "--work-tree=$dir" update-index --ignore-submodules --refresh > /dev/null; then
|
|
# something different, but dirty working tree
|
|
if [ "${repo#git+}" != "${repo0#git+}" ]; then
|
|
echo_warning "$dirname: repo mismatch ($repo vs. $repo0)"
|
|
else
|
|
echo_warning "$dirname: branch mismatch ($branch vs. $branch0)"
|
|
fi
|
|
echo_error "$dirname: cannot continue: you have unstaged changes"
|
|
git "--work-tree=$dir" diff-files --name-status -r --ignore-submodules -- >&2
|
|
return 1
|
|
elif git "--git-dir=$GIT_DIR" branch | grep -q "^. $branch\$"; then
|
|
echo_info "$dirname: local branch $branch found"
|
|
git "--work-tree=$dir" checkout "$branch"
|
|
|
|
# check repo0 and branch0, and set if not tracking
|
|
remote0=$(git --git-dir="$GIT_DIR" config --get "branch.$branch.remote")
|
|
branch0=$(git --git-dir="$GIT_DIR" config --get "branch.$branch.merge" | cut -d/ -f3-)
|
|
|
|
if [ -z "$remote0" ]; then
|
|
|
|
repo0=$(git --git-dir="$GIT_DIR" config --get "remote.$remote0.url")
|
|
|
|
|
|
|
|
fi
|
|
elif [ "$branch" = master ]; then
|
|
echo_info "$dirname: cloning $repo"
|
|
git clone "$repo" "$dir"
|
|
else
|
|
echo_info "$dirname: cloning $repo ($branch)"
|
|
git clone "$repo" "$dir" &&
|
|
git "--work-tree=$dir" checkout --track -b "$branch" "origin/$branch"
|
|
fi
|
|
}
|
|
|
|
manifest_update_svn() {
|
|
local dir="$SDEROOT/$1" dirname="$1" repo="$2" path="$3" branch="$4"
|
|
local url="$repo$path"
|
|
if [ "$branch" = "trunk" ]; then
|
|
url="$url/$branch"
|
|
else
|
|
url="$url/branches/$branch"
|
|
fi
|
|
|
|
if [ -d "$dir/.svn" ]; then
|
|
echo_info "$dirname: updating..."
|
|
svn -N up "$dir"
|
|
else
|
|
echo_info "$1: <- $url"
|
|
svn co "$url" "$dir"
|
|
fi
|
|
}
|
|
|
|
manifest_update_custom() {
|
|
local dir="$1" repo="$3" arg1="$3" arg2="$4"
|
|
echo_info "$1 <-? $repo ($arg1, $arg2)"
|
|
}
|
|
|
|
|
|
while read d r a0 a1 x; do
|
|
case "${r%%:*}" in
|
|
git|git+ssh) manifest_update_git "$d" "$r" "$a0"
|
|
;;
|
|
svn|svn+ssh) manifest_update_svn "$d" "$r" "$a0" "$a1"
|
|
;;
|
|
*) manifest_update_custom "$d" "$r" "$a0" "$a1"
|
|
;;
|
|
esac
|
|
done < "$MANIFEST.scan"
|