#define NO_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
+#include "repository.h"
+#include "config.h"
#include "dir.h"
#include "tree.h"
#include "tree-walk.h"
msgs[ERROR_BIND_OVERLAP] = _("Entry '%s' overlaps with '%s'. Cannot bind.");
msgs[ERROR_SPARSE_NOT_UPTODATE_FILE] =
- _("Cannot update sparse checkout: the following entries are not up-to-date:\n%s");
+ _("Cannot update sparse checkout: the following entries are not up to date:\n%s");
msgs[ERROR_WOULD_LOSE_ORPHANED_OVERWRITTEN] =
_("The following working tree files would be overwritten by sparse checkout update:\n%s");
msgs[ERROR_WOULD_LOSE_ORPHANED_REMOVED] =
const char *new_id,
struct unpack_trees_options *o)
{
+ unsigned flags = SUBMODULE_MOVE_HEAD_DRY_RUN;
const struct submodule *sub = submodule_from_ce(ce);
+
if (!sub)
return 0;
- switch (sub->update_strategy.type) {
- case SM_UPDATE_UNSPECIFIED:
- case SM_UPDATE_CHECKOUT:
- if (submodule_move_head(ce->name, old_id, new_id, SUBMODULE_MOVE_HEAD_DRY_RUN))
- return o->gently ? -1 :
- add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name);
- return 0;
- case SM_UPDATE_NONE:
- return 0;
- case SM_UPDATE_REBASE:
- case SM_UPDATE_MERGE:
- case SM_UPDATE_COMMAND:
- default:
- warning(_("submodule update strategy not supported for submodule '%s'"), ce->name);
- return -1;
- }
+ if (o->reset)
+ flags |= SUBMODULE_MOVE_HEAD_FORCE;
+
+ if (submodule_move_head(ce->name, old_id, new_id, flags))
+ return o->gently ? -1 :
+ add_rejected_path(o, ERROR_WOULD_LOSE_SUBMODULE, ce->name);
+ return 0;
}
-static void reload_gitmodules_file(struct index_state *index,
- struct checkout *state)
+/*
+ * Preform the loading of the repository's gitmodules file. This function is
+ * used by 'check_update()' to perform loading of the gitmodules file in two
+ * differnt situations:
+ * (1) before removing entries from the working tree if the gitmodules file has
+ * been marked for removal. This situation is specified by 'state' == NULL.
+ * (2) before checking out entries to the working tree if the gitmodules file
+ * has been marked for update. This situation is specified by 'state' != NULL.
+ */
+static void load_gitmodules_file(struct index_state *index,
+ struct checkout *state)
{
- int i;
- for (i = 0; i < index->cache_nr; i++) {
- struct cache_entry *ce = index->cache[i];
- if (ce->ce_flags & CE_UPDATE) {
- int r = strcmp(ce->name, ".gitmodules");
- if (r < 0)
- continue;
- else if (r == 0) {
- submodule_free();
- checkout_entry(ce, state, NULL);
- gitmodules_config();
- git_config(submodule_config, NULL);
- } else
- break;
+ int pos = index_name_pos(index, GITMODULES_FILE, strlen(GITMODULES_FILE));
+
+ if (pos >= 0) {
+ struct cache_entry *ce = index->cache[pos];
+ if (!state && ce->ce_flags & CE_WT_REMOVE) {
+ repo_read_gitmodules(the_repository);
+ } else if (state && (ce->ce_flags & CE_UPDATE)) {
+ submodule_free();
+ checkout_entry(ce, state, NULL);
+ repo_read_gitmodules(the_repository);
}
}
}
{
const struct submodule *sub = submodule_from_ce(ce);
if (sub) {
- switch (sub->update_strategy.type) {
- case SM_UPDATE_UNSPECIFIED:
- case SM_UPDATE_CHECKOUT:
- case SM_UPDATE_REBASE:
- case SM_UPDATE_MERGE:
- submodule_move_head(ce->name, "HEAD", NULL,
- SUBMODULE_MOVE_HEAD_FORCE);
- break;
- case SM_UPDATE_NONE:
- case SM_UPDATE_COMMAND:
- return; /* Do not touch the submodule. */
- }
+ /* state.force is set at the caller. */
+ submodule_move_head(ce->name, "HEAD", NULL,
+ SUBMODULE_MOVE_HEAD_FORCE);
}
if (!check_leading_path(ce->name, ce_namelen(ce)))
return;
total++;
}
- return start_progress_delay(_("Checking out files"),
- total, 50, 1);
+ return start_delayed_progress(_("Checking out files"), total);
}
static int check_updates(struct unpack_trees_options *o)
if (o->update)
git_attr_set_direction(GIT_ATTR_CHECKOUT, index);
+
+ if (should_update_submodules() && o->update && !o->dry_run)
+ load_gitmodules_file(index, NULL);
+
for (i = 0; i < index->cache_nr; i++) {
const struct cache_entry *ce = index->cache[i];
remove_scheduled_dirs();
if (should_update_submodules() && o->update && !o->dry_run)
- reload_gitmodules_file(index, &state);
+ load_gitmodules_file(index, &state);
+ enable_delayed_checkout(&state);
for (i = 0; i < index->cache_nr; i++) {
struct cache_entry *ce = index->cache[i];
}
}
stop_progress(&progress);
+ errs |= finish_delayed_checkout(&state);
if (o->update)
git_attr_set_direction(GIT_ATTR_CHECKIN, NULL);
return errs != 0;
else if (i > 1 && are_same_oid(&names[i], &names[i - 2]))
t[i] = t[i - 2];
else {
- const unsigned char *sha1 = NULL;
+ const struct object_id *oid = NULL;
if (dirmask & 1)
- sha1 = names[i].oid->hash;
- buf[nr_buf++] = fill_tree_descriptor(t+i, sha1);
+ oid = names[i].oid;
+ buf[nr_buf++] = fill_tree_descriptor(t + i, oid);
}
}
struct cache_entry **cache_end;
int dtype = DT_DIR;
int ret = is_excluded_from_list(prefix->buf, prefix->len,
- basename, &dtype, el);
+ basename, &dtype, el, &the_index);
int rc;
strbuf_addch(prefix, '/');
/* Non-directory */
dtype = ce_to_dtype(ce);
ret = is_excluded_from_list(ce->name, ce_namelen(ce),
- name, &dtype, el);
+ name, &dtype, el, &the_index);
if (ret < 0)
ret = defval;
if (ret > 0)
o->skip_sparse_checkout = 1;
if (!o->skip_sparse_checkout) {
char *sparse = git_pathdup("info/sparse-checkout");
- if (add_excludes_from_file_to_list(sparse, "", 0, &el, 0) < 0)
+ if (add_excludes_from_file_to_list(sparse, "", 0, &el, NULL) < 0)
o->skip_sparse_checkout = 1;
else
o->el = ⪙
WRITE_TREE_SILENT |
WRITE_TREE_REPAIR);
}
+ move_index_extensions(&o->result, o->dst_index);
discard_index(o->dst_index);
*o->dst_index = o->result;
} else {
memset(&d, 0, sizeof(d));
if (o->dir)
d.exclude_per_dir = o->dir->exclude_per_dir;
- i = read_directory(&d, pathbuf, namelen+1, NULL);
+ i = read_directory(&d, &the_index, pathbuf, namelen+1, NULL);
if (i)
return o->gently ? -1 :
add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name);
return 0;
if (o->dir &&
- is_excluded(o->dir, name, &dtype))
+ is_excluded(o->dir, &the_index, name, &dtype))
/*
* ce->name is explicitly excluded, so it is Ok to
* overwrite it.