static int error_dirty_index(struct replay_opts *opts) { if (read_cache_unmerged()) return error_resolve_conflict(_(action_name(opts))); error(_("your local changes would be overwritten by %s."), _(action_name(opts))); if (advice_commit_before_merge) advise(_("commit your changes or stash them to proceed.")); return -1; }
static NORETURN void die_dirty_index(const char *me) { if (read_cache_unmerged()) { die_resolve_conflict(me); } else { if (advice_commit_before_merge) die("Your local changes would be overwritten by %s.\n" "Please, commit your changes or stash them to proceed.", me); else die("Your local changes would be overwritten by %s.\n", me); } }
static int reset_index_file(const unsigned char *sha1, int reset_type, int quiet) { int nr = 1; int newfd; struct tree_desc desc[2]; struct unpack_trees_options opts; struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.src_index = &the_index; opts.dst_index = &the_index; opts.fn = oneway_merge; opts.merge = 1; if (!quiet) opts.verbose_update = 1; switch (reset_type) { case KEEP: case MERGE: opts.update = 1; break; case HARD: opts.update = 1; /* fallthrough */ default: opts.reset = 1; } newfd = hold_locked_index(lock, 1); read_cache_unmerged(); if (reset_type == KEEP) { unsigned char head_sha1[20]; if (get_sha1("HEAD", head_sha1)) return error(_("You do not have a valid HEAD.")); if (!fill_tree_descriptor(desc, head_sha1)) return error(_("Failed to find tree of HEAD.")); nr++; opts.fn = twoway_merge; } if (!fill_tree_descriptor(desc + nr - 1, sha1)) return error(_("Failed to find tree of %s."), sha1_to_hex(sha1)); if (unpack_trees(nr, desc, &opts)) return -1; if (write_cache(newfd, active_cache, active_nr) || commit_locked_index(lock)) return error(_("Could not write new index file.")); return 0; }
static int reset_index(const unsigned char *sha1, int reset_type, int quiet) { int nr = 1; struct tree_desc desc[2]; struct tree *tree; struct unpack_trees_options opts; memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.src_index = &the_index; opts.dst_index = &the_index; opts.fn = oneway_merge; opts.merge = 1; if (!quiet) opts.verbose_update = 1; switch (reset_type) { case KEEP: case MERGE: opts.update = 1; break; case HARD: opts.update = 1; /* fallthrough */ default: opts.reset = 1; } read_cache_unmerged(); if (reset_type == KEEP) { unsigned char head_sha1[20]; if (get_sha1("HEAD", head_sha1)) return error(_("You do not have a valid HEAD.")); if (!fill_tree_descriptor(desc, head_sha1)) return error(_("Failed to find tree of HEAD.")); nr++; opts.fn = twoway_merge; } if (!fill_tree_descriptor(desc + nr - 1, sha1)) return error(_("Failed to find tree of %s."), sha1_to_hex(sha1)); if (unpack_trees(nr, desc, &opts)) return -1; if (reset_type == MIXED || reset_type == HARD) { tree = parse_tree_indirect(sha1); prime_cache_tree(&active_cache_tree, tree); } return 0; }
static int error_dirty_index(struct replay_opts *opts) { if (read_cache_unmerged()) return error_resolve_conflict(action_name(opts)); /* Different translation strings for cherry-pick and revert */ if (opts->action == REPLAY_PICK) error(_("Your local changes would be overwritten by cherry-pick.")); else error(_("Your local changes would be overwritten by revert.")); if (advice_commit_before_merge) advise(_("Commit your changes or stash them to proceed.")); return -1; }