Merge branch 'nd/checkout-m-doc-update'
authorJunio C Hamano <gitster@pobox.com>
Tue, 16 Apr 2019 10:28:10 +0000 (19:28 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Apr 2019 10:28:10 +0000 (19:28 +0900)
Doc about the above.

* nd/checkout-m-doc-update:
checkout.txt: note about losing staged changes with --merge

Documentation/git-checkout.txt
builtin/checkout.c
index f179b43732aa2a7e211a95889847294890c90d38..877e5f503a66145912886c14917f0e68512e6284 100644 (file)
@@ -242,6 +242,8 @@ should result in deletion of the path).
 +
 When checking out paths from the index, this option lets you recreate
 the conflicted merge in the specified paths.
++
+When switching branches with `--merge`, staged changes may be lost.
 
 --conflict=<style>::
        The same as --merge option above, but changes the way the
index 0e6037b2968f326ca2781fa141d74683e52c983c..f95e7975f7e970cf205c9e97c25296324477f249 100644 (file)
@@ -726,6 +726,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
                        struct tree *result;
                        struct tree *work;
                        struct merge_options o;
+                       struct strbuf sb = STRBUF_INIT;
+
                        if (!opts->merge)
                                return 1;
 
@@ -736,6 +738,13 @@ static int merge_working_tree(const struct checkout_opts *opts,
                        if (!old_branch_info->commit)
                                return 1;
 
+                       if (repo_index_has_changes(the_repository,
+                                                  get_commit_tree(old_branch_info->commit),
+                                                  &sb))
+                               warning(_("staged changes in the following files may be lost: %s"),
+                                       sb.buf);
+                       strbuf_release(&sb);
+
                        /* Do more real merge */
 
                        /*