{"thread":{"id":"6049","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","startedAt":"2006-12-20T09:01:30Z","lastAt":"2006-12-21T08:49:48Z","messageCount":11,"participants":["Andy Parkins","Junio C Hamano","Andreas Ericsson","Brian Gernhardt","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"297400","messageId":"200612200901.30584.andyparkins@gmail.com","threadId":"6049","inReplyTo":null,"subject":"[RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2006-12-20T09:01:30Z","receivedAt":"2006-12-20T09:01:30Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Make a file called .gitmodules.  In it, list the paths containing a\nsubmodule.  Add that file to the index.\n\nThis addition to the pre-commit hook finds that file and pulls the HEAD\nhash out of each of the listed submodule repositories.  That hash is\nthen listed to the .gitmodules file along with the submodule name and\n.gitmodules is added back to the repository.\n\nYou've now got poor-man's submodule support.  Any commits to the\nsubmodule will change the hash and hence the .gitmodules file will be\ndifferent and therefore will show up as \"modified\" to git.\n\nIt's not got any nice UI for checking out (obviously) or merging; but it\ndoes at least record the state of a project with a bit of manual work to\ncheck out the right commit in the submodule.\n\nProblems:\n - git-prune in the submodule could destroy supermodule-referenced\n   commits\n - no checkout support\n - no merge support (other than what git provides for the .gitmodule\n   file)\n - no check for dirty submodule before commit\n\nSigned-off-by: Andy Parkins <andyparkins@gmail.com>\n---\n templates/hooks--pre-commit |   31 ++++++++++++++++++++++++++++++-\n 1 files changed, 30 insertions(+), 1 deletions(-)\n\ndiff --git a/templates/hooks--pre-commit b/templates/hooks--pre-commit\nindex 723a9ef..7a71d81 100644\n--- a/templates/hooks--pre-commit\n+++ b/templates/hooks--pre-commit\n@@ -67,5 +67,34 @@ perl -e '\n \t}\n     }\n     exit($found_bad);\n-'\n+' || exit 1\n+\n+# Enable poor-man's submodule support when .gitmodules is present\n+# Simply create a .gitmodules file listing the paths in your repository\n+# that contain other git repositories; each line will be replaced with the\n+# path followed by the hash of the current HEAD of the submodule.\n+# When the submodule changes hash this file will be different from the\n+# version in the repository and a change will be noted - voila, submodules.\n+# Of course there is no checkout support, but at least the current state\n+# will be accurately recorded\n+if [ -f .gitmodules ]; then\n+\tcat .gitmodules |\n+\twhile read subdir hash\n+\tdo\n+\t\t# XXX: check if the line is a comment\n+\n+\t\t# XXX: really need a check here and quit if the submodule is\n+\t\t# dirty\n+\n+\t\techo \"$subdir $(GIT_DIR=$subdir/.git git-rev-parse HEAD)\"\n+\tdone > .gitmodules\n+\n+\t# This relies on the .gitmodules file having already been added to\n+\t# the repository - perhaps this should be automated?\n+\tgit-update-index .gitmodules ||\n+\t(\n+\techo \"Submodule tracker file is not tracked by this repository.\" >&2\n+\texit 1\n+\t)\n+fi\n \n-- \n1.4.4.2.g95ee-dirty\n"},{"id":"296279","messageId":"200612201008.49045.andyparkins@gmail.com","threadId":"6049","inReplyTo":"200612200901.30584.andyparkins@gmail.com","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2006-12-20T10:08:47Z","receivedAt":"2006-12-20T10:08:47Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"Hello,\n\nHelp...\n\n> +if [ -f .gitmodules ]; then\n\nThis doesn't work because git-commit is not necessarily in the root of the \nworking tree.  How do I safely get that root?  While ${GIT_DIR}/.. would work \nit is not guaranteed.\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\n"},{"id":"298693","messageId":"A76C0FA3-1649-409B-B0D4-C22865622C1F@silverinsanity.com","threadId":"6049","inReplyTo":"200612201008.49045.andyparkins@gmail.com","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-20T11:49:04Z","receivedAt":"2006-12-20T11:49:04Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Dec 20, 2006, at 5:08 AM, Andy Parkins wrote:\n\n> Hello,\n>\n> Help...\n>\n>> +if [ -f .gitmodules ]; then\n>\n> This doesn't work because git-commit is not necessarily in the root  \n> of the\n> working tree.  How do I safely get that root?  While ${GIT_DIR}/..  \n> would work\n> it is not guaranteed.\n\nThe way to do that seems to be \"git rev-parse --git-dir\".  I'm not  \nsure why it's not just \"git --git-dir\" or similar (probably just  \nhistorical reasons), but there you go.\n\n"},{"id":"296878","messageId":"emb8ev$egb$1@sea.gmane.org","threadId":"6049","inReplyTo":"200612201008.49045.andyparkins@gmail.com","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-20T11:59:58Z","receivedAt":"2006-12-20T11:59:58Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Andy Parkins wrote:\n\n> Help...\n> \n>> +if [ -f .gitmodules ]; then\n> \n> This doesn't work because git-commit is not necessarily in the root of the \n> working tree.  How do I safely get that root?  While ${GIT_DIR}/.. would work \n> it is not guaranteed.\n\nDo you want \"git rev-parse --show-prefix\" or \"git rev-parse --show-cdup\",\nor \"git rev-parse --git-dir\" perhaps? (Although here rev in rev-parse is\nmisnomer).\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"297632","messageId":"emb8h2$io4$1@sea.gmane.org","threadId":"6049","inReplyTo":"A76C0FA3-1649-409B-B0D4-C22865622C1F@silverinsanity.com","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-12-20T12:01:04Z","receivedAt":"2006-12-20T12:01:04Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Brian Gernhardt wrote:\n\n> \n> On Dec 20, 2006, at 5:08 AM, Andy Parkins wrote:\n> \n>> Hello,\n>>\n>> Help...\n>>\n>>> +if [ -f .gitmodules ]; then\n>>\n>> This doesn't work because git-commit is not necessarily in the root  \n>> of the\n>> working tree.  How do I safely get that root?  While ${GIT_DIR}/..  \n>> would work\n>> it is not guaranteed.\n> \n> The way to do that seems to be \"git rev-parse --git-dir\".  I'm not  \n> sure why it's not just \"git --git-dir\" or similar (probably just  \n> historical reasons), but there you go.\n\nBecause it is \"git --git-dir=<PATH>\" to set it (probably).\nAlthough it is not insurmountable difficulity...\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"295874","messageId":"200612201211.10163.andyparkins@gmail.com","threadId":"6049","inReplyTo":"emb8ev$egb$1@sea.gmane.org","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2006-12-20T12:11:07Z","receivedAt":"2006-12-20T12:11:07Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Wednesday 2006 December 20 11:59, Jakub Narebski wrote:\n\n> Do you want \"git rev-parse --show-prefix\" or \"git rev-parse --show-cdup\",\n> or \"git rev-parse --git-dir\" perhaps? (Although here rev in rev-parse is\n> misnomer).\n\n--show-cdup was the one.  Thanks so much.  I tried git-var, never even thought \nof git-rev-parse.\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\n"},{"id":"295640","messageId":"45892E16.2040301@op5.se","threadId":"6049","inReplyTo":"emb8h2$io4$1@sea.gmane.org","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-12-20T12:35:34Z","receivedAt":"2006-12-20T12:35:34Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Jakub Narebski wrote:\n> Brian Gernhardt wrote:\n> \n>> On Dec 20, 2006, at 5:08 AM, Andy Parkins wrote:\n>>\n>>> Hello,\n>>>\n>>> Help...\n>>>\n>>>> +if [ -f .gitmodules ]; then\n>>> This doesn't work because git-commit is not necessarily in the root  \n>>> of the\n>>> working tree.  How do I safely get that root?  While ${GIT_DIR}/..  \n>>> would work\n>>> it is not guaranteed.\n>> The way to do that seems to be \"git rev-parse --git-dir\".  I'm not  \n>> sure why it's not just \"git --git-dir\" or similar (probably just  \n>> historical reasons), but there you go.\n> \n> Because it is \"git --git-dir=<PATH>\" to set it (probably).\n> Although it is not insurmountable difficulity...\n\nAFAIR, the discussions long ago went along the lines of \"if no argument \nis passed to any of the --*-dir options, print out the current value\". \nIf \"git --git-dir\" doesn't print the directory name of the .git \ndirectory inside the repo you're currently in, I'd consider it a bug.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\n"},{"id":"296735","messageId":"CF24F5E4-AE2F-48FD-A0C5-474D8BFA757F@silverinsanity.com","threadId":"6049","inReplyTo":"45892E16.2040301@op5.se","subject":"[BUG] git --git-dir dies with bus error","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2006-12-20T14:47:37Z","receivedAt":"2006-12-20T14:47:37Z","isPatch":false,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Dec 20, 2006, at 7:35 AM, Andreas Ericsson wrote:\n\n> AFAIR, the discussions long ago went along the lines of \"if no  \n> argument is passed to any of the --*-dir options, print out the  \n> current value\". If \"git --git-dir\" doesn't print the directory name  \n> of the .git directory inside the repo you're currently in, I'd  \n> consider it a bug.\n\nConsider this a bug then:\n\n$ git --git-dir\nBus error\n$ git --version\ngit version 1.4.4.1.GIT\n$ git rev-parse origin/master\n8336afa563fbeff35e531396273065161181f04c\n$ gdb git\n(gdb) set args --git-dir\n(gdb) run\nStarting program: /usr/local/stow/git/src/git/git --git-dir\nReading symbols for shared libraries ..+ done\n\nProgram received signal EXC_BAD_ACCESS, Could not access memory.\nReason: KERN_PROTECTION_FAILURE at address: 0x00000000\n0x900332e6 in setenv ()\n(gdb) bt\n#0  0x900332e6 in setenv ()\n#1  0x00001f9e in handle_options (argv=0xbffff4a4, argc=0xbffff4a0)  \nat git.c:76\n#2  0x000022da in main (argc=1, argv=0xbffff504, envp=0xbffff50c) at  \ngit.c:346\n\nMy current HEAD (and installed version) just includes my \"remove  \nCOLLISION_CHECK\" patch on top of git master.  This is on OS 10.4.8  \nwith fink 0.26.  It appears to be trying to set GIT_DIR to some non- \nset section of memory.  Bad git, bad.  I'd try to patch this myself  \n(to at least display an error instead of dying), but I'm deep in my  \nactual project code right now.\n\n"},{"id":"297518","messageId":"7vslfae4uv.fsf@assigned-by-dhcp.cox.net","threadId":"6049","inReplyTo":"200612200901.30584.andyparkins@gmail.com","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-20T19:37:12Z","receivedAt":"2006-12-20T19:37:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n> Problems:\n>  - git-prune in the submodule could destroy supermodule-referenced\n>    commits\n>  - no checkout support\n>  - no merge support (other than what git provides for the .gitmodule\n>    file)\n>  - no check for dirty submodule before commit\n>\n> Signed-off-by: Andy Parkins <andyparkins@gmail.com>\n\nI do not think these are insurmountable.\n\nAs you fix them and enhance the support, I suspect you would\nwant a separate command to manage .gitmodule file and submodules\nreferenced by it.  I think it would be better to keep the patch\nto the template to the minimum (for example, run \"git submodule\nupdate\" if there is .gitmodules file at the toplevel), and\nimplement the body of the processing in \"git-submodule.sh\", or\nsomething like that.\n"},{"id":"29910","messageId":"200612210839.35980.andyparkins@gmail.com","threadId":"6049","inReplyTo":"7vslfae4uv.fsf@assigned-by-dhcp.cox.net","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2006-12-21T08:39:34Z","receivedAt":"2006-12-21T08:39:34Z","isPatch":true,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Wednesday 2006 December 20 19:37, Junio C Hamano wrote:\n\n> I do not think these are insurmountable.\n\nMe either.  I wasn't really sure how warmly these patches would be received, \nso thought some small patches that make the feature highly might be more \npalatable.  I actually don't think that the hook templates is the right place \nfor this work; submodule support is not something you would customise \nper-repository, and so the hook scripts are manifestly the wrong place for \nthis.\n\n> As you fix them and enhance the support, I suspect you would\n> want a separate command to manage .gitmodule file and submodules\n> referenced by it.  I think it would be better to keep the patch\n> to the template to the minimum (for example, run \"git submodule\n> update\" if there is .gitmodules file at the toplevel), and\n> implement the body of the processing in \"git-submodule.sh\", or\n> something like that.\n\nThat's an interesting idea.  I was thinking that git-commit itself would have \nbeen the final target; but I certainly don't have any problem with a separate \ncommand.\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIEE\nandyparkins@gmail.com\n"},{"id":"29914","messageId":"7v7iwleiqb.fsf@assigned-by-dhcp.cox.net","threadId":"6049","inReplyTo":"200612210839.35980.andyparkins@gmail.com","subject":"Re: [RFC/PATCH] Implement poor-man's submodule support in pre-commit hook","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-21T08:49:48Z","receivedAt":"2006-12-21T08:49:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Parkins <andyparkins@gmail.com> writes:\n\n>> As you fix them and enhance the support, I suspect you would\n>> want a separate command to manage .gitmodule file and submodules\n>> referenced by it.  I think it would be better to keep the patch\n>> to the template to the minimum (for example, run \"git submodule\n>> update\" if there is .gitmodules file at the toplevel), and\n>> implement the body of the processing in \"git-submodule.sh\", or\n>> something like that.\n>\n> That's an interesting idea.  I was thinking that git-commit\n> itself would have been the final target; but I certainly don't\n> have any problem with a separate command.\n\nI do not think the commit command would be the \"final\" one.\n\nWhen you have a loosely coupled subproject, sometimes you might\nwant to check out subprojects recursively, so you would also\nwant \"checkout\" action to \"git submodule\", which might hook into\n\"git checkout\" just like your patch hooked into \"git commit\".\nSimilarly your future versions certainly would want to hook into\n\"git fetch/pull\".\n\nJust like some peoples' workflow avoid \"git pull\" but do \"git\nfetch\" and \"git merge\" as separate steps, some people may want\nto disable the above \"hooks\", and prefer using \"git submodule\"\nfrom the command line as a separate step, especially if they\nwant very loose coupling.\n"}]}