Merge branch 'em/checkout-orphan'
authorJunio C Hamano <gitster@pobox.com>
Fri, 21 May 2010 11:02:14 +0000 (04:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 May 2010 11:02:14 +0000 (04:02 -0700)
* em/checkout-orphan:
git checkout: create unparented branch by --orphan

1  2 
builtin/checkout.c
diff --combined builtin/checkout.c
index 88b1f43e05e64f0e8dcd6dd0461bbebd6fab1e25,347927788b53031f0ada6bc3394940255637ad2c..c3825219c1efbd4939af6d18bcad6efcfa74f406
@@@ -33,6 -33,7 +33,7 @@@ struct checkout_opts 
        int writeout_error;
  
        const char *new_branch;
+       const char *new_orphan_branch;
        int new_branch_log;
        enum branch_track track;
  };
@@@ -149,7 -150,7 +150,7 @@@ static int checkout_merged(int pos, str
        read_mmblob(&ours, active_cache[pos+1]->sha1);
        read_mmblob(&theirs, active_cache[pos+2]->sha1);
  
 -      status = ll_merge(&result_buf, path, &ancestor,
 +      status = ll_merge(&result_buf, path, &ancestor, "base",
                          &ours, "ours", &theirs, "theirs", 0);
        free(ancestor.ptr);
        free(ours.ptr);
@@@ -439,7 -440,6 +440,7 @@@ static int merge_working_tree(struct ch
                        ret = reset_tree(new->commit->tree, opts, 1);
                        if (ret)
                                return ret;
 +                      o.ancestor = old->name;
                        o.branch1 = new->name;
                        o.branch2 = "local";
                        merge_trees(&o, new->commit->tree, work,
@@@ -492,8 -492,9 +493,9 @@@ static void update_refs_for_switch(stru
        struct strbuf msg = STRBUF_INIT;
        const char *old_desc;
        if (opts->new_branch) {
-               create_branch(old->name, opts->new_branch, new->name, 0,
-                             opts->new_branch_log, opts->track);
+               if (!opts->new_orphan_branch)
+                       create_branch(old->name, opts->new_branch, new->name, 0,
+                                     opts->new_branch_log, opts->track);
                new->name = opts->new_branch;
                setup_branch_path(new);
        }
@@@ -633,6 -634,7 +635,7 @@@ int cmd_checkout(int argc, const char *
                OPT_BOOLEAN('l', NULL, &opts.new_branch_log, "log for new branch"),
                OPT_SET_INT('t', "track",  &opts.track, "track",
                        BRANCH_TRACK_EXPLICIT),
+               OPT_STRING(0, "orphan", &opts.new_orphan_branch, "new branch", "new unparented branch"),
                OPT_SET_INT('2', "ours", &opts.writeout_stage, "stage",
                            2),
                OPT_SET_INT('3', "theirs", &opts.writeout_stage, "stage",
                opts.new_branch = argv0 + 1;
        }
  
+       if (opts.new_orphan_branch) {
+               if (opts.new_branch)
+                       die("--orphan and -b are mutually exclusive");
+               if (opts.track > 0 || opts.new_branch_log)
+                       die("--orphan cannot be used with -t or -l");
+               opts.new_branch = opts.new_orphan_branch;
+       }
        if (conflict_style) {
                opts.merge = 1; /* implied */
                git_xmerge_config("merge.conflictstyle", conflict_style, NULL);