{"thread":{"id":"19105","subject":"[PATCHv2] Add --reference option to git submodule.","startedAt":"2009-04-28T12:30:33Z","lastAt":"2009-05-04T17:57:57Z","messageCount":6,"participants":["Michael S. Tsirkin","Michael J Gruber","Johannes Sixt","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"112514","messageId":"20090428123033.GA6839@redhat.com","threadId":"19105","inReplyTo":null,"subject":"[PATCHv2] Add --reference option to git submodule.","fromName":"Michael S. Tsirkin","fromEmail":"mst@redhat.com","sentAt":"2009-04-28T12:30:33Z","receivedAt":"2009-04-28T12:30:33Z","isPatch":false,"sender":{"key":"mst@kernel.org","avatar":null},"body":"This adds --reference option to git submodule add and\ngit submodule update commands, which is passed on to git clone.\n\nSigned-off-by: Michael S. Tsirkin <mst@redhat.com>\n---\n\nHere's v2. Ack?\n\nChanges from v1: fixes in documentation, fix test usage and\nmake it portable.\n\n Documentation/git-submodule.txt |   14 ++++++++++++--\n git-submodule.sh                |   31 ++++++++++++++++++++++++++++---\n 2 files changed, 40 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 3b8df44..14256c6 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -9,10 +9,12 @@ git-submodule - Initialize, update or inspect submodules\n SYNOPSIS\n --------\n [verse]\n-'git submodule' [--quiet] add [-b branch] [--] <repository> <path>\n+'git submodule' [--quiet] add [-b branch]\n+\t      [--reference <repository>] [--] <repository> <path>\n 'git submodule' [--quiet] status [--cached] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n-'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...]\n+'git submodule' [--quiet] update [--init] [-N|--no-fetch]\n+\t      [--reference <repository>] [--] [<path>...]\n 'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]\n 'git submodule' [--quiet] foreach <command>\n 'git submodule' [--quiet] sync [--] [<path>...]\n@@ -177,6 +179,14 @@ OPTIONS\n \tThis option is only valid for the update command.\n \tDon't fetch new objects from the remote site.\n \n+--reference <repository>::\n+\tThis option is only valid for add and update commands.  These\n+\tcommands sometimes need to clone a remote repository. In this case,\n+\tthis option will be passed to the linkgit:git-clone[1] command.\n++\n+*NOTE*: Do *not* use this option unless you have read the note\n+for linkgit:git-clone[1]'s --reference and --shared options carefully.\n+\n <path>...::\n \tPaths to submodule(s). When specified this will restrict the command\n \tto only operate on the submodules found at the specified paths.\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 8e234a4..4989d86 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -15,6 +15,7 @@ require_work_tree\n command=\n branch=\n quiet=\n+reference=\n cached=\n nofetch=\n \n@@ -91,6 +92,7 @@ module_clone()\n {\n \tpath=$1\n \turl=$2\n+\treference=\"$3\"\n \n \t# If there already is a directory at the submodule path,\n \t# expect it to be empty (since that is the default checkout\n@@ -106,7 +108,12 @@ module_clone()\n \ttest -e \"$path\" &&\n \tdie \"A file already exist at path '$path'\"\n \n-\tgit-clone -n \"$url\" \"$path\" ||\n+\tif test -n \"$reference\"\n+\tthen\n+\t\tgit-clone \"$reference\" -n \"$url\" \"$path\"\n+\telse\n+\t\tgit-clone -n \"$url\" \"$path\"\n+\tfi ||\n \tdie \"Clone of '$url' into submodule path '$path' failed\"\n }\n \n@@ -131,6 +138,15 @@ cmd_add()\n \t\t-q|--quiet)\n \t\t\tquiet=1\n \t\t\t;;\n+\t\t--reference)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\treference=\"--reference=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--reference=*)\n+\t\t\treference=\"$1\"\n+\t\t\tshift\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -203,7 +219,7 @@ cmd_add()\n \t\tgit config submodule.\"$path\".url \"$url\"\n \telse\n \n-\t\tmodule_clone \"$path\" \"$realrepo\" || exit\n+\t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n \t\t(\n \t\t\tunset GIT_DIR\n \t\t\tcd \"$path\" &&\n@@ -321,6 +337,15 @@ cmd_update()\n \t\t\tshift\n \t\t\tnofetch=1\n \t\t\t;;\n+\t\t--reference)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\treference=\"$2\"\n+\t\t\tshift 2\n+\t\t\t;;\n+\t\t--reference=*)\n+\t\t\treference=\"$1\"\n+\t\t\tshift\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -351,7 +376,7 @@ cmd_update()\n \n \t\tif ! test -d \"$path\"/.git -o -f \"$path\"/.git\n \t\tthen\n-\t\t\tmodule_clone \"$path\" \"$url\" || exit\n+\t\t\tmodule_clone \"$path\" \"$url\" \"$reference\"|| exit\n \t\t\tsubsha1=\n \t\telse\n \t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n-- \n1.6.3.rc3.dirty\n"},{"id":"112518","messageId":"49F702C0.8030206@drmicha.warpmail.net","threadId":"19105","inReplyTo":"20090428123033.GA6839@redhat.com","subject":"Re: [PATCHv2] Add --reference option to git submodule.","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-04-28T13:21:04Z","receivedAt":"2009-04-28T13:21:04Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Michael S. Tsirkin venit, vidit, dixit 28.04.2009 14:30:\n> This adds --reference option to git submodule add and\n> git submodule update commands, which is passed on to git clone.\n> \n> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>\n> ---\n> \n> Here's v2. Ack?\n\nI don't think it's up to me to Ack but you addressed my remarks.\nBTW, even dash has \"test STRING\" so portability doesn't require -n but I\nthink it's OK either way.\n\nJust be prepared in case someone asks for a test script ;)\n\nMichael\n\n> \n> Changes from v1: fixes in documentation, fix test usage and\n> make it portable.\n> \n>  Documentation/git-submodule.txt |   14 ++++++++++++--\n>  git-submodule.sh                |   31 ++++++++++++++++++++++++++++---\n>  2 files changed, 40 insertions(+), 5 deletions(-)\n> \n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index 3b8df44..14256c6 100644\n> --- a/Documentation/git-submodule.txt\n> +++ b/Documentation/git-submodule.txt\n> @@ -9,10 +9,12 @@ git-submodule - Initialize, update or inspect submodules\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git submodule' [--quiet] add [-b branch] [--] <repository> <path>\n> +'git submodule' [--quiet] add [-b branch]\n> +\t      [--reference <repository>] [--] <repository> <path>\n>  'git submodule' [--quiet] status [--cached] [--] [<path>...]\n>  'git submodule' [--quiet] init [--] [<path>...]\n> -'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...]\n> +'git submodule' [--quiet] update [--init] [-N|--no-fetch]\n> +\t      [--reference <repository>] [--] [<path>...]\n>  'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]\n>  'git submodule' [--quiet] foreach <command>\n>  'git submodule' [--quiet] sync [--] [<path>...]\n> @@ -177,6 +179,14 @@ OPTIONS\n>  \tThis option is only valid for the update command.\n>  \tDon't fetch new objects from the remote site.\n>  \n> +--reference <repository>::\n> +\tThis option is only valid for add and update commands.  These\n> +\tcommands sometimes need to clone a remote repository. In this case,\n> +\tthis option will be passed to the linkgit:git-clone[1] command.\n> ++\n> +*NOTE*: Do *not* use this option unless you have read the note\n> +for linkgit:git-clone[1]'s --reference and --shared options carefully.\n> +\n>  <path>...::\n>  \tPaths to submodule(s). When specified this will restrict the command\n>  \tto only operate on the submodules found at the specified paths.\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 8e234a4..4989d86 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -15,6 +15,7 @@ require_work_tree\n>  command=\n>  branch=\n>  quiet=\n> +reference=\n>  cached=\n>  nofetch=\n>  \n> @@ -91,6 +92,7 @@ module_clone()\n>  {\n>  \tpath=$1\n>  \turl=$2\n> +\treference=\"$3\"\n>  \n>  \t# If there already is a directory at the submodule path,\n>  \t# expect it to be empty (since that is the default checkout\n> @@ -106,7 +108,12 @@ module_clone()\n>  \ttest -e \"$path\" &&\n>  \tdie \"A file already exist at path '$path'\"\n>  \n> -\tgit-clone -n \"$url\" \"$path\" ||\n> +\tif test -n \"$reference\"\n> +\tthen\n> +\t\tgit-clone \"$reference\" -n \"$url\" \"$path\"\n> +\telse\n> +\t\tgit-clone -n \"$url\" \"$path\"\n> +\tfi ||\n>  \tdie \"Clone of '$url' into submodule path '$path' failed\"\n>  }\n>  \n> @@ -131,6 +138,15 @@ cmd_add()\n>  \t\t-q|--quiet)\n>  \t\t\tquiet=1\n>  \t\t\t;;\n> +\t\t--reference)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\treference=\"--reference=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--reference=*)\n> +\t\t\treference=\"$1\"\n> +\t\t\tshift\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -203,7 +219,7 @@ cmd_add()\n>  \t\tgit config submodule.\"$path\".url \"$url\"\n>  \telse\n>  \n> -\t\tmodule_clone \"$path\" \"$realrepo\" || exit\n> +\t\tmodule_clone \"$path\" \"$realrepo\" \"$reference\" || exit\n>  \t\t(\n>  \t\t\tunset GIT_DIR\n>  \t\t\tcd \"$path\" &&\n> @@ -321,6 +337,15 @@ cmd_update()\n>  \t\t\tshift\n>  \t\t\tnofetch=1\n>  \t\t\t;;\n> +\t\t--reference)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\treference=\"$2\"\n> +\t\t\tshift 2\n> +\t\t\t;;\n> +\t\t--reference=*)\n> +\t\t\treference=\"$1\"\n> +\t\t\tshift\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -351,7 +376,7 @@ cmd_update()\n>  \n>  \t\tif ! test -d \"$path\"/.git -o -f \"$path\"/.git\n>  \t\tthen\n> -\t\t\tmodule_clone \"$path\" \"$url\" || exit\n> +\t\t\tmodule_clone \"$path\" \"$url\" \"$reference\"|| exit\n>  \t\t\tsubsha1=\n>  \t\telse\n>  \t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n"},{"id":"112522","messageId":"49F717D4.70708@viscovery.net","threadId":"19105","inReplyTo":"49F702C0.8030206@drmicha.warpmail.net","subject":"Re: [PATCHv2] Add --reference option to git submodule.","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2009-04-28T14:51:00Z","receivedAt":"2009-04-28T14:51:00Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Michael J Gruber schrieb:\n> BTW, even dash has \"test STRING\" so portability doesn't require -n but I\n> think it's OK either way.\n\nIt is not if STRING is user input; it could be, e.g., '-f', and then the\ncommand gives a syntax error because of a missing argument.\n\nIt's safer to use test -z and test -n unless the string to test is\ncompletely under the control of the script.\n\n-- Hannes\n"},{"id":"112544","messageId":"49F73682.2010404@drmicha.warpmail.net","threadId":"19105","inReplyTo":"49F717D4.70708@viscovery.net","subject":"Re: [PATCHv2] Add --reference option to git submodule.","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-04-28T17:01:54Z","receivedAt":"2009-04-28T17:01:54Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Johannes Sixt venit, vidit, dixit 28.04.2009 16:51:\n> Michael J Gruber schrieb:\n>> BTW, even dash has \"test STRING\" so portability doesn't require -n but I\n>> think it's OK either way.\n> \n> It is not if STRING is user input; it could be, e.g., '-f', and then the\n> command gives a syntax error because of a missing argument.\n> \n> It's safer to use test -z and test -n unless the string to test is\n> completely under the control of the script.\n\nYep, that's true as a general rule. Here it's always preceeded by\n\"--reference=\". But in any case I'm happy I suggested -n and it's in ;)\n\nMichael\n"},{"id":"112548","messageId":"7vskjslig6.fsf@gitster.siamese.dyndns.org","threadId":"19105","inReplyTo":"49F702C0.8030206@drmicha.warpmail.net","subject":"Re: [PATCHv2] Add --reference option to git submodule.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-28T18:52:09Z","receivedAt":"2009-04-28T18:52:09Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> Michael S. Tsirkin venit, vidit, dixit 28.04.2009 14:30:\n>> This adds --reference option to git submodule add and\n>> git submodule update commands, which is passed on to git clone.\n>> \n>> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>\n>> ---\n>> \n>> Here's v2. Ack?\n>\n> I don't think it's up to me to Ack but you addressed my remarks.\n\nYou can certainly say \"Reviewed-by: me\" and/or \"Tested-by: me\".\n\n> BTW, even dash has \"test STRING\" so portability doesn't require -n but I\n> think it's OK either way.\n\nIt always is a good discipline and style.\n"},{"id":"112997","messageId":"20090504175757.GA1144@redhat.com","threadId":"19105","inReplyTo":"7vskjslig6.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCHv2] Add --reference option to git submodule.","fromName":"Michael S. Tsirkin","fromEmail":"mst@redhat.com","sentAt":"2009-05-04T17:57:57Z","receivedAt":"2009-05-04T17:57:57Z","isPatch":false,"sender":{"key":"mst@kernel.org","avatar":null},"body":"On Tue, Apr 28, 2009 at 11:52:09AM -0700, Junio C Hamano wrote:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n> > Michael S. Tsirkin venit, vidit, dixit 28.04.2009 14:30:\n> >> This adds --reference option to git submodule add and\n> >> git submodule update commands, which is passed on to git clone.\n> >> \n> >> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>\n> >> ---\n> >> \n> >> Here's v2. Ack?\n> >\n> > I don't think it's up to me to Ack but you addressed my remarks.\n> \n> You can certainly say \"Reviewed-by: me\" and/or \"Tested-by: me\".\n\nSo ... Junio, what do you think about the patch?\n\n-- \nMST\n"}]}