From: Jens Lehmann Date: Fri, 06 May 2011 22:12:18 GMT Subject: [PATCH] Teach checkout the -n|--dry-run option Message-ID: <4DC47242.6060205@web.de> This option can be used to determine if checking out a branch or commit would touch files which are modified in the work tree. It doesn't change the work tree contents or the index, so it can only tell if the checkout would succeed using trivial merges. It can neither be used when checking out only certain paths nor together with the '-m' option. Signed-off-by: Jens Lehmann --- This is a repost of a RFC patch from Sep 04, 2010 I did not receive any responses upon: I need this new option for the recursive submodule checkout. Denying a checkout inside a submodule just because it has modifications is a too limiting condition (and it is way too expensive to check the whole tree, just looking at those paths going to be changed by the checkout should be much faster, especially for large submodules). IMO the same behavior that applies for a checkout in the superproject should apply for the checkout inside the submodule: no local changes may be overwritten by the checkout (and the HEAD must match the commit recorded in the superproject, but that is handled elsewhere). To be able to test that, I added the -n|--dry-run option to checkout. I think I found all relevant places, but a few more eyeballs are highly appreciated as I am not very familiar with this part of the code. A thing I'm not so sure about is the output of show_local_changes(), with -n it doesn't show the changes as they would have been *after* the - not executed - checkout but *without* having done it. Is that a problem here? Documentation/git-checkout.txt | 15 ++++++++++++--- builtin/checkout.c | 20 +++++++++++++++----- t/t2018-checkout-branch.sh | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 1063f69..ae58762 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -8,9 +8,9 @@ git-checkout - Checkout a branch or paths to the working tree SYNOPSIS -------- [verse] -'git checkout' [-q] [-f] [-m] [] -'git checkout' [-q] [-f] [-m] [--detach] [] -'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] ] [] +'git checkout' [-q] [-f] [-m|-n] [] +'git checkout' [-q] [-f] [-m|-n] [--detach] [] +'git checkout' [-q] [-f] [-m|-n] [[-b|-B|--orphan] ] [] 'git checkout' [-f|--ours|--theirs|-m|--conflict=