{"thread":{"id":"50386","subject":"[PATCH v5 1/2] describe: setup working tree for --dirty","startedAt":"2019-02-03T06:00:53Z","lastAt":"2019-02-03T06:00:53Z","messageCount":2,"participants":["Sebastian Staudt"],"isPatch":true,"patchVersion":5,"patchTotal":2},"messages":[{"id":"368426","messageId":"20190203060025.7486-1-koraktor@gmail.com","threadId":"50386","inReplyTo":null,"subject":"[PATCH v5 1/2] describe: setup working tree for --dirty","fromName":"Sebastian Staudt","fromEmail":"koraktor@gmail.com","sentAt":"2019-02-03T06:00:24Z","receivedAt":"2019-02-03T06:00:53Z","isPatch":true,"sender":{"key":"koraktor@gmail.com","avatar":"https://avatars.githubusercontent.com/u/66112?v=4"},"body":"We don't use NEED_WORK_TREE when running the git-describe builtin,\nsince you should be able to describe a commit even in a bare repository.\nHowever, the --dirty flag does need a working tree. Since we don't call\nsetup_work_tree(), it uses whatever directory we happen to be in. That's\nunlikely to match our index, meaning we'd say \"dirty\" even when the real\nworking tree is clean.\n\nWe can fix that by calling setup_work_tree() once we know that the user\nhas asked for --dirty.\n\nThe --broken option also needs a working tree. But because its\nimplementation calls git-diff-index we don‘t have to setup the working\ntree in the git-describe process.\n\nSigned-off-by: Sebastian Staudt <koraktor@gmail.com>\nHelped-by: Jeff King <peff@peff.net>\n---\n builtin/describe.c  |  1 +\n t/t6120-describe.sh | 33 +++++++++++++++++++++++++++++++++\n 2 files changed, 34 insertions(+)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex cc118448ee..b5b7abdc8f 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -629,6 +629,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t\tstruct argv_array args = ARGV_ARRAY_INIT;\n \t\t\tint fd, result;\n \n+\t\t\tsetup_work_tree();\n \t\t\tread_cache();\n \t\t\trefresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,\n \t\t\t\t      NULL, NULL, NULL);\ndiff --git a/t/t6120-describe.sh b/t/t6120-describe.sh\nindex d639d94696..a9e3bf0ce0 100755\n--- a/t/t6120-describe.sh\n+++ b/t/t6120-describe.sh\n@@ -145,14 +145,38 @@ check_describe A-* HEAD\n \n check_describe \"A-*[0-9a-f]\" --dirty\n \n+test_expect_success 'describe --dirty with --work-tree' '\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\tgrep \"^A-[1-9][0-9]\\?-g[0-9a-f]\\+$\" out\n+'\n+\n test_expect_success 'set-up dirty work tree' '\n \techo >>file\n '\n \n check_describe \"A-*[0-9a-f]-dirty\" --dirty\n \n+test_expect_success 'describe --dirty with --work-tree (dirty)' '\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\tgrep \"^A-[1-9][0-9]\\?-g[0-9a-f]\\+-dirty$\" out\n+'\n+\n check_describe \"A-*[0-9a-f].mod\" --dirty=.mod\n \n+test_expect_success 'describe --dirty=.mod with --work-tree (dirty)' '\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --dirty=.mod >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n+\tgrep \"^A-[1-9][0-9]\\?-g[0-9a-f]\\+.mod$\" out\n+'\n+\n test_expect_success 'describe --dirty HEAD' '\n \ttest_must_fail git describe --dirty HEAD\n '\n@@ -303,8 +327,17 @@ test_expect_success 'describe chokes on severely broken submodules' '\n \tmv .git/modules/sub1/ .git/modules/sub_moved &&\n \ttest_must_fail git describe --dirty\n '\n+\n test_expect_success 'describe ignoring a broken submodule' '\n \tgit describe --broken >out &&\n+\tgrep broken out\n+'\n+\n+test_expect_success 'describe with --work-tree ignoring a broken submodule' '\n+\t(\n+\t\tcd \"$TEST_DIRECTORY\" &&\n+\t\tgit --git-dir \"$TRASH_DIRECTORY/.git\" --work-tree \"$TRASH_DIRECTORY\" describe --broken >\"$TRASH_DIRECTORY/out\"\n+\t) &&\n \ttest_when_finished \"mv .git/modules/sub_moved .git/modules/sub1\" &&\n \tgrep broken out\n '\n-- \n2.20.1\n\n"},{"id":"368427","messageId":"20190203060025.7486-2-koraktor@gmail.com","threadId":"50386","inReplyTo":"20190203060025.7486-1-koraktor@gmail.com","subject":"[PATCH v5 2/2] t6120: test for describe with a bare repository","fromName":"Sebastian Staudt","fromEmail":"koraktor@gmail.com","sentAt":"2019-02-03T06:00:25Z","receivedAt":"2019-02-03T06:00:53Z","isPatch":true,"sender":{"key":"koraktor@gmail.com","avatar":"https://avatars.githubusercontent.com/u/66112?v=4"},"body":"This ensures that nothing breaks the basic functionality of describe for\nbare repositories. Please note that --broken and --dirty need a working\ntree.\n\nSigned-off-by: Sebastian Staudt <koraktor@gmail.com>\n---\n t/t6120-describe.sh | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/t/t6120-describe.sh b/t/t6120-describe.sh\nindex a9e3bf0ce0..ee5b03ee18 100755\n--- a/t/t6120-describe.sh\n+++ b/t/t6120-describe.sh\n@@ -143,6 +143,12 @@ test_expect_success 'rename tag Q back to A' '\n test_expect_success 'pack tag refs' 'git pack-refs'\n check_describe A-* HEAD\n \n+test_expect_success 'describe works from outside repo using --git-dir' '\n+\tgit clone --bare \"$TRASH_DIRECTORY\" \"$TRASH_DIRECTORY/bare\" &&\n+\tgit --git-dir \"$TRASH_DIRECTORY/bare\" describe >out &&\n+\tgrep \"^A-[1-9][0-9]\\?-g[0-9a-f]\\+$\" out\n+'\n+\n check_describe \"A-*[0-9a-f]\" --dirty\n \n test_expect_success 'describe --dirty with --work-tree' '\n-- \n2.20.1\n\n"}]}