# Copyright (c) 2007 Lars Hjemli
dashless=$(basename "$0" | sed -e 's/-/ /')
-USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
+USAGE="[--quiet] add [-b branch] [--local-branch[=<branch>]] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: $dashless [--quiet] init [--] [<path>...]
or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
command=
branch=
+local_branch=
+local_branch_empty=
force=
reference=
cached=
branch=$2
shift
;;
+ --local-branch)
+ local_branch_empty=true
+ ;;
+ --local-branch=*)
+ local_branch="${1#*=}"
+ ;;
-f | --force)
force=$1
;;
git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
die "$(eval_gettext "'\$sm_path' already exists in the index")"
+ if test -z "$local_branch" && test "$local_branch_empty" = "true"
+ then
+ local_branch="${branch:=HEAD}"
+ fi
+
if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
then
eval_gettextln "The following path is ignored by one of your .gitignore files:
git config -f .gitmodules submodule."$sm_path".path "$sm_path" &&
git config -f .gitmodules submodule."$sm_path".url "$repo" &&
+ if test -n "$local_branch"
+ then
+ git config -f .gitmodules submodule."$sm_path".branch "$local_branch"
+ fi &&
git add --force .gitmodules ||
die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
}
test -n "$(git config submodule."$name".update)" ||
git config submodule."$name".update "$upd" ||
die "$(eval_gettext "Failed to register update mode for submodule path '\$sm_path'")"
+
+ # Copy "branch" setting when it is not set yet
+ branch="$(git config -f .gitmodules submodule."$name".branch)"
+ test -z "$branch" ||
+ test -n "$(git config submodule."$name".branch)" ||
+ git config submodule."$name".branch "$branch" ||
+ die "$(eval_gettext "Failed to register branch for submodule path '\$sm_path'")"
done
}
done
# No command word defaults to "status"
-test -n "$command" || command=status
+if test -z "$command"
+then
+ if test $# = 0
+ then
+ command=status
+ else
+ usage
+ fi
+fi
# "-b branch" is accepted only by "add"
if test -n "$branch" && test "$command" != add