diff --git a/bin/git-delete-submodule b/bin/git-delete-submodule index fee6aa9f6..a4ed08de9 100755 --- a/bin/git-delete-submodule +++ b/bin/git-delete-submodule @@ -2,12 +2,11 @@ submodule=$1 -test -z $submodule && echo "submodule required" 1>&2 && exit 1 +test -z "$submodule" && echo "submodule required" 1>&2 && exit 1 test ! -f .gitmodules && echo ".gitmodules file not found" 1>&2 && exit 2 +NAME="${submodule%/}" # remove tailing / +check_submodule_existence "$NAME" -NAME=$(echo $submodule | sed 's/\/$//g') -test -z $(git config --file=.gitmodules submodule.$NAME.url) && echo "submodule not found" 1>&2 && exit 3 - -git submodule deinit $NAME -git rm --cached $NAME -rm -rf .git/modules/$NAME +git submodule deinit "$NAME" +git rm --cached "$NAME" +rm -rf .git/modules/"$NAME" diff --git a/bin/git-pull-submodule b/bin/git-pull-submodule new file mode 100755 index 000000000..8083e6d2b --- /dev/null +++ b/bin/git-pull-submodule @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +pull_submodule() { + git submodule update --remote --recursive "${2:---merge}" "$1" +} + +while [ "$1" != "" ]; do + case $1 in + -m | --merge ) + procedure=--merge + ;; + -c | --checkout ) + procedure=--checkout + ;; + -r | --rebase ) + procedure=--rebase + ;; + * ) + submodule="$1" + ;; + esac + shift +done + +if [ "$submodule" == "" ] +then + pull_submodule "" "$procedure" # update all submodules +else + submodule="${submodule%/}" # remove tailing / + check_submodule_existence "$submodule" + pull_submodule "$submodule" "$procedure" +fi diff --git a/helper/git-extra-utility b/helper/git-extra-utility index 98ed09f4c..95bc1342d 100755 --- a/helper/git-extra-utility +++ b/helper/git-extra-utility @@ -5,3 +5,10 @@ git_extra_mktemp() { mktemp -t "$(basename "$0")".XXX } +check_submodule_existence() { + if test -z "$(git config --file=.gitmodules submodule."$1".url)" + then + echo "submodule $1 not found" 1>&2 + exit 3 + fi +} diff --git a/man/git-pull-submodule.1 b/man/git-pull-submodule.1 new file mode 100644 index 000000000..09a16643a --- /dev/null +++ b/man/git-pull-submodule.1 @@ -0,0 +1,58 @@ +.\" generated with Ronn/v0.7.3 +.\" http://github.com/rtomayko/ronn/tree/0.7.3 +. +.TH "GIT\-PULL\-SUBMODULE" "1" "June 2015" "" "" +. +.SH "NAME" +\fBgit\-pull\-submodule\fR \- Pull submodules +. +.SH "SYNOPSIS" +\fBgit\-pull\-submodule\fR [OPTIONS] [] +. +.SH "DESCRIPTION" +Pull submodule to latest version +. +.SH "OPTIONS" + +. +.P +The path of the submodule to pull\. If no path is given, all submodules will be pulled\. +. +.P +\-m, \-\-merge +. +.P +Merge the submodule\. It is the default one if no option is given\. +. +.P +\-c, \-\-checkout +. +.P +Checkout the submodule\. +. +.P +\-r, \-\-rebase +. +.P +Rebase the submodule\. +. +.SH "EXAMPLES" +. +.nf + +# checkout latest version of lib/abc +$ git pull\-submodule \-\-checkout lib/abc + +# merge latest version of lib/abc +$ git pull\-submodule lib/abc +. +.fi +. +.SH "AUTHOR" +Written by spacewander <\fIspacewanderlzx@gmail\.com\fR> +. +.SH "REPORTING BUGS" +<\fIhttps://github\.com/tj/git\-extras/issues\fR> +. +.SH "SEE ALSO" +<\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-pull-submodule.1.html b/man/git-pull-submodule.1.html new file mode 100644 index 000000000..6e4b9c17f --- /dev/null +++ b/man/git-pull-submodule.1.html @@ -0,0 +1,133 @@ + + + + + + git-pull-submodule(1) - Pull submodules + + + + +
+ + + +
    +
  1. git-pull-submodule(1)
  2. +
  3. +
  4. git-pull-submodule(1)
  5. +
+ +

NAME

+

+ git-pull-submodule - Pull submodules +

+ +

SYNOPSIS

+ +

git-pull-submodule [OPTIONS] [<path>]

+ +

DESCRIPTION

+ +

Pull submodule to latest version

+ +

OPTIONS

+ +

<path>

+ +

The path of the submodule to pull. If no path is given, all submodules will be pulled.

+ +

-m, --merge

+ +

Merge the submodule. It is the default one if no option is given.

+ +

-c, --checkout

+ +

Checkout the submodule.

+ +

-r, --rebase

+ +

Rebase the submodule.

+ +

EXAMPLES

+ +
# checkout latest version of lib/abc
+$ git pull-submodule --checkout lib/abc 
+
+# merge latest version of lib/abc
+$ git pull-submodule lib/abc
+
+ +

AUTHOR

+ +

Written by spacewander <spacewanderlzx@gmail.com>

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. June 2015
  3. +
  4. git-pull-submodule(1)
  5. +
+ +
+ + diff --git a/man/git-pull-submodule.md b/man/git-pull-submodule.md new file mode 100644 index 000000000..2f84ae7fd --- /dev/null +++ b/man/git-pull-submodule.md @@ -0,0 +1,49 @@ +git-pull-submodule(1) -- Pull submodules +============================================ + +## SYNOPSIS + +`git-pull-submodule` [OPTIONS] [<path>] + +## DESCRIPTION + +Pull submodule to latest version + +## OPTIONS + + <path> + + The path of the submodule to pull. If no path is given, all submodules will be pulled. + + -m, --merge + + Merge the submodule. It is the default one if no option is given. + + -c, --checkout + + Checkout the submodule. + + -r, --rebase + + Rebase the submodule. + +## EXAMPLES + + # checkout latest version of lib/abc + $ git pull-submodule --checkout lib/abc + + # merge latest version of lib/abc + $ git pull-submodule lib/abc + +## AUTHOR + +Written by spacewander <> + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> +