|
2 | 2 | #include "blob.h"
|
3 | 3 | #include "dir.h"
|
4 | 4 | #include "streaming.h"
|
| 5 | +#include "submodule.h" |
5 | 6 |
|
6 | 7 | static void create_directories(const char *path, int path_len,
|
7 | 8 | const struct checkout *state)
|
@@ -146,6 +147,7 @@ static int write_entry(struct cache_entry *ce,
|
146 | 147 | unsigned long size;
|
147 | 148 | size_t wrote, newsize = 0;
|
148 | 149 | struct stat st;
|
| 150 | + const struct submodule *sub; |
149 | 151 |
|
150 | 152 | if (ce_mode_s_ifmt == S_IFREG) {
|
151 | 153 | struct stream_filter *filter = get_stream_filter(ce->name,
|
@@ -203,6 +205,10 @@ static int write_entry(struct cache_entry *ce,
|
203 | 205 | return error("cannot create temporary submodule %s", path);
|
204 | 206 | if (mkdir(path, 0777) < 0)
|
205 | 207 | return error("cannot create submodule directory %s", path);
|
| 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); |
206 | 212 | break;
|
207 | 213 | default:
|
208 | 214 | return error("unknown file mode for %s in index", path);
|
@@ -259,7 +265,31 @@ int checkout_entry(struct cache_entry *ce,
|
259 | 265 | strbuf_add(&path, ce->name, ce_namelen(ce));
|
260 | 266 |
|
261 | 267 | if (!check_path(path.buf, path.len, &st, state->base_dir_len)) {
|
| 268 | + const struct submodule *sub; |
262 | 269 | unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
|
| 270 | + /* |
| 271 | + * Needs to be checked before !changed returns early, |
| 272 | + * as the possibly empty directory was not changed |
| 273 | + */ |
| 274 | + sub = submodule_from_ce(ce); |
| 275 | + if (sub) { |
| 276 | + int err; |
| 277 | + if (!is_submodule_populated_gently(ce->name, &err)) { |
| 278 | + struct stat sb; |
| 279 | + if (lstat(ce->name, &sb)) |
| 280 | + die(_("could not stat file '%s'"), ce->name); |
| 281 | + if (!(st.st_mode & S_IFDIR)) |
| 282 | + unlink_or_warn(ce->name); |
| 283 | + |
| 284 | + return submodule_move_head(ce->name, |
| 285 | + NULL, oid_to_hex(&ce->oid), |
| 286 | + SUBMODULE_MOVE_HEAD_FORCE); |
| 287 | + } else |
| 288 | + return submodule_move_head(ce->name, |
| 289 | + "HEAD", oid_to_hex(&ce->oid), |
| 290 | + SUBMODULE_MOVE_HEAD_FORCE); |
| 291 | + } |
| 292 | + |
263 | 293 | if (!changed)
|
264 | 294 | return 0;
|
265 | 295 | if (!state->force) {
|
|
0 commit comments