diff --git a/bin/sde-update-manifest b/bin/sde-update-manifest index a100953..b2539b8 100755 --- a/bin/sde-update-manifest +++ b/bin/sde-update-manifest @@ -18,28 +18,55 @@ . "$SDEROOT/lib/libsde.in" +WORKTREENAME="${SDEROOT##*/}" MANIFEST="$SDEROOT/etc/manifest.ini" manifest_update_git() { - local dir="$SDEROOT/$1" dirname="$1" GIT_DIR="$SDEROOT/$1/.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_DIR="$GIT_DIR" git branch | grep ^* | cut -c3-) - local remote0=$(GIT_DIR="$GIT_DIR" git config --get "branch.$cur.remote") - local branch0=$(GIT_DIR="$GIT_DIR" git config --get "branch.$cur.merge" | cut -d/ -f3-) - local repo0=$(GIT_DIR="$GIT_DIR" git config --get "remote.$remote0.url") - if [ "${repo#git+}" != "${repo0#git+}" ]; then - echo_warning "$dirname: repo mismatch ($repo vs. $repo0)" - elif [ "$branch" != "$branch0" ]; then - echo_warning "$dirname: branch mismatch ($branch vs. $branch0)" - else - echo_info "$dirname: updating..." - (cd "$dir"; git pull --rebase) + 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 clone "$repo" "$dir" && + git "--work-tree=$dir" checkout --track -b "$branch" "origin/$branch" fi } @@ -53,9 +80,10 @@ manifest_update_svn() { fi if [ -d "$dir/.svn" ]; then - echo_warning "$dirname: already exists" + echo_info "$dirname: updating..." + svn -N up "$dir" else - echo_info "$1 <- $url" + echo_info "$1: <- $url" svn co "$url" "$dir" fi }