Skip to content

Commit

Permalink
Merge branch 'jc/maint-checkout-keep-remove' into maint
Browse files Browse the repository at this point in the history
* jc/maint-checkout-keep-remove:
  checkout: do not lose staged removal
  • Loading branch information
gitster committed Sep 19, 2008
2 parents 01409bb + 5521883 commit 2ba3d5d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Documentation/git-read-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ Here are the "carry forward" rules:
0 nothing nothing nothing (does not happen)
1 nothing nothing exists use M
2 nothing exists nothing remove path from index
3 nothing exists exists use M
3 nothing exists exists, use M if "initial checkout"
H == M keep index otherwise
exists fail
H != M

clean I==H I==M
------------------
Expand Down Expand Up @@ -207,6 +210,12 @@ you picked it up via e-mail in a patch form), `git diff-index
merge, but it would not show in `git diff-index --cached $M`
output after two-tree merge.

Case #3 is slightly tricky and needs explanation. The result from this
rule logically should be to remove the path if the user staged the removal
of the path and then swiching to a new branch. That however will prevent
the initial checkout from happening, so the rule is modified to use M (new
tree) only when the contents of the index is empty. Otherwise the removal
of the path is kept as long as $H and $M are the same.

3-Way Merge
~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions builtin-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ static int merge_working_tree(struct checkout_opts *opts,
}

/* 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;
Expand Down
1 change: 1 addition & 0 deletions builtin-read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
break;
case 2:
opts.fn = twoway_merge;
opts.initial_checkout = !active_nr;
break;
case 3:
default:
Expand Down
11 changes: 10 additions & 1 deletion unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,8 +941,17 @@ int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
return -1;
}
}
else if (newtree)
else if (newtree) {
if (oldtree && !o->initial_checkout) {
/*
* deletion of the path was staged;
*/
if (same(oldtree, newtree))
return 1;
return reject_merge(oldtree, o);
}
return merged_entry(newtree, current, o);
}
return deleted_entry(oldtree, current, o);
}

Expand Down
1 change: 1 addition & 0 deletions unpack-trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct unpack_trees_options {
verbose_update:1,
aggressive:1,
skip_unmerged:1,
initial_checkout:1,
gently:1;
const char *prefix;
int pos;
Expand Down

0 comments on commit 2ba3d5d

Please sign in to comment.