Skip to content

Commit cd279e2

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 584f897 commit cd279e2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

entry.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ static int write_entry(struct cache_entry *ce,
208208
sub = submodule_from_ce(ce);
209209
if (sub)
210210
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);
212213
break;
213214
default:
214215
return error("unknown file mode for %s in index", path);
@@ -282,12 +283,11 @@ int checkout_entry(struct cache_entry *ce,
282283
unlink_or_warn(ce->name);
283284

284285
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);
287287
} else
288288
return submodule_move_head(ce->name,
289289
"HEAD", oid_to_hex(&ce->oid),
290-
SUBMODULE_MOVE_HEAD_FORCE);
290+
state->force ? SUBMODULE_MOVE_HEAD_FORCE : 0);
291291
}
292292

293293
if (!changed)

unpack-trees.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,18 @@ static int check_submodule_move_head(const struct cache_entry *ce,
252252
const char *new_id,
253253
struct unpack_trees_options *o)
254254
{
255+
unsigned flags = SUBMODULE_MOVE_HEAD_DRY_RUN;
255256
const struct submodule *sub = submodule_from_ce(ce);
256257
if (!sub)
257258
return 0;
258259

260+
if (o->reset)
261+
flags |= SUBMODULE_MOVE_HEAD_FORCE;
262+
259263
switch (sub->update_strategy.type) {
260264
case SM_UPDATE_UNSPECIFIED:
261265
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))
263267
return o->gently ? -1 :
264268
add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name);
265269
return 0;
@@ -308,6 +312,7 @@ static void unlink_entry(const struct cache_entry *ce)
308312
case SM_UPDATE_CHECKOUT:
309313
case SM_UPDATE_REBASE:
310314
case SM_UPDATE_MERGE:
315+
/* state.force is set at the caller. */
311316
submodule_move_head(ce->name, "HEAD", NULL,
312317
SUBMODULE_MOVE_HEAD_FORCE);
313318
break;

0 commit comments

Comments
 (0)