Merge branch 'jc/maint-checkout-keep-remove' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2008 02:53:22 +0000 (19:53 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2008 02:53:22 +0000 (19:53 -0700)
* jc/maint-checkout-keep-remove:
checkout: do not lose staged removal

1  2 
builtin-checkout.c
builtin-read-tree.c
diff --combined builtin-checkout.c
index 8e77767b49888aa2131088a810850dab7854594d,774f29992a967201d1d4f39e6d2a9993d11a8eb7..08c6d8614ae2b619f520616fecd45b24fd866732
@@@ -76,15 -76,6 +76,15 @@@ static int read_tree_some(struct tree *
        return 0;
  }
  
 +static int skip_same_name(struct cache_entry *ce, int pos)
 +{
 +      while (++pos < active_nr &&
 +             !strcmp(active_cache[pos]->name, ce->name))
 +              ; /* skip */
 +      return pos;
 +}
 +
 +
  static int checkout_paths(struct tree *source_tree, const char **pathspec)
  {
        int pos;
        if (report_path_error(ps_matched, pathspec, 0))
                return 1;
  
 +      /* Any unmerged paths? */
 +      for (pos = 0; pos < active_nr; pos++) {
 +              struct cache_entry *ce = active_cache[pos];
 +              if (pathspec_match(pathspec, NULL, ce->name, 0)) {
 +                      if (!ce_stage(ce))
 +                              continue;
 +                      errs = 1;
 +                      error("path '%s' is unmerged", ce->name);
 +                      pos = skip_same_name(ce, pos) - 1;
 +              }
 +      }
 +      if (errs)
 +              return 1;
 +
        /* Now we are committed to check them out */
        memset(&state, 0, sizeof(state));
        state.force = 1;
        for (pos = 0; pos < active_nr; pos++) {
                struct cache_entry *ce = active_cache[pos];
                if (pathspec_match(pathspec, NULL, ce->name, 0)) {
 -                      errs |= checkout_entry(ce, &state, NULL);
 +                      if (!ce_stage(ce)) {
 +                              errs |= checkout_entry(ce, &state, NULL);
 +                              continue;
 +                      }
 +                      pos = skip_same_name(ce, pos) - 1;
                }
        }
  
@@@ -269,6 -242,8 +269,8 @@@ static int merge_working_tree(struct ch
                }
  
                /* 2-way merge to the new branch */
+               topts.initial_checkout = (!active_nr &&
+                                         (old->commit == new->commit));
                topts.update = 1;
                topts.merge = 1;
                topts.gently = opts->merge;
diff --combined builtin-read-tree.c
index ac219ac2db3eafe8fc3363692e92fa7e1765138a,362216b272f36afc625c97501c34bac6be813eb0..0706c958181c54aeb18d91f6e3dbe7c9f572b94d
@@@ -64,7 -64,7 +64,7 @@@ static void prime_cache_tree(void
  
  }
  
 -static const char read_tree_usage[] = "git-read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
 +static const char read_tree_usage[] = "git read-tree (<sha> | [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u | -i]] [--exclude-per-directory=<gitignore>] [--index-output=<file>] <sha1> [<sha2> [<sha3>]])";
  
  static struct lock_file lock_file;
  
@@@ -206,6 -206,7 +206,7 @@@ int cmd_read_tree(int argc, const char 
                        break;
                case 2:
                        opts.fn = twoway_merge;
+                       opts.initial_checkout = !active_nr;
                        break;
                case 3:
                default: