From 9db31bdf5c834689c826f809d6d15bf7ab8d3598 Mon Sep 17 00:00:00 2001 From: Nicolas Morey-Chaisemartin Date: Fri, 1 Apr 2011 11:42:03 +0200 Subject: submodule: Add --force option for git submodule update 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' In order to reset a whole git submodule tree, a user has to run first 'git submodule foreach --recursive git checkout -f' and then 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 Acked-by: Jens Lehmann Signed-off-by: Junio C Hamano --- t/t7406-submodule-update.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 't') diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index fa9d23aa31..5d24d9ff74 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 -- cgit v1.2.3