]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/checkout.c
Merge branch 'en/merge-recursive-cleanup'
[thirdparty/git.git] / builtin / checkout.c
index 5e41fc1c018c745ea4593fc9c839721b92feebcb..3634a3dac15ae9deca30325ef5b19d5b3e250eb0 100644 (file)
@@ -126,6 +126,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
        if (pos >= 0) {
                struct cache_entry *old = active_cache[pos];
                if (ce->ce_mode == old->ce_mode &&
+                   !ce_intent_to_add(old) &&
                    oideq(&ce->oid, &old->oid)) {
                        old->ce_flags |= CE_UPDATE;
                        discard_cache_entry(ce);
@@ -730,13 +731,6 @@ static int merge_working_tree(const struct checkout_opts *opts,
                                      "the following files:\n%s"), sb.buf);
                        strbuf_release(&sb);
 
-                       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 */
 
                        /*
@@ -1720,6 +1714,15 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
        opts.checkout_index = -2;    /* default on */
        opts.checkout_worktree = -2; /* default on */
 
+       if (argc == 3 && !strcmp(argv[1], "-b")) {
+               /*
+                * User ran 'git checkout -b <branch>' and expects
+                * the same behavior as 'git switch -c <branch>'.
+                */
+               opts.switch_branch_doing_nothing_is_ok = 0;
+               opts.only_merge_on_switching_branches = 1;
+       }
+
        options = parse_options_dup(checkout_options);
        options = add_common_options(&opts, options);
        options = add_common_switch_branch_options(&opts, options);