{"thread":{"id":"46648","subject":"Best way to check whether working tree matches a commit's tree","startedAt":"2017-08-22T18:00:32Z","lastAt":"2017-08-22T20:08:57Z","messageCount":3,"participants":["Sebastian Schuberth","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"326949","messageId":"onhres$g9$1@blaine.gmane.org","threadId":"46648","inReplyTo":null,"subject":"Best way to check whether working tree matches a commit's tree","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2017-08-22T18:00:01Z","receivedAt":"2017-08-22T18:00:32Z","isPatch":false,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"Hi,\n\nI'd like to check whether my working tree exactly matches the tree of a given commit. That is, there should not be any untracked, staged or modified files (including ignored files).\n\nCurrently, I'm doing this in two steps:\n\n- check for success and empty output of \"git status --ignored --porcelain\"\n- check that the output of \"git rev-parse HEAD\" matches the given commit\n\nWhile this works, it feels sub-optimal. Is there a better / smarter way?\n\n-- \nSebastian Schuberth\n\n"},{"id":"326958","messageId":"xmqqfucj2y7d.fsf@gitster.mtv.corp.google.com","threadId":"46648","inReplyTo":"onhres$g9$1@blaine.gmane.org","subject":"Re: Best way to check whether working tree matches a commit's tree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-08-22T19:34:46Z","receivedAt":"2017-08-22T19:34:54Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sebastian Schuberth <sschuberth@gmail.com> writes:\n\n> Hi,\n>\n> I'd like to check whether my working tree exactly matches the tree of a given commit. That is, there should not be any untracked, staged or modified files (including ignored files).\n>\n> Currently, I'm doing this in two steps:\n>\n> - check for success and empty output of \"git status --ignored --porcelain\"\n> - check that the output of \"git rev-parse HEAD\" matches the given commit\n>\n> While this works, it feels sub-optimal. Is there a better / smarter way?\n\nI do not think so; you want three things to match and you have a way\nto compare two things at a time.\n\nBy the way, I think your second check should compare\n\n\trev-parse HEAD^{tree} $that_commit^{tree}\n\nas you are checking if the tree exactly matches.\n"},{"id":"326967","messageId":"CAHGBnuPpJtdTBPapFrKcEg6QknBkMjFzwmF0cx9S_2Uo+vp2HA@mail.gmail.com","threadId":"46648","inReplyTo":"xmqqfucj2y7d.fsf@gitster.mtv.corp.google.com","subject":"Re: Best way to check whether working tree matches a commit's tree","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2017-08-22T20:08:52Z","receivedAt":"2017-08-22T20:08:57Z","isPatch":false,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"On Tue, Aug 22, 2017 at 9:34 PM, Junio C Hamano <gitster@pobox.com> wrote:\n\n>> While this works, it feels sub-optimal. Is there a better / smarter way?\n>\n> I do not think so; you want three things to match and you have a way\n> to compare two things at a time.\n\nRight. I was just thinking if there's a lesser known command like \"git\ndiff --no-index\", but instead of taking two paths, take just one path\nand a commit.\n\n> By the way, I think your second check should compare\n>\n>         rev-parse HEAD^{tree} $that_commit^{tree}\n>\n> as you are checking if the tree exactly matches.\n\nIn fact, I was considering to use \"git diff HEAD $that_commit\" as I\ndon't really care whether the SHA1s are equal, but just about the file\ncontents / tree.\n\n-- \nSebastian Schuberth\n"}]}