# Copyright (c) 2007 Lars Hjemli
USAGE="[--quiet] [--cached] \
-[add <repo> [-b branch] <path>]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit <n>] [<commit>]] \
+[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit <n>] [<commit>]] \
[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
OPTIONS_SPEC=
. git-sh-setup
quiet=
cached=
nofetch=
+rebase=
#
# print stuff on stdout unless -q was specified
else
module_clone "$path" "$realrepo" || exit
- (unset GIT_DIR; cd "$path" && git checkout -f -q ${branch:+-b "$branch" "origin/$branch"}) ||
- die "Unable to checkout submodule '$path'"
+ (
+ unset GIT_DIR
+ cd "$path" &&
+ # ash fails to wordsplit ${branch:+-b "$branch"...}
+ case "$branch" in
+ '') git checkout -f -q ;;
+ ?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
+ esac
+ ) || die "Unable to checkout submodule '$path'"
fi
git add "$path" ||
git config submodule."$name".url "$url" ||
die "Failed to register url for submodule path '$path'"
+ test true != "$(git config -f .gitmodules --bool \
+ submodule."$name".rebase)" ||
+ git config submodule."$name".rebase true ||
+ die "Failed to register submodule path '$path' as rebasing"
+
say "Submodule '$name' ($url) registered for path '$path'"
done
}
shift
nofetch=1
;;
+ -r|--rebase)
+ shift
+ rebase=true
+ ;;
--)
shift
break
do
name=$(module_name "$path") || exit
url=$(git config submodule."$name".url)
+ rebase_module=$(git config --bool submodule."$name".rebase)
if test -z "$url"
then
# Only mention uninitialized submodules when its
die "Unable to find current revision in submodule path '$path'"
fi
+ if test true = "$rebase"
+ then
+ rebase_module=true
+ fi
+
if test "$subsha1" != "$sha1"
then
force=
die "Unable to fetch in submodule path '$path'"
fi
- (unset GIT_DIR; cd "$path" &&
- git-checkout $force -q "$sha1") ||
- die "Unable to checkout '$sha1' in submodule path '$path'"
+ if test true = "$rebase_module"
+ then
+ command="git-rebase"
+ action="rebase"
+ msg="rebased onto"
+ else
+ command="git-checkout $force -q"
+ action="checkout"
+ msg="checked out"
+ fi
- say "Submodule path '$path': checked out '$sha1'"
+ (unset GIT_DIR; cd "$path" && $command "$sha1") ||
+ die "Unable to $action '$sha1' in submodule path '$path'"
+ say "Submodule path '$path': $msg '$sha1'"
fi
done
}