{"thread":{"id":"51112","subject":"getting pull/push/fetch url","startedAt":"2019-05-17T07:30:37Z","lastAt":"2019-05-17T11:10:22Z","messageCount":4,"participants":["clime","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"375792","messageId":"CAGqZTUvTg5S_-i9JjOwEG75CY+xFXJHAwTqh8uLG3SQTa3O0YA@mail.gmail.com","threadId":"51112","inReplyTo":null,"subject":"getting pull/push/fetch url","fromName":"clime","fromEmail":"clime7@gmail.com","sentAt":"2019-05-17T07:30:23Z","receivedAt":"2019-05-17T07:30:37Z","isPatch":false,"sender":{"key":"clime7@gmail.com","avatar":"https://gravatar.com/avatar/d99ae46a5b0f57415bb74fc6c8ecd7eec304ff769f298c3be00fabf961b215ff?d=mp&s=160"},"body":"Hello,\n\nfor my app, i need to be able get remote urls (fetch/pull/push) so\nthat i can derive some information from those, e.g. pull url netloc\nfrom which i derive where other custom endpoints (binary file storage)\nrelated to the remote git repo is located. This is just one example. I\nam also using fetch url to store it into the composed package that i\ngenerate by the app.\n\n...And I also want to support git down to 1.7.1 (maybe i could live\nwith 1.8.3, not sure now)\n\nNow, the problem is that getting those urls (fetch/pull/push) doesn't\nseem to be an easy task. Currently i have the attached scripts to do\nthat. But i noticed that older gits like 1.7 use origin as a fallback\nfor pull url whereas the newer raise an error.\n\nMy question is if there is a better way to determine the urls that\nwould be backward compatible and easier than what i am doing right\nnow.\n\nI could probably tweak my app to only use fetch url but then i won't\nsupport triangle workflow so i would like to know if there is some\nbetter option.\n\nThank you\nclime\n"},{"id":"375794","messageId":"CAPig+cQ0MB4F++JDC-RO2SFA4Hv7DiEW4hNJGQs71Wi75pXuOg@mail.gmail.com","threadId":"51112","inReplyTo":"CAGqZTUvTg5S_-i9JjOwEG75CY+xFXJHAwTqh8uLG3SQTa3O0YA@mail.gmail.com","subject":"Re: getting pull/push/fetch url","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-05-17T08:09:48Z","receivedAt":"2019-05-17T08:10:02Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, May 17, 2019 at 3:30 AM clime <clime7@gmail.com> wrote:\n> for my app, i need to be able get remote urls (fetch/pull/push) so\n> that i can derive some information from those, e.g. pull url netloc\n> from which i derive where other custom endpoints (binary file storage)\n> related to the remote git repo is located. This is just one example. I\n> am also using fetch url to store it into the composed package that i\n> generate by the app.\n>\n> Now, the problem is that getting those urls (fetch/pull/push) doesn't\n> seem to be an easy task. Currently i have the attached scripts to do\n> that. But i noticed that older gits like 1.7 use origin as a fallback\n> for pull url whereas the newer raise an error.\n>\n> My question is if there is a better way to determine the urls that\n> would be backward compatible and easier than what i am doing right\n> now.\n\nPerhaps not a complete answer (and I'm sure people more familiar with\nthe topic can provide better direction), but have you tried querying\nthis information via higher-level commands rather than low-level\ngit-config? For instance, to get the name of the remote for a branch:\n\n    git branch --list --format='%(upstream:remotename)' $BRANCH\n\nand, to get the fetch URL for a remote:\n\n    git remote get-url $REMOTE\n\nor the push URL:\n\n    git remote get-url --push $REMOTE\n"},{"id":"375797","messageId":"CAGqZTUv7zkgT=GJK5Mo7HCoNcjqvsZoCKb93Pc=_r6LcskAabw@mail.gmail.com","threadId":"51112","inReplyTo":"CAPig+cQ0MB4F++JDC-RO2SFA4Hv7DiEW4hNJGQs71Wi75pXuOg@mail.gmail.com","subject":"Re: getting pull/push/fetch url","fromName":"clime","fromEmail":"clime7@gmail.com","sentAt":"2019-05-17T11:02:47Z","receivedAt":"2019-05-17T11:03:01Z","isPatch":false,"sender":{"key":"clime7@gmail.com","avatar":"https://gravatar.com/avatar/d99ae46a5b0f57415bb74fc6c8ecd7eec304ff769f298c3be00fabf961b215ff?d=mp&s=160"},"body":"On Fri, 17 May 2019 at 10:10, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>\n> On Fri, May 17, 2019 at 3:30 AM clime <clime7@gmail.com> wrote:\n> > for my app, i need to be able get remote urls (fetch/pull/push) so\n> > that i can derive some information from those, e.g. pull url netloc\n> > from which i derive where other custom endpoints (binary file storage)\n> > related to the remote git repo is located. This is just one example. I\n> > am also using fetch url to store it into the composed package that i\n> > generate by the app.\n> >\n> > Now, the problem is that getting those urls (fetch/pull/push) doesn't\n> > seem to be an easy task. Currently i have the attached scripts to do\n> > that. But i noticed that older gits like 1.7 use origin as a fallback\n> > for pull url whereas the newer raise an error.\n> >\n> > My question is if there is a better way to determine the urls that\n> > would be backward compatible and easier than what i am doing right\n> > now.\n>\n> Perhaps not a complete answer (and I'm sure people more familiar with\n> the topic can provide better direction), but have you tried querying\n> this information via higher-level commands rather than low-level\n> git-config? For instance, to get the name of the remote for a branch:\n>\n>     git branch --list --format='%(upstream:remotename)' $BRANCH\n>\n> and, to get the fetch URL for a remote:\n>\n>     git remote get-url $REMOTE\n>\n> or the push URL:\n>\n>     git remote get-url --push $REMOTE\n\nRight, the problem is that both constructs `git branch --list\n--format=<format> <branch>` and `git remote get-url <remote>`\nworks only under git v2 (not exactly sure about the minor version) but\nthey do not work under git 1.7.1 and git 1.8.3, it\nseems.\n\nAnyway, i figured i was too fuzzy in what kind of url i actually need.\nI thought about it a bit more and figured that I probably this\n\nfunction git_branch_remote {\n    branch_remote=\"$(git -C \"$GIT_ROOT\" config --get\nbranch.\"$GIT_BRANCH\".pushRemote)\"\n\n    if [ -z \"$branch_remote\" ]; then\n        branch_remote=\"$(git -C \"$GIT_ROOT\" config --get remote.pushDefault)\"\n    fi\n\n    if [ -z \"$branch_remote\" ]; then\n        branch_remote=\"$(git -C \"$GIT_ROOT\" config --get\nbranch.\"$GIT_BRANCH\".remote)\"\n    fi\n\n    if [ -z \"$branch_remote\" ]; then\n        branch_remote=\"origin\"\n    fi\n\n    echo \"$branch_remote\"\n}\n\nBecause basically, if some wants to go for triangle workflow, then\npush url remote should be preferred because\nthat's where user has write access. If not, then there is a fallback\nto branch.<branch>.remote and to origin\neventually, which is just nice to have cause it makes a minimal setup\nfor my app easier.\n\nSo basically, it is possible that an effective (where git actually\npushes when `git push` is invoked) remote\nfor pushing will be different than what that function returns (e.g.\nwhen git 1.7.1. is used which doesn't\nknow about branch.<branch>.pushRemote and remote.pushDefault) but it\ndoesn't really matter as long\nas a user is able to make a local configuration where effective push\nremote and remote returned by\nthe fuction will align.\n\nThen i also need 'origin' being returned immediatelly after clean\nclone but that's the case as well.\n\nSo when i have this kind of 'abstracted' remote, then i need to take\npushUrl on one place and fetch\nurl on another but there should be no problem there.\n\nSorry, i didn't realize i actually kind of this 'hybrid remote' thing.\nThere still might an easier way to write\nthat function (in a compatible way). Not sure about that.\n\nAnyway, thanks\nclime\n"},{"id":"375798","messageId":"CAGqZTUuh5K447ejUTDfnR-5t0oqQ8BpU=tKUR=s9APmCja=mhw@mail.gmail.com","threadId":"51112","inReplyTo":"CAGqZTUv7zkgT=GJK5Mo7HCoNcjqvsZoCKb93Pc=_r6LcskAabw@mail.gmail.com","subject":"Re: getting pull/push/fetch url","fromName":"clime","fromEmail":"clime7@gmail.com","sentAt":"2019-05-17T11:10:09Z","receivedAt":"2019-05-17T11:10:22Z","isPatch":false,"sender":{"key":"clime7@gmail.com","avatar":"https://gravatar.com/avatar/d99ae46a5b0f57415bb74fc6c8ecd7eec304ff769f298c3be00fabf961b215ff?d=mp&s=160"},"body":"On Fri, 17 May 2019 at 13:02, clime <clime7@gmail.com> wrote:\n>\n> On Fri, 17 May 2019 at 10:10, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> >\n> > On Fri, May 17, 2019 at 3:30 AM clime <clime7@gmail.com> wrote:\n> > > for my app, i need to be able get remote urls (fetch/pull/push) so\n> > > that i can derive some information from those, e.g. pull url netloc\n> > > from which i derive where other custom endpoints (binary file storage)\n> > > related to the remote git repo is located. This is just one example. I\n> > > am also using fetch url to store it into the composed package that i\n> > > generate by the app.\n> > >\n> > > Now, the problem is that getting those urls (fetch/pull/push) doesn't\n> > > seem to be an easy task. Currently i have the attached scripts to do\n> > > that. But i noticed that older gits like 1.7 use origin as a fallback\n> > > for pull url whereas the newer raise an error.\n> > >\n> > > My question is if there is a better way to determine the urls that\n> > > would be backward compatible and easier than what i am doing right\n> > > now.\n> >\n> > Perhaps not a complete answer (and I'm sure people more familiar with\n> > the topic can provide better direction), but have you tried querying\n> > this information via higher-level commands rather than low-level\n> > git-config? For instance, to get the name of the remote for a branch:\n> >\n> >     git branch --list --format='%(upstream:remotename)' $BRANCH\n> >\n> > and, to get the fetch URL for a remote:\n> >\n> >     git remote get-url $REMOTE\n> >\n> > or the push URL:\n> >\n> >     git remote get-url --push $REMOTE\n>\n> Right, the problem is that both constructs `git branch --list\n> --format=<format> <branch>` and `git remote get-url <remote>`\n> works only under git v2 (not exactly sure about the minor version) but\n> they do not work under git 1.7.1 and git 1.8.3, it\n> seems.\n>\n> Anyway, i figured i was too fuzzy in what kind of url i actually need.\n> I thought about it a bit more and figured that I probably this\n>\n> function git_branch_remote {\n>     branch_remote=\"$(git -C \"$GIT_ROOT\" config --get\n> branch.\"$GIT_BRANCH\".pushRemote)\"\n>\n>     if [ -z \"$branch_remote\" ]; then\n>         branch_remote=\"$(git -C \"$GIT_ROOT\" config --get remote.pushDefault)\"\n>     fi\n>\n>     if [ -z \"$branch_remote\" ]; then\n>         branch_remote=\"$(git -C \"$GIT_ROOT\" config --get\n> branch.\"$GIT_BRANCH\".remote)\"\n>     fi\n>\n>     if [ -z \"$branch_remote\" ]; then\n>         branch_remote=\"origin\"\n>     fi\n>\n>     echo \"$branch_remote\"\n> }\n>\n> Because basically, if some wants to go for triangle workflow, then\n> push url remote should be preferred because\n> that's where user has write access. If not, then there is a fallback\n> to branch.<branch>.remote and to origin\n> eventually, which is just nice to have cause it makes a minimal setup\n> for my app easier.\n>\n> So basically, it is possible that an effective (where git actually\n> pushes when `git push` is invoked) remote\n> for pushing will be different than what that function returns (e.g.\n> when git 1.7.1. is used which doesn't\n> know about branch.<branch>.pushRemote and remote.pushDefault) but it\n> doesn't really matter as long\n> as a user is able to make a local configuration where effective push\n> remote and remote returned by\n> the fuction will align.\n>\n> Then i also need 'origin' being returned immediatelly after clean\n> clone but that's the case as well.\n>\n> So when i have this kind of 'abstracted' remote, then i need to take\n> pushUrl on one place and fetch\n> url on another but there should be no problem there.\n>\n> Sorry, i didn't realize i actually kind of this 'hybrid remote' thing.\n> There still might an easier way to write\n> that function (in a compatible way). Not sure about that.\n>\n> Anyway, thanks\n> clime\n\nAnd sry for my previous email being a mess. I rushed too much\nto write it.\n"}]}