Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'jc/maint-checkout-keep-remove' into maint

* jc/maint-checkout-keep-remove:
  checkout: do not lose staged removal
  • Loading branch information...
commit 2ba3d5d9bd47c42400049e81d0e1e94948112277 2 parents 01409bb + 5521883
Junio C Hamano authored September 18, 2008
11  Documentation/git-read-tree.txt
@@ -160,7 +160,10 @@ Here are the "carry forward" rules:
160 160
       0 nothing             nothing  nothing  (does not happen)
161 161
       1 nothing             nothing  exists   use M
162 162
       2 nothing             exists   nothing  remove path from index
163  
-      3 nothing             exists   exists   use M
  163
+      3 nothing             exists   exists,  use M if "initial checkout"
  164
+				     H == M   keep index otherwise
  165
+				     exists   fail
  166
+				     H != M
164 167
 
165 168
         clean I==H  I==M
166 169
        ------------------
@@ -207,6 +210,12 @@ you picked it up via e-mail in a patch form), `git diff-index
207 210
 merge, but it would not show in `git diff-index --cached $M`
208 211
 output after two-tree merge.
209 212
 
  213
+Case #3 is slightly tricky and needs explanation.  The result from this
  214
+rule logically should be to remove the path if the user staged the removal
  215
+of the path and then swiching to a new branch.  That however will prevent
  216
+the initial checkout from happening, so the rule is modified to use M (new
  217
+tree) only when the contents of the index is empty.  Otherwise the removal
  218
+of the path is kept as long as $H and $M are the same.
210 219
 
211 220
 3-Way Merge
212 221
 ~~~~~~~~~~~
2  builtin-checkout.c
@@ -269,6 +269,8 @@ static int merge_working_tree(struct checkout_opts *opts,
269 269
 		}
270 270
 
271 271
 		/* 2-way merge to the new branch */
  272
+		topts.initial_checkout = (!active_nr &&
  273
+					  (old->commit == new->commit));
272 274
 		topts.update = 1;
273 275
 		topts.merge = 1;
274 276
 		topts.gently = opts->merge;
1  builtin-read-tree.c
@@ -206,6 +206,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
206 206
 			break;
207 207
 		case 2:
208 208
 			opts.fn = twoway_merge;
  209
+			opts.initial_checkout = !active_nr;
209 210
 			break;
210 211
 		case 3:
211 212
 		default:
11  unpack-trees.c
@@ -941,8 +941,17 @@ int twoway_merge(struct cache_entry **src, struct unpack_trees_options *o)
941 941
 			return -1;
942 942
 		}
943 943
 	}
944  
-	else if (newtree)
  944
+	else if (newtree) {
  945
+		if (oldtree && !o->initial_checkout) {
  946
+			/*
  947
+			 * deletion of the path was staged;
  948
+			 */
  949
+			if (same(oldtree, newtree))
  950
+				return 1;
  951
+			return reject_merge(oldtree, o);
  952
+		}
945 953
 		return merged_entry(newtree, current, o);
  954
+	}
946 955
 	return deleted_entry(oldtree, current, o);
947 956
 }
948 957
 
1  unpack-trees.h
@@ -26,6 +26,7 @@ struct unpack_trees_options {
26 26
 		     verbose_update:1,
27 27
 		     aggressive:1,
28 28
 		     skip_unmerged:1,
  29
+		     initial_checkout:1,
29 30
 		     gently:1;
30 31
 	const char *prefix;
31 32
 	int pos;

0 notes on commit 2ba3d5d

Please sign in to comment.
Something went wrong with that request. Please try again.