Merge branch 'wtk/submodule-doc-fixup'
authorJunio C Hamano <gitster@pobox.com>
Wed, 21 Nov 2012 21:25:42 +0000 (13:25 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Nov 2012 21:25:42 +0000 (13:25 -0800)
* wtk/submodule-doc-fixup:
git-submodule: wrap branch option with "<>" in usage strings.

1  2 
Documentation/git-submodule.txt
git-submodule.sh
index 1d6527ab9f46fb0eb5d52ef335c1c4b4c377a72b,a65f38e18427c0b87854181c45e49a7bd226e63a..b1de3bade751f34b9629e3d4c0d8f654fca86a91
@@@ -9,7 -9,7 +9,7 @@@ git-submodule - Initialize, update or i
  SYNOPSIS
  --------
  [verse]
- 'git submodule' [--quiet] add [-b branch] [-f|--force] [--name <name>]
 -'git submodule' [--quiet] add [-b <branch>] [-f|--force]
++'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]
              [--reference <repository>] [--] <repository> [<path>]
  'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
  'git submodule' [--quiet] init [--] [<path>...]
@@@ -265,11 -265,6 +265,11 @@@ OPTION
        Initialize all submodules for which "git submodule init" has not been
        called so far before updating.
  
 +--name::
 +      This option is only valid for the add command. It sets the submodule's
 +      name to the given string instead of defaulting to its path. The name
 +      must be valid as a directory name and may not end with a '/'.
 +
  --reference <repository>::
        This option is only valid for add and update commands.  These
        commands sometimes need to clone a remote repository. In this case,
diff --combined git-submodule.sh
index 0522c3871a55d50cdada04c92db8d4bd87120df7,02f82e9ed53c2184113752fa5768e706cf228e1a..2365149d0b920ece4d076dafbebf23fef6888df1
@@@ -5,13 -5,13 +5,13 @@@
  # Copyright (c) 2007 Lars Hjemli
  
  dashless=$(basename "$0" | sed -e 's/-/ /')
- USAGE="[--quiet] add [-b branch] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
 -USAGE="[--quiet] add [-b <branch>] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
++USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--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>...]
     or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
     or: $dashless [--quiet] foreach [--recursive] <command>
 -   or: $dashless [--quiet] sync [--] [<path>...]"
 +   or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
  OPTIONS_SPEC=
  . git-sh-setup
  . git-sh-i18n
@@@ -29,7 -29,6 +29,7 @@@ files
  nofetch=
  update=
  prefix=
 +custom_name=
  
  # The function takes at most 2 arguments. The first argument is the
  # URL that navigates to the submodule origin repo. When relative, this URL
@@@ -180,9 -179,8 +180,9 @@@ module_name(
  module_clone()
  {
        sm_path=$1
 -      url=$2
 -      reference="$3"
 +      name=$2
 +      url=$3
 +      reference="$4"
        quiet=
        if test -n "$GIT_QUIET"
        then
  
        gitdir=
        gitdir_base=
 -      name=$(module_name "$sm_path" 2>/dev/null)
 -      test -n "$name" || name="$sm_path"
        base_name=$(dirname "$name")
  
        gitdir=$(git rev-parse --git-dir)
@@@ -270,10 -270,6 +270,10 @@@ cmd_add(
                        ;;
                --reference=*)
                        reference="$1"
 +                      ;;
 +              --name)
 +                      case "$2" in '') usage ;; esac
 +                      custom_name=$2
                        shift
                        ;;
                --)
@@@ -340,13 -336,6 +340,13 @@@ Use -f if you really want to add it." >
                exit 1
        fi
  
 +      if test -n "$custom_name"
 +      then
 +              sm_name="$custom_name"
 +      else
 +              sm_name="$sm_path"
 +      fi
 +
        # perhaps the path exists and is already a git repo, else clone it
        if test -e "$sm_path"
        then
                fi
  
        else
 -
 -              module_clone "$sm_path" "$realrepo" "$reference" || exit
 +              if test -d ".git/modules/$sm_name"
 +              then
 +                      if test -z "$force"
 +                      then
 +                              echo >&2 "$(eval_gettext "A git directory for '\$sm_name' is found locally with remote(s):")"
 +                              GIT_DIR=".git/modules/$sm_name" GIT_WORK_TREE=. git remote -v | grep '(fetch)' | sed -e s,^,"  ", -e s,' (fetch)',, >&2
 +                              echo >&2 "$(eval_gettext "If you want to reuse this local git directory instead of cloning again from")"
 +                              echo >&2 "  $realrepo"
 +                              echo >&2 "$(eval_gettext "use the '--force' option. If the local git directory is not the correct repo")"
 +                              die "$(eval_gettext "or you are unsure what this means choose another name with the '--name' option.")"
 +                      else
 +                              echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
 +                      fi
 +              fi
 +              module_clone "$sm_path" "$sm_name" "$realrepo" "$reference" || exit
                (
                        clear_local_git_env
                        cd "$sm_path" &&
                        esac
                ) || die "$(eval_gettext "Unable to checkout submodule '\$sm_path'")"
        fi
 -      git config submodule."$sm_path".url "$realrepo"
 +      git config submodule."$sm_name".url "$realrepo"
  
        git add $force "$sm_path" ||
        die "$(eval_gettext "Failed to add submodule '\$sm_path'")"
  
 -      git config -f .gitmodules submodule."$sm_path".path "$sm_path" &&
 -      git config -f .gitmodules submodule."$sm_path".url "$repo" &&
 +      git config -f .gitmodules submodule."$sm_name".path "$sm_path" &&
 +      git config -f .gitmodules submodule."$sm_name".url "$repo" &&
        git add --force .gitmodules ||
        die "$(eval_gettext "Failed to register submodule '\$sm_path'")"
  }
@@@ -618,7 -594,7 +618,7 @@@ Maybe you want to use 'update --init'?"
  
                if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
                then
 -                      module_clone "$sm_path" "$url" "$reference"|| exit
 +                      module_clone "$sm_path" "$name" "$url" "$reference" || exit
                        cloned_modules="$cloned_modules;$name"
                        subsha1=
                else
@@@ -950,6 -926,7 +950,6 @@@ cmd_summary() 
  cmd_status()
  {
        # parse $args after "submodule ... status".
 -      orig_flags=
        while test $# -ne 0
        do
                case "$1" in
                        break
                        ;;
                esac
 -              orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
                shift
        done
  
                                prefix="$displaypath/"
                                clear_local_git_env
                                cd "$sm_path" &&
 -                              eval cmd_status "$orig_args"
 +                              eval cmd_status
                        ) ||
                        die "$(eval_gettext "Failed to recurse into submodule path '\$sm_path'")"
                fi
@@@ -1032,10 -1010,6 +1032,10 @@@ cmd_sync(
                        GIT_QUIET=1
                        shift
                        ;;
 +              --recursive)
 +                      recursive=1
 +                      shift
 +                      ;;
                --)
                        shift
                        break
  
                if git config "submodule.$name.url" >/dev/null 2>/dev/null
                then
 -                      say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
 +                      say "$(eval_gettext "Synchronizing submodule url for '\$prefix\$sm_path'")"
                        git config submodule."$name".url "$super_config_url"
  
                        if test -e "$sm_path"/.git
                                cd "$sm_path"
                                remote=$(get_default_remote)
                                git config remote."$remote".url "$sub_origin_url"
 +
 +                              if test -n "$recursive"
 +                              then
 +                                      prefix="$prefix$sm_path/"
 +                                      eval cmd_sync
 +                              fi
                        )
                        fi
                fi