{"thread":{"id":"41855","subject":"`git rev-parse --git-dir` relative to current working directory?","startedAt":"2016-03-29T10:32:31Z","lastAt":"2016-03-29T10:50:14Z","messageCount":2,"participants":["Elliott Cable","John Keeping"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"282036","messageId":"CAPZ477NfQ7pCiHQ3V42kZ1Cic5UPP03TCFPvABR_ugSZYEn4xg@mail.gmail.com","threadId":"41855","inReplyTo":null,"subject":"`git rev-parse --git-dir` relative to current working directory?","fromName":"Elliott Cable","fromEmail":"me@ell.io","sentAt":"2016-03-29T10:32:31Z","receivedAt":"2016-03-29T10:32:31Z","isPatch":false,"sender":{"key":"me@ell.io","avatar":"https://gravatar.com/avatar/0d35bb7d7c29b6bbcaafdf13ec70745573d31cb222130cc754a064e707c08d63?d=mp&s=160"},"body":"So, `git help rev-parse` [mentions the following][rev-parse], as of\n2.8.0:\n\n    --git-dir\n       Show $GIT_DIR if defined. Otherwise show the path to the .git\n       directory. The path shown, when relative, is relative to the\n       current working directory.\n\nHowever, when inside a symlinked repository, this doesn't function as\nadvertised:\n\n    $ ln -s a-symlink a-git-repo\n    $ cd a-symlink/.git/hooks\n    $ git rev-parse --git-dir\n    /Users/ec/Documents/a-git-repo/.git\n\nFrom my reading of that snippet of documentation (“The path shown ... is\nrelative to the CWD”), I'd expect to receive `..`, not\n`/absolute/path/to/a-git-repo/.git`.\n\nIs the documentation incorrect, or is this a bug? (I'm hoping the\nlatter: I'm trying to write git-scripting that is sensitive to symlinks,\ni.e. retains the user's CWD without unintentionally resolving symlinks\nin their path during operation; and it'd be ideal if this were handled\nas documented, saving me manual effort checking symlinks.)\n\n\n⁓ ELLIOTTCABLE — fly safe.\n  http://ell.io/tt\n\n   [rev-parse]:\n<https://git-scm.com/docs/git-rev-parse/2.8.0#_options_for_files>\n      \"git rev-parse documentation @2.8.0\"\n"},{"id":"282038","messageId":"20160329105014.GA1578@serenity.lan","threadId":"41855","inReplyTo":"CAPZ477NfQ7pCiHQ3V42kZ1Cic5UPP03TCFPvABR_ugSZYEn4xg@mail.gmail.com","subject":"Re: `git rev-parse --git-dir` relative to current working directory?","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2016-03-29T10:50:14Z","receivedAt":"2016-03-29T10:50:14Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Tue, Mar 29, 2016 at 05:32:31AM -0500, Elliott Cable wrote:\n> So, `git help rev-parse` [mentions the following][rev-parse], as of\n> 2.8.0:\n> \n>     --git-dir\n>        Show $GIT_DIR if defined. Otherwise show the path to the .git\n>        directory. The path shown, when relative, is relative to the\n>        current working directory.\n> \n> However, when inside a symlinked repository, this doesn't function as\n> advertised:\n> \n>     $ ln -s a-symlink a-git-repo\n>     $ cd a-symlink/.git/hooks\n>     $ git rev-parse --git-dir\n>     /Users/ec/Documents/a-git-repo/.git\n> \n> From my reading of that snippet of documentation (“The path shown ... is\n> relative to the CWD”), I'd expect to receive `..`, not\n> `/absolute/path/to/a-git-repo/.git`.\n> \n> Is the documentation incorrect, or is this a bug? (I'm hoping the\n> latter: I'm trying to write git-scripting that is sensitive to symlinks,\n> i.e. retains the user's CWD without unintentionally resolving symlinks\n> in their path during operation; and it'd be ideal if this were handled\n> as documented, saving me manual effort checking symlinks.)\n\nThe documentation seems correct to me, it just requires careful parsing;\nI read it as:\n\n\tif the path printed it relative\n\tthen it is relative to the current working directory\n\nbut it makes not claims about when a relative path will be printed (or\neven if one ever will be, although in my testing the path is relative\nonly if $CWD can be stripped from the beginning of the path; in other\nwords only when no component of the relative path would be \"../\").\n"}]}