Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenton Liu <liu.denton@gmail.com>2021-03-03 14:16:42 +0300
committerJunio C Hamano <gitster@pobox.com>2021-03-06 01:31:26 +0300
commitd3c7bf73bdb679dd98c6aff65edbce4df743ddd3 (patch)
tree7e4757674006ff07cfe29906afdc6bb8f0ec8aea /t/t3905-stash-include-untracked.sh
parent3e885f02775dad0d907d447bc3c24fa07870b41f (diff)
stash show: teach --include-untracked and --only-untracked
Stash entries can be made with untracked files via `git stash push --include-untracked`. However, because the untracked files are stored in the third parent of the stash entry and not the stash entry itself, running `git stash show` does not include the untracked files as part of the diff. With --include-untracked, untracked paths, which are recorded in the third-parent if it exists, are shown in addition to the paths that have modifications between the stash base and the working tree in the stash. It is possible to manually craft a malformed stash entry where duplicate untracked files in the stash entry will mask tracked files. We detect and error out in that case via a custom unpack_trees() callback: stash_worktree_untracked_merge(). Also, teach stash the --only-untracked option which only shows the untracked files of a stash entry. This is similar to `git show stash^3` but it is nice to provide a convenient abstraction for it so that users do not have to think about the underlying implementation. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3905-stash-include-untracked.sh')
-rwxr-xr-xt/t3905-stash-include-untracked.sh106
1 files changed, 106 insertions, 0 deletions
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index b26a97aef4..08ceef6411 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -297,4 +297,110 @@ test_expect_success 'stash -u with globs' '
test_path_is_missing untracked.txt
'
+test_expect_success 'stash show --include-untracked shows untracked files' '
+ git reset --hard &&
+ git clean -xf &&
+ >untracked &&
+ >tracked &&
+ git add tracked &&
+ empty_blob_oid=$(git rev-parse --short :tracked) &&
+ git stash -u &&
+
+ cat >expect <<-EOF &&
+ tracked | 0
+ untracked | 0
+ 2 files changed, 0 insertions(+), 0 deletions(-)
+ EOF
+ git stash show --include-untracked >actual &&
+ test_cmp expect actual &&
+ git stash show -u >actual &&
+ test_cmp expect actual &&
+ git stash show --no-include-untracked --include-untracked >actual &&
+ test_cmp expect actual &&
+ git stash show --only-untracked --include-untracked >actual &&
+ test_cmp expect actual &&
+
+ cat >expect <<-EOF &&
+ diff --git a/tracked b/tracked
+ new file mode 100644
+ index 0000000..$empty_blob_oid
+ diff --git a/untracked b/untracked
+ new file mode 100644
+ index 0000000..$empty_blob_oid
+ EOF
+ git stash show -p --include-untracked >actual &&
+ test_cmp expect actual &&
+ git stash show --include-untracked -p >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'stash show --only-untracked only shows untracked files' '
+ git reset --hard &&
+ git clean -xf &&
+ >untracked &&
+ >tracked &&
+ git add tracked &&
+ empty_blob_oid=$(git rev-parse --short :tracked) &&
+ git stash -u &&
+
+ cat >expect <<-EOF &&
+ untracked | 0
+ 1 file changed, 0 insertions(+), 0 deletions(-)
+ EOF
+ git stash show --only-untracked >actual &&
+ test_cmp expect actual &&
+ git stash show --no-include-untracked --only-untracked >actual &&
+ test_cmp expect actual &&
+ git stash show --include-untracked --only-untracked >actual &&
+ test_cmp expect actual &&
+
+ cat >expect <<-EOF &&
+ diff --git a/untracked b/untracked
+ new file mode 100644
+ index 0000000..$empty_blob_oid
+ EOF
+ git stash show -p --only-untracked >actual &&
+ test_cmp expect actual &&
+ git stash show --only-untracked -p >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'stash show --no-include-untracked cancels --{include,show}-untracked' '
+ git reset --hard &&
+ git clean -xf &&
+ >untracked &&
+ >tracked &&
+ git add tracked &&
+ git stash -u &&
+
+ cat >expect <<-EOF &&
+ tracked | 0
+ 1 file changed, 0 insertions(+), 0 deletions(-)
+ EOF
+ git stash show --only-untracked --no-include-untracked >actual &&
+ test_cmp expect actual &&
+ git stash show --include-untracked --no-include-untracked >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'stash show --include-untracked errors on duplicate files' '
+ git reset --hard &&
+ git clean -xf &&
+ >tracked &&
+ git add tracked &&
+ tree=$(git write-tree) &&
+ i_commit=$(git commit-tree -p HEAD -m "index on any-branch" "$tree") &&
+ test_when_finished "rm -f untracked_index" &&
+ u_commit=$(
+ GIT_INDEX_FILE="untracked_index" &&
+ export GIT_INDEX_FILE &&
+ git update-index --add tracked &&
+ u_tree=$(git write-tree) &&
+ git commit-tree -m "untracked files on any-branch" "$u_tree"
+ ) &&
+ w_commit=$(git commit-tree -p HEAD -p "$i_commit" -p "$u_commit" -m "WIP on any-branch" "$tree") &&
+ test_must_fail git stash show --include-untracked "$w_commit" 2>err &&
+ test_i18ngrep "worktree and untracked commit have duplicate entries: tracked" err
+'
+
test_done