{"thread":{"id":"58338","subject":"rev-parse: -- is sometimes a flag and sometimes an arg?","startedAt":"2022-08-20T22:40:11Z","lastAt":"2022-08-23T19:08:52Z","messageCount":8,"participants":["Tim Hockin","Junio C Hamano","brian m. carlson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"461668","messageId":"CAO_RewbD+BJd1hPKCmCNM8wYBSUmZ2TuOoy6t1up1CT-rbn4DA@mail.gmail.com","threadId":"58338","inReplyTo":null,"subject":"rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"Tim Hockin","fromEmail":"thockin@google.com","sentAt":"2022-08-20T22:39:54Z","receivedAt":"2022-08-20T22:40:11Z","isPatch":false,"sender":{"key":"thockin@google.com","avatar":null},"body":"```\n$ git rev-parse unknown-tag\nunknown-tag\nfatal: ambiguous argument 'unknown-tag': unknown revision or path not\nin the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n```\n\nOK\n\n```\n$ git rev-parse unknown-tag --\nfatal: bad revision 'unknown-tag'\n```\n\nMuch nicer error.  But:\n\n```\n$ git rev-parse HEAD --\n113a928239196d0d9f70671517ce917071ceecf6\n--\n```\n\nThat's not very nice.  Why is \"--\" treated as an arg?\n\n```\n$ git rev-parse HEAD\n113a928239196d0d9f70671517ce917071ceecf6\n```\n\nLooking at rev-parse code it SEEMS to be intentional, but I can't\ncomprehend why.\n\nTim\n"},{"id":"461670","messageId":"xmqq8rniikrg.fsf@gitster.g","threadId":"58338","inReplyTo":"CAO_RewbD+BJd1hPKCmCNM8wYBSUmZ2TuOoy6t1up1CT-rbn4DA@mail.gmail.com","subject":"Re: rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-20T22:59:47Z","receivedAt":"2022-08-20T22:59:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tim Hockin <thockin@google.com> writes:\n\n> ```\n> $ git rev-parse unknown-tag\n> unknown-tag\n> fatal: ambiguous argument 'unknown-tag': unknown revision or path not\n> in the working tree.\n> Use '--' to separate paths from revisions, like this:\n> 'git <command> [<revision>...] -- [<file>...]'\n> ```\n>\n> OK\n>\n> ```\n> $ git rev-parse unknown-tag --\n> fatal: bad revision 'unknown-tag'\n> ```\n>\n> Much nicer error.  But:\n>\n> ```\n> $ git rev-parse HEAD --\n> 113a928239196d0d9f70671517ce917071ceecf6\n> --\n> ```\n>\n> That's not very nice.  Why is \"--\" treated as an arg?\n>\n> ```\n> $ git rev-parse HEAD\n> 113a928239196d0d9f70671517ce917071ceecf6\n> ```\n>\n> Looking at rev-parse code it SEEMS to be intentional, but I can't\n> comprehend why.\n\nBecause the first function of \"rev-parse\" (among many others) is to\nbe a helper usable in scripted Porcelains to \"parse\" command line\narguments, shifting them into revs and \"files\".  Without options\nlike --revs-only, --no-revs, --flags etc., it dumps everything, while\ntranslating \"revs\" into raw object names, to its output.  \"--\" is a\nvalid command line option for whatever scripted Porcelain you'd be\nwriting using \"rev-parse\" to help parsing its command line arguments.\n\nSo everything we see above is very much working as designed.\n\n"},{"id":"461674","messageId":"CAO_RewZPXP1EUP90kU6uEQ3_CqqC7yWedjfNd7RaVASFSfrg0Q@mail.gmail.com","threadId":"58338","inReplyTo":"xmqq8rniikrg.fsf@gitster.g","subject":"Re: rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"Tim Hockin","fromEmail":"thockin@google.com","sentAt":"2022-08-21T00:31:23Z","receivedAt":"2022-08-21T00:31:40Z","isPatch":false,"sender":{"key":"thockin@google.com","avatar":null},"body":"Thanks.  Is there a more friendly way to do what I'm trying to\nexpress?  Should I just use `rev-list -n1` instead?\n\nOn Sat, Aug 20, 2022 at 3:59 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Tim Hockin <thockin@google.com> writes:\n>\n> > ```\n> > $ git rev-parse unknown-tag\n> > unknown-tag\n> > fatal: ambiguous argument 'unknown-tag': unknown revision or path not\n> > in the working tree.\n> > Use '--' to separate paths from revisions, like this:\n> > 'git <command> [<revision>...] -- [<file>...]'\n> > ```\n> >\n> > OK\n> >\n> > ```\n> > $ git rev-parse unknown-tag --\n> > fatal: bad revision 'unknown-tag'\n> > ```\n> >\n> > Much nicer error.  But:\n> >\n> > ```\n> > $ git rev-parse HEAD --\n> > 113a928239196d0d9f70671517ce917071ceecf6\n> > --\n> > ```\n> >\n> > That's not very nice.  Why is \"--\" treated as an arg?\n> >\n> > ```\n> > $ git rev-parse HEAD\n> > 113a928239196d0d9f70671517ce917071ceecf6\n> > ```\n> >\n> > Looking at rev-parse code it SEEMS to be intentional, but I can't\n> > comprehend why.\n>\n> Because the first function of \"rev-parse\" (among many others) is to\n> be a helper usable in scripted Porcelains to \"parse\" command line\n> arguments, shifting them into revs and \"files\".  Without options\n> like --revs-only, --no-revs, --flags etc., it dumps everything, while\n> translating \"revs\" into raw object names, to its output.  \"--\" is a\n> valid command line option for whatever scripted Porcelain you'd be\n> writing using \"rev-parse\" to help parsing its command line arguments.\n>\n> So everything we see above is very much working as designed.\n>\n"},{"id":"461675","messageId":"xmqq4jy6igb2.fsf@gitster.g","threadId":"58338","inReplyTo":"CAO_RewZPXP1EUP90kU6uEQ3_CqqC7yWedjfNd7RaVASFSfrg0Q@mail.gmail.com","subject":"Re: rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-21T00:36:01Z","receivedAt":"2022-08-21T00:36:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tim Hockin <thockin@google.com> writes:\n\n> Thanks.  Is there a more friendly way to do what I'm trying to\n> express?  Should I just use `rev-list -n1` instead?\n\nThat's hard to answer, as you didn't exactly say what you are trying\nto express.  All you asked was: why is \"--\" treated as an arg.\n"},{"id":"461676","messageId":"CAO_RewaZHL34WBaoXVyXh6ZNVuG+fi5uGUbpRMsc9N=orHzx1Q@mail.gmail.com","threadId":"58338","inReplyTo":"xmqq4jy6igb2.fsf@gitster.g","subject":"Re: rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"Tim Hockin","fromEmail":"thockin@google.com","sentAt":"2022-08-21T00:39:36Z","receivedAt":"2022-08-21T00:39:52Z","isPatch":false,"sender":{"key":"thockin@google.com","avatar":null},"body":"Sorry, I assumed it was clear, but that was dumb of me.\n\nI have a string - might be a tag name, might be a branch name, might\nbe a SHA (complete or partial).  I want to resolve that into a\ncanonical SHA.  My finger-memory is `git rev-parse`, but I can't say\nif that's just a bad habit I picked up somewhere...\n\nTim\n\nOn Sat, Aug 20, 2022 at 5:36 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Tim Hockin <thockin@google.com> writes:\n>\n> > Thanks.  Is there a more friendly way to do what I'm trying to\n> > express?  Should I just use `rev-list -n1` instead?\n>\n> That's hard to answer, as you didn't exactly say what you are trying\n> to express.  All you asked was: why is \"--\" treated as an arg.\n"},{"id":"461677","messageId":"xmqqzgfyh0vj.fsf@gitster.g","threadId":"58338","inReplyTo":"CAO_RewaZHL34WBaoXVyXh6ZNVuG+fi5uGUbpRMsc9N=orHzx1Q@mail.gmail.com","subject":"Re: rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-21T00:54:40Z","receivedAt":"2022-08-21T00:54:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tim Hockin <thockin@google.com> writes:\n\n> Sorry, I assumed it was clear, but that was dumb of me.\n>\n> I have a string - might be a tag name, might be a branch name, might\n> be a SHA (complete or partial).  I want to resolve that into a\n> canonical SHA.\n\n\"git rev-parse --verify string\" would insist that 'string' is an\nobject name and show it as an object name to the standard output, or\ngives an error message and exits with a non-zero status.\n\n\"git rev-parse --help\" has some more elaborate examples in its\nEXAMPLES section.\n\n\n\n"},{"id":"461821","messageId":"YwQki4nAEOp4wvv9@tapette.crustytoothpaste.net","threadId":"58338","inReplyTo":"xmqqzgfyh0vj.fsf@gitster.g","subject":"Re: rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-08-23T00:51:23Z","receivedAt":"2022-08-23T00:51:29Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-08-21 at 00:54:40, Junio C Hamano wrote:\n> Tim Hockin <thockin@google.com> writes:\n> \n> > Sorry, I assumed it was clear, but that was dumb of me.\n> >\n> > I have a string - might be a tag name, might be a branch name, might\n> > be a SHA (complete or partial).  I want to resolve that into a\n> > canonical SHA.\n> \n> \"git rev-parse --verify string\" would insist that 'string' is an\n> object name and show it as an object name to the standard output, or\n> gives an error message and exits with a non-zero status.\n\nNote that this will print a full hex object ID whether it exists in the\nrepo or not if one is given (for example, the all-zeros object ID).  If\nyou want to verify that the object exists, write this:\n\ngit rev-parse --verify string^{object}\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"461867","messageId":"CAO_RewZCjdGcC3fx7pPZEZ9iTk8_Xs7eBqaf8208da3fD=40mA@mail.gmail.com","threadId":"58338","inReplyTo":"YwQki4nAEOp4wvv9@tapette.crustytoothpaste.net","subject":"Re: rev-parse: -- is sometimes a flag and sometimes an arg?","fromName":"Tim Hockin","fromEmail":"thockin@google.com","sentAt":"2022-08-23T17:45:24Z","receivedAt":"2022-08-23T19:08:52Z","isPatch":false,"sender":{"key":"thockin@google.com","avatar":null},"body":"Thanks!  That helps a lot.\n\nOn Mon, Aug 22, 2022 at 5:51 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> On 2022-08-21 at 00:54:40, Junio C Hamano wrote:\n> > Tim Hockin <thockin@google.com> writes:\n> >\n> > > Sorry, I assumed it was clear, but that was dumb of me.\n> > >\n> > > I have a string - might be a tag name, might be a branch name, might\n> > > be a SHA (complete or partial).  I want to resolve that into a\n> > > canonical SHA.\n> >\n> > \"git rev-parse --verify string\" would insist that 'string' is an\n> > object name and show it as an object name to the standard output, or\n> > gives an error message and exits with a non-zero status.\n>\n> Note that this will print a full hex object ID whether it exists in the\n> repo or not if one is given (for example, the all-zeros object ID).  If\n> you want to verify that the object exists, write this:\n>\n> git rev-parse --verify string^{object}\n> --\n> brian m. carlson (he/him or they/them)\n> Toronto, Ontario, CA\n"}]}