{"thread":{"id":"46404","subject":"Detect invalid submodule names from script?","startedAt":"2017-07-17T11:17:29Z","lastAt":"2017-07-17T18:31:27Z","messageCount":3,"participants":["Joachim Durchholz","Stefan Beller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"324640","messageId":"41004589-4a98-2084-b542-51b7458f607b@durchholz.org","threadId":"46404","inReplyTo":null,"subject":"Detect invalid submodule names from script?","fromName":"Joachim Durchholz","fromEmail":"jo@durchholz.org","sentAt":"2017-07-17T11:17:22Z","receivedAt":"2017-07-17T11:17:29Z","isPatch":false,"sender":{"key":"jo@durchholz.org","avatar":null},"body":"Hi all\n\nI'm hacking some script that calls into git, and I need to detect \nwhether a repository was configured with a submodule name that will work \non \"git submodule init\" and friends.\nI *can* run a git init and see whether it works, but I need to be 100% \nsure that the error was due to an invalid submodule name and not \nsomething else. Bonus points for every version of git for which it works.\n\nAny suggestions?\nThanks!\n\nRegards,\nJo\n"},{"id":"324654","messageId":"CAGZ79kYvup5yOqsgbphwvQe-2sKfXO3a8E1S548WLOXRp4SB_g@mail.gmail.com","threadId":"46404","inReplyTo":"41004589-4a98-2084-b542-51b7458f607b@durchholz.org","subject":"Re: Detect invalid submodule names from script?","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-07-17T17:49:58Z","receivedAt":"2017-07-17T17:50:05Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Jul 17, 2017 at 4:17 AM, Joachim Durchholz <jo@durchholz.org> wrote:\n> Hi all\n>\n> I'm hacking some script that calls into git, and I need to detect whether a\n> repository was configured with a submodule name that will work on \"git\n> submodule init\" and friends.\n\nThere is no such a thing as \"git submodule valid-name\" unfortunately.\nLooking through \"git submodule add\", I think it is safe to assume\nthat any string valid as a subsection in git-config is a valid submodule name.\nOur man page says:\n\n    Subsection names are case sensitive and can contain any characters\n    except newline (doublequote \" and backslash can be included by escaping\n    them as \\\" and \\\\, respectively).\n\nI am not sure about the quality of submodule shell code to handle the quotations\nfor double quote and backslash correctly, so I would suggest not using them,\neither.\n\n> I *can* run a git init and see whether it works, but I need to be 100% sure\n> that the error was due to an invalid submodule name and not something else.\n> Bonus points for every version of git for which it works.\n\nI do not think Git offers a universal solution across versions except actually\nrunning \"submodule init\" and then making an educated guess if the error\ncomes from bad naming or something else.\n\nThis sounds like you're taking user input or otherwise untrustworthy data\nas submodule names?\n\nThanks,\nStefan\n\n>\n> Any suggestions?\n> Thanks!\n>\n> Regards,\n> Jo\n"},{"id":"324659","messageId":"3109accd-5e7b-fdab-4d2e-734c42abf939@durchholz.org","threadId":"46404","inReplyTo":"CAGZ79kYvup5yOqsgbphwvQe-2sKfXO3a8E1S548WLOXRp4SB_g@mail.gmail.com","subject":"Re: Detect invalid submodule names from script?","fromName":"Joachim Durchholz","fromEmail":"jo@durchholz.org","sentAt":"2017-07-17T18:31:21Z","receivedAt":"2017-07-17T18:31:27Z","isPatch":false,"sender":{"key":"jo@durchholz.org","avatar":null},"body":"Am 17.07.2017 um 19:49 schrieb Stefan Beller:\n> On Mon, Jul 17, 2017 at 4:17 AM, Joachim Durchholz <jo@durchholz.org> wrote:\n>> Hi all\n>>\n>> I'm hacking some script that calls into git, and I need to detect whether a\n>> repository was configured with a submodule name that will work on \"git\n>> submodule init\" and friends.\n> \n> There is no such a thing as \"git submodule valid-name\" unfortunately.\n> Looking through \"git submodule add\", I think it is safe to assume\n> that any string valid as a subsection in git-config is a valid submodule name.\n\nThat's what I have been thinking myself.\n\n> Our man page says:\n> \n>      Subsection names are case sensitive and can contain any characters\n>      except newline (doublequote \" and backslash can be included by escaping\n>      them as \\\" and \\\\, respectively).\n> \n> I am not sure about the quality of submodule shell code to handle the quotations\n> for double quote and backslash correctly, so I would suggest not using them,\n> either.\n\nThe quality is pretty dubious for path names (where I have torture tests \nin place).\nI haven't done these tests for module names yet. I doubt it's going to \nlook prettier though.\n\n>> I *can* run a git init and see whether it works, but I need to be 100% sure\n>> that the error was due to an invalid submodule name and not something else.\n>> Bonus points for every version of git for which it works.\n> \n> I do not think Git offers a universal solution across versions except actually\n> running \"submodule init\" and then making an educated guess if the error\n> comes from bad naming or something else.\n\nYeah, I think that's the way to go - clone into a local temp directory, \nset up the submodule to a sane module and subdirectory name, and if that \nworks, test what happens with the original configuration.\n\nI'd have preferred something less elaborate though.\nE.g. SVN has a --xml option that will output everything in XML format. \n(Not useful for shell scripting but easy for almost any other scripting \nlanguage.)\n\n> This sounds like you're taking user input or otherwise untrustworthy data\n> as submodule names?\n\nI'm auto-downloading submodules as configured in 3rd-party repositories.\nWhich means untrusted data is copied to the user's home directory, so I \ndefinitely need to make sure that nothing nasty can happen.\n\nMy current code is a /bin/sh script.\nGiven the security/reliability/robustness problems I keep encountering, \nthe temptation to rewrite this in Python has been steadily growing, \nthough I'm not quite there yet.\n\nRegards,\nJo\n"}]}