]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'js/update-index-ignore-removal-for-skip-worktree'
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Nov 2019 09:02:16 +0000 (18:02 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Nov 2019 09:02:16 +0000 (18:02 +0900)
"git stash save" in a working tree that is sparsely checked out
mistakenly removed paths that are outside the area of interest.

* js/update-index-ignore-removal-for-skip-worktree:
  stash: handle staged changes in skip-worktree files correctly
  update-index: optionally leave skip-worktree entries alone

Documentation/git-update-index.txt
builtin/stash.c
builtin/update-index.c
git-legacy-stash.sh
t/t3903-stash.sh
t/t7012-skip-worktree-writing.sh

index 1c4d146a41ce091755b2e4baef0fa79f45a4b515..08393445e754d9dbbc5b387ad830343af4904c8b 100644 (file)
@@ -16,6 +16,7 @@ SYNOPSIS
             [--chmod=(+|-)x]
             [--[no-]assume-unchanged]
             [--[no-]skip-worktree]
+            [--[no-]ignore-skip-worktree-entries]
             [--[no-]fsmonitor-valid]
             [--ignore-submodules]
             [--[no-]split-index]
@@ -113,6 +114,11 @@ you will need to handle the situation manually.
        set and unset the "skip-worktree" bit for the paths. See
        section "Skip-worktree bit" below for more information.
 
+
+--[no-]ignore-skip-worktree-entries::
+       Do not remove skip-worktree (AKA "index-only") entries even when
+       the `--remove` option was specified.
+
 --[no-]fsmonitor-valid::
        When one of these flags is specified, the object name recorded
        for the paths are not updated. Instead, these options
index 4e806176b0828b65cf405492ca2cd2d157e3fc4a..d913487a43f913bc4ecb59c3f4739ee9b56ada79 100644 (file)
@@ -1088,8 +1088,9 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
        }
 
        cp_upd_index.git_cmd = 1;
-       argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add",
-                        "--remove", "--stdin", NULL);
+       argv_array_pushl(&cp_upd_index.args, "update-index",
+                        "--ignore-skip-worktree-entries",
+                        "-z", "--add", "--remove", "--stdin", NULL);
        argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s",
                         stash_index_path.buf);
 
index 49302d98c55d19651cacef7b36197de65d805e50..d527b8f1066859d79d746805c42bb73fab95e78c 100644 (file)
@@ -35,6 +35,7 @@ static int verbose;
 static int mark_valid_only;
 static int mark_skip_worktree_only;
 static int mark_fsmonitor_only;
+static int ignore_skip_worktree_entries;
 #define MARK_FLAG 1
 #define UNMARK_FLAG 2
 static struct strbuf mtime_dir = STRBUF_INIT;
@@ -381,7 +382,8 @@ static int process_path(const char *path, struct stat *st, int stat_errno)
                 * so updating it does not make sense.
                 * On the other hand, removing it from index should work
                 */
-               if (allow_remove && remove_file_from_cache(path))
+               if (!ignore_skip_worktree_entries && allow_remove &&
+                   remove_file_from_cache(path))
                        return error("%s: cannot remove from the index", path);
                return 0;
        }
@@ -1014,6 +1016,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                {OPTION_SET_INT, 0, "no-skip-worktree", &mark_skip_worktree_only, NULL,
                        N_("clear skip-worktree bit"),
                        PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, UNMARK_FLAG},
+               OPT_BOOL(0, "ignore-skip-worktree-entries", &ignore_skip_worktree_entries,
+                        N_("do not touch index-only entries")),
                OPT_SET_INT(0, "info-only", &info_only,
                        N_("add to index only; do not add content to object database"), 1),
                OPT_SET_INT(0, "force-remove", &force_remove,
index 07ad4a545910da5ff5a591c159da292d5101dec3..53fa5743018f19d8428f4a24379907bcbb6d80bf 100755 (executable)
@@ -193,7 +193,8 @@ create_stash () {
                        GIT_INDEX_FILE="$TMPindex" &&
                        export GIT_INDEX_FILE &&
                        git diff-index --name-only -z HEAD -- "$@" >"$TMP-stagenames" &&
-                       git update-index -z --add --remove --stdin <"$TMP-stagenames" &&
+                       git update-index --ignore-skip-worktree-entries \
+                               -z --add --remove --stdin <"$TMP-stagenames" &&
                        git write-tree &&
                        rm -f "$TMPindex"
                ) ) ||
index 580bfbdc23f4924cea78358629e09a974ad6aa6c..a4da72f0ab4453451309bbdbafd24a0eee423a88 100755 (executable)
@@ -1269,4 +1269,15 @@ test_expect_success 'stash apply should succeed with unmodified file' '
        git stash apply
 '
 
+test_expect_success 'stash handles skip-worktree entries nicely' '
+       test_commit A &&
+       echo changed >A.t &&
+       git add A.t &&
+       git update-index --skip-worktree A.t &&
+       rm A.t &&
+       git stash &&
+
+       git rev-parse --verify refs/stash:A.t
+'
+
 test_done
index 9d1abe50eff6772673df545d3e6715d4d2e6f2db..7476781979c3ff164ce9eeba1079d41f15bdaa5c 100755 (executable)
@@ -134,6 +134,21 @@ test_expect_success 'git-clean, dirty case' '
        test_i18ncmp expected result
 '
 
+test_expect_success '--ignore-skip-worktree-entries leaves worktree alone' '
+       test_commit keep-me &&
+       git update-index --skip-worktree keep-me.t &&
+       rm keep-me.t &&
+
+       : ignoring the worktree &&
+       git update-index --remove --ignore-skip-worktree-entries keep-me.t &&
+       git diff-index --cached --exit-code HEAD &&
+
+       : not ignoring the worktree, a deletion is staged &&
+       git update-index --remove keep-me.t &&
+       test_must_fail git diff-index --cached --exit-code HEAD \
+               --diff-filter=D -- keep-me.t
+'
+
 #TODO test_expect_failure 'git-apply adds file' false
 #TODO test_expect_failure 'git-apply updates file' false
 #TODO test_expect_failure 'git-apply removes file' false