{"thread":{"id":"28457","subject":"Re: [PATCH 1/2] sparse checkout: show error messages when worktree shaping fails","startedAt":"2011-09-21T19:15:29Z","lastAt":"2011-09-22T19:57:19Z","messageCount":5,"participants":["Joshua Jensen","Junio C Hamano","Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"175957","messageId":"4E7A37D1.1020501@workspacewhiz.com","threadId":"28457","inReplyTo":"1316602259-22576-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 1/2] sparse checkout: show error messages when worktree shaping fails","fromName":"Joshua Jensen","fromEmail":"jjensen@workspacewhiz.com","sentAt":"2011-09-21T19:15:29Z","receivedAt":"2011-09-21T19:15:29Z","isPatch":true,"sender":{"key":"jjensen@workspacewhiz.com","avatar":"https://avatars.githubusercontent.com/u/111687?v=4"},"body":"----- Original Message -----\nFrom: Nguyễn Thái Ngọc Duy\nDate: 9/21/2011 4:50 AM\n>   \t\t\tif (ce->ce_flags&  CE_ADDED&&\n>   \t\t\tverify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))\n> -\t\t\t\t\treturn -1;\n> +\t\t\t\tgoto return_failed;\n>\n> -\t\t\tif (apply_sparse_checkout(ce, o)) {\n> -\t\t\t\tret = -1;\n> -\t\t\t\tgoto done;\n> -\t\t\t}\n> +\t\t\tif (apply_sparse_checkout(ce, o))\n> +\t\t\t\tgoto return_failed;\n>   \t\t\tif (!ce_skip_worktree(ce))\n>   \t\t\t\tempty_worktree = 0;\nUnfortunately, this patch only collects and displays the first untracked \nfile for me.  It does not display all of the files that would be \noverwritten (desired behavior, IMHO).\n\nThis script illustrates:\n\n#!/bin/sh\n\nrm -Rf utest || exit 1\nmkdir utest || exit 1\ncd utest || exit 1\ngit init\ngit config core.sparseCheckout true\necho *>.git/info/sparse-checkout\necho tracked>a\ngit add a\ngit commit -m a a\ngit branch side\necho tracked>b\necho tracked>c\ngit add b c\ngit commit -m bc\ncat b\ngit checkout side\ncat b\necho untracked>b\necho untracked>c\ncat b\ngit checkout master\ncat b\n\n-Josh\n"},{"id":"175964","messageId":"7vk4911ux8.fsf@alter.siamese.dyndns.org","threadId":"28457","inReplyTo":"1316602259-22576-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH 1/2] sparse checkout: show error messages when worktree shaping fails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-09-21T20:50:59Z","receivedAt":"2011-09-21T20:50:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Please add a test when you reroll this, hopefully with help from Joshua.\n\nThanks.\n"},{"id":"175992","messageId":"1316690663-29382-1-git-send-email-pclouds@gmail.com","threadId":"28457","inReplyTo":"7vk4911ux8.fsf@alter.siamese.dyndns.org","subject":"[PATCH v2 1/2] sparse checkout: show error messages when worktree shaping fails","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-09-22T11:24:22Z","receivedAt":"2011-09-22T11:24:22Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"verify_* functions can queue errors up and to be printed later at\nlabel return_failed. In case of errors, do not go to label \"done\"\ndirectly because all queued messages would be dropped on the floor.\n\nFound-by: Joshua Jensen <jjensen@workspacewhiz.com>\nTracked-down-by: Michael J Gruber <git@drmicha.warpmail.net>\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Now print all errors.\n\n t/t1011-read-tree-sparse-checkout.sh |   15 +++++++++++++++\n unpack-trees.c                       |   13 ++++++++++---\n 2 files changed, 25 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh\nindex 018c354..efcd8ab 100755\n--- a/t/t1011-read-tree-sparse-checkout.sh\n+++ b/t/t1011-read-tree-sparse-checkout.sh\n@@ -234,4 +234,19 @@ test_expect_success 'read-tree --reset removes outside worktree' '\n \ttest_cmp empty result\n '\n \n+test_expect_success 'print errors when failed to update worktree' '\n+\techo sub >.git/info/sparse-checkout &&\n+\tgit checkout -f init &&\n+\tmkdir sub &&\n+\ttouch sub/added sub/addedtoo &&\n+\ttest_must_fail git checkout top 2>actual &&\n+\tcat >expected <<\\EOF &&\n+error: The following untracked working tree files would be overwritten by checkout:\n+\tsub/added\n+\tsub/addedtoo\n+Please move or remove them before you can switch branches.\n+EOF\n+\ttest_cmp expected actual\n+'\n+\n test_done\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex cc616c3..fcf40a0 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -1089,6 +1089,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \t\t */\n \t\tmark_new_skip_worktree(o->el, &o->result, CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);\n \n+\t\tret = 0;\n \t\tfor (i = 0; i < o->result.cache_nr; i++) {\n \t\t\tstruct cache_entry *ce = o->result.cache[i];\n \n@@ -1101,17 +1102,23 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \t\t\t * correct CE_NEW_SKIP_WORKTREE\n \t\t\t */\n \t\t\tif (ce->ce_flags & CE_ADDED &&\n-\t\t\t    verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))\n-\t\t\t\t\treturn -1;\n+\t\t\t    verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) {\n+\t\t\t\tif (!o->show_all_errors)\n+\t\t\t\t\tgoto return_failed;\n+\t\t\t\tret = -1;\n+\t\t\t}\n \n \t\t\tif (apply_sparse_checkout(ce, o)) {\n+\t\t\t\tif (!o->show_all_errors)\n+\t\t\t\t\tgoto return_failed;\n \t\t\t\tret = -1;\n-\t\t\t\tgoto done;\n \t\t\t}\n \t\t\tif (!ce_skip_worktree(ce))\n \t\t\t\tempty_worktree = 0;\n \n \t\t}\n+\t\tif (ret < 0)\n+\t\t\tgoto return_failed;\n \t\tif (o->result.cache_nr && empty_worktree) {\n \t\t\t/* dubious---why should this fail??? */\n \t\t\tret = unpack_failed(o, \"Sparse checkout leaves no entry on working directory\");\n-- \n1.7.3.1.256.g2539c.dirty\n"},{"id":"175993","messageId":"1316690663-29382-2-git-send-email-pclouds@gmail.com","threadId":"28457","inReplyTo":"7vk4911ux8.fsf@alter.siamese.dyndns.org","subject":"[PATCH v2 2/2] Add explanation why we do not allow to sparse checkout to empty working tree","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-09-22T11:24:23Z","receivedAt":"2011-09-22T11:24:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n unpack-trees.c |    7 ++++++-\n 1 files changed, 6 insertions(+), 1 deletions(-)\n\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex fcf40a0..bacb473 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -1119,8 +1119,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \t\t}\n \t\tif (ret < 0)\n \t\t\tgoto return_failed;\n+\t\t/*\n+\t\t * Sparse checkout is meant to narrow down checkout area\n+\t\t * but it does not make sense to narrow down to empty working\n+\t\t * tree. This is usually a mistake in sparse checkout rules.\n+\t\t * Do not allow users to do that.\n+\t\t */\n \t\tif (o->result.cache_nr && empty_worktree) {\n-\t\t\t/* dubious---why should this fail??? */\n \t\t\tret = unpack_failed(o, \"Sparse checkout leaves no entry on working directory\");\n \t\t\tgoto done;\n \t\t}\n-- \n1.7.3.1.256.g2539c.dirty\n"},{"id":"176016","messageId":"4E7B931F.5010600@workspacewhiz.com","threadId":"28457","inReplyTo":"1316690663-29382-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH v2 1/2] sparse checkout: show error messages when worktree shaping fails","fromName":"Joshua Jensen","fromEmail":"jjensen@workspacewhiz.com","sentAt":"2011-09-22T19:57:19Z","receivedAt":"2011-09-22T19:57:19Z","isPatch":true,"sender":{"key":"jjensen@workspacewhiz.com","avatar":"https://avatars.githubusercontent.com/u/111687?v=4"},"body":"----- Original Message -----\nFrom: Nguyễn Thái Ngọc Duy\nDate: 9/22/2011 5:24 AM\n> diff --git a/unpack-trees.c b/unpack-trees.c\n> index cc616c3..fcf40a0 100644\n> --- a/unpack-trees.c\n> +++ b/unpack-trees.c\n> @@ -1089,6 +1089,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n>   \t\t */\n>   \t\tmark_new_skip_worktree(o->el,&o->result, CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);\n>\n> +\t\tret = 0;\n>   \t\tfor (i = 0; i<  o->result.cache_nr; i++) {\n>   \t\t\tstruct cache_entry *ce = o->result.cache[i];\n>\n> @@ -1101,17 +1102,23 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n>   \t\t\t * correct CE_NEW_SKIP_WORKTREE\n>   \t\t\t */\n>   \t\t\tif (ce->ce_flags&  CE_ADDED&&\n> -\t\t\t    verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))\n> -\t\t\t\t\treturn -1;\n> +\t\t\t    verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) {\n> +\t\t\t\tif (!o->show_all_errors)\n> +\t\t\t\t\tgoto return_failed;\n> +\t\t\t\tret = -1;\n> +\t\t\t}\n>\n>   \t\t\tif (apply_sparse_checkout(ce, o)) {\n> +\t\t\t\tif (!o->show_all_errors)\n> +\t\t\t\t\tgoto return_failed;\n>   \t\t\t\tret = -1;\n> -\t\t\t\tgoto done;\n>   \t\t\t}\n>   \t\t\tif (!ce_skip_worktree(ce))\n>   \t\t\t\tempty_worktree = 0;\n>\n>   \t\t}\n> +\t\tif (ret<  0)\n> +\t\t\tgoto return_failed;\n>   \t\tif (o->result.cache_nr&&  empty_worktree) {\n>   \t\t\t/* dubious---why should this fail??? */\n>   \t\t\tret = unpack_failed(o, \"Sparse checkout leaves no entry on working directory\");\nI can confirm that this version of the patch works for me with multiple \nuntracked files in a sparse checkout.\n\n-Josh\n"}]}