From: Jens Lehmann <Jens.Lehmann@web.de>
To: Nicolas Morey-Chaisemartin <nmorey@kalray.eu>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2] submodule: Add --force option for git submodule update
Date: Sun, 03 Apr 2011 21:21:58 +0200 [thread overview]
Message-ID: <4D98C8D6.3050406@web.de> (raw)
In-Reply-To: <4D959DEB.3010206@kalray.eu>
Am 01.04.2011 11:42, schrieb Nicolas Morey-Chaisemartin:
> By default git submodule update runs a simple checkout on submodules
> that are not up-to-date.
> If the submodules contains modified or untracked files, the command may
> exit sanely with an error:
>
> $ git submodule update
> error: Your local changes to the following files would be overwritten by
> checkout:
> file
> Please, commit your changes or stash them before you can switch branches.
> Aborting
> Unable to checkout '1b69c6e55606b48d3284a3a9efe4b58bfb7e8c9e' in
> submodule path 'test1'
>
> This implies that to reset a whole git submodule tree, a user has to run
> first 'git submodule foreach --recursive git checkout -f' to then be
> able to run git submodule update.
>
> This patch adds a --force option for the update command (only used for
> submodules without --rebase or --merge options). It passes the --force
> option to git checkout which will throw away the local changes.
>
> Signed-off-by: Nicolas Morey-Chaisemartin <nmorey@kalray.eu>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
> ---
>
> Much less intrusive patch that only adds the --force option but do not
> add unnecessary checkouts to throw away *all* the changes
>
> Documentation/git-submodule.txt | 6 ++++--
> git-submodule.sh | 14 +++++++++-----
> t/t7406-submodule-update.sh | 23 +++++++++++++++++++++++
> 3 files changed, 36 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
> index 3a5aa01..328bdad 100644
> --- a/Documentation/git-submodule.txt
> +++ b/Documentation/git-submodule.txt
> @@ -185,8 +185,10 @@ OPTIONS
>
> -f::
> --force::
> - This option is only valid for the add command.
> - Allow adding an otherwise ignored submodule path.
> + This option is only valid for add and update commands.
> + When running add, allow adding an otherwise ignored submodule path.
> + When running update, throw away local changes in submodules when
> + switching to a different commit.
>
> --cached::
> This option is only valid for status and summary commands. These
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 3a13397..f732709 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -8,7 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /')
> USAGE="[--quiet] add [-b 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] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<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>...]"
> @@ -385,6 +385,9 @@ cmd_update()
> -N|--no-fetch)
> nofetch=1
> ;;
> + -f|--force)
> + force=$1
> + ;;
> -r|--rebase)
> update="rebase"
> ;;
> @@ -458,10 +461,11 @@ cmd_update()
>
> if test "$subsha1" != "$sha1"
> then
> - force=
> - if test -z "$subsha1"
> + subforce=$force
> + # If we don't already have a -f flag and the submodule has never been checked out
> + if test -z "$subsha1" -a -z "$force"
> then
> - force="-f"
> + subforce="-f"
> fi
>
> if test -z "$nofetch"
> @@ -490,7 +494,7 @@ cmd_update()
> msg="merged in"
> ;;
> *)
> - command="git checkout $force -q"
> + command="git checkout $subforce -q"
> action="checkout"
> msg="checked out"
> ;;
> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
> index fa9d23a..5d24d9f 100755
> --- a/t/t7406-submodule-update.sh
> +++ b/t/t7406-submodule-update.sh
> @@ -74,6 +74,29 @@ test_expect_success 'submodule update detaching the HEAD ' '
> )
> '
>
> +test_expect_success 'submodule update should fail due to local changes' '
> + (cd super/submodule &&
> + git reset --hard HEAD~1 &&
> + echo "local change" > file
> + ) &&
> + (cd super &&
> + (cd submodule &&
> + compare_head
> + ) &&
> + test_must_fail git submodule update submodule
> + )
> +'
> +test_expect_success 'submodule update should throw away changes with --force ' '
> + (cd super &&
> + (cd submodule &&
> + compare_head
> + ) &&
> + git submodule update --force submodule &&
> + cd submodule &&
> + ! compare_head
> + )
> +'
> +
> test_expect_success 'submodule update --rebase staying on master' '
> (cd super/submodule &&
> git checkout master
prev parent reply other threads:[~2011-04-03 19:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-01 9:42 [PATCH v2] submodule: Add --force option for git submodule update Nicolas Morey-Chaisemartin
2011-04-03 19:21 ` Jens Lehmann [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D98C8D6.3050406@web.de \
--to=jens.lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=nmorey@kalray.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).