entry.c: submodule recursing: respect force flag correctly
In case of a non-forced worktree update, the submodule movement is tested in a dry run first, such that it doesn't matter if the actual update is done via the force flag. However for correctness, we want to give the flag as specified by the user. All callers have been inspected and updated if needed. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Apr 18, 2017 at 14:37 UTC
cd279e2e1b4f41f0272d90abb2ba5a06c544b3da
2 files changed
+10
-5
entry.c
+4
-4
@@ -208,7 +208,8 @@ static int write_entry(struct cache_entry *ce,
208
sub = submodule_from_ce(ce);
209
if (sub)
210
return submodule_move_head(ce->name,
211
- NULL, oid_to_hex(&ce->oid), SUBMODULE_MOVE_HEAD_FORCE);
211
+ NULL, oid_to_hex(&ce->oid),
212
+ state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0);
213
break;
214
default:
215
return error("unknown file mode for %s in index", path);
@@ -282,12 +283,11 @@ int checkout_entry(struct cache_entry *ce,
283
unlink_or_warn(ce->name);
284
285
return submodule_move_head(ce->name,
285
- NULL, oid_to_hex(&ce->oid),
286
- SUBMODULE_MOVE_HEAD_FORCE);
286
+ NULL, oid_to_hex(&ce->oid), 0);
287
} else
288
return submodule_move_head(ce->name,
289
"HEAD", oid_to_hex(&ce->oid),
290
- SUBMODULE_MOVE_HEAD_FORCE);
290
+ state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0);
291
}
292
293
if (!changed)
unpack-trees.c
+6
-1
@@ -252,14 +252,18 @@ static int check_submodule_move_head(const struct cache_entry *ce,
252
const char *new_id,
253
struct unpack_trees_options *o)
254
{
255
+ unsigned flags = SUBMODULE_MOVE_HEAD_DRY_RUN;
256
const struct submodule *sub = submodule_from_ce(ce);
257
if (!sub)
258
return 0;
259
260
+ if (o->reset)
261
+ flags |= SUBMODULE_MOVE_HEAD_FORCE;
262
+
263
switch (sub->update_strategy.type) {
264
case SM_UPDATE_UNSPECIFIED:
265
case SM_UPDATE_CHECKOUT:
262
- if (submodule_move_head(ce->name, old_id, new_id, SUBMODULE_MOVE_HEAD_DRY_RUN))
266
+ if (submodule_move_head(ce->name, old_id, new_id, flags))
267
return o->gently ? -1 :
268
add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name);
269
return 0;
@@ -308,6 +312,7 @@ static void unlink_entry(const struct cache_entry *ce)
312
case SM_UPDATE_CHECKOUT:
313
case SM_UPDATE_REBASE:
314
case SM_UPDATE_MERGE:
315
+ /* state.force is set at the caller. */
316
submodule_move_head(ce->name, "HEAD", NULL,
317
SUBMODULE_MOVE_HEAD_FORCE);
318
break;