MCPcopy Create free account
hub / github.com/git/git / require_clean_work_tree

Function require_clean_work_tree

wt-status.c:2683–2725  ·  view source on GitHub ↗

* If the work tree has unstaged or uncommitted changes, dies with the * appropriate message. */

Source from the content-addressed store, hash-verified

2681 * appropriate message.
2682 */
2683int require_clean_work_tree(struct repository *r,
2684 const char *action,
2685 const char *hint,
2686 int ignore_submodules,
2687 int gently)
2688{
2689 struct lock_file lock_file = LOCK_INIT;
2690 int err = 0, fd;
2691
2692 fd = repo_hold_locked_index(r, &lock_file, 0);
2693 refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
2694 if (0 <= fd)
2695 repo_update_index_if_able(r, &lock_file);
2696 rollback_lock_file(&lock_file);
2697
2698 if (has_unstaged_changes(r, ignore_submodules)) {
2699 /* TRANSLATORS: the action is e.g. "pull with rebase" */
2700 error(_("cannot %s: You have unstaged changes."), _(action));
2701 err = 1;
2702 }
2703
2704 if (has_uncommitted_changes(r, ignore_submodules)) {
2705 if (err)
2706 error(_("additionally, your index contains uncommitted changes."));
2707 else
2708 error(_("cannot %s: Your index contains uncommitted changes."),
2709 _(action));
2710 err = 1;
2711 }
2712
2713 if (err) {
2714 if (hint) {
2715 if (!*hint)
2716 BUG("empty hint passed to require_clean_work_tree();"
2717 " use NULL instead");
2718 error("%s", hint);
2719 }
2720 if (!gently)
2721 exit(128);
2722 }
2723
2724 return err;
2725}

Callers 4

do_execFunction · 0.85
complete_actionFunction · 0.85
cmd_rebaseFunction · 0.85
cmd_pullFunction · 0.85

Calls 7

repo_hold_locked_indexFunction · 0.85
refresh_indexFunction · 0.85
rollback_lock_fileFunction · 0.85
has_unstaged_changesFunction · 0.85
errorFunction · 0.85
has_uncommitted_changesFunction · 0.85

Tested by

no test coverage detected