{"thread":{"id":"12911","subject":"git-archive and submodules","startedAt":"2008-03-29T13:47:27Z","lastAt":"2008-03-29T21:05:58Z","messageCount":4,"participants":["Whit Armstrong","Shawn O. Pearce","CJ van den Berg"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"73319","messageId":"8ec76080803290647h25e86f18k7a86bc4cb2cc3d38@mail.gmail.com","threadId":"12911","inReplyTo":null,"subject":"git-archive and submodules","fromName":"Whit Armstrong","fromEmail":"armstrong.whit@gmail.com","sentAt":"2008-03-29T13:47:27Z","receivedAt":"2008-03-29T13:47:27Z","isPatch":false,"sender":{"key":"armstrong.whit@gmail.com","avatar":"https://gravatar.com/avatar/3977f2e287db4d4de47839714313edee1222fa9d68677e1de922ec243da4b77d?d=mp&s=160"},"body":"Is there a way to ask git-archive to archive the submodules of the\nproject as well?\n\nI have a project that needs it's submoduels distributed with it.\n\nIs anyone else using submodules in this way?\n\nmy project is: \tgit://repo.or.cz/fts.git\n\nIt has a submodule: \ttslib at git://repo.or.cz/tslib.git\n\nI create the archive by:\ngit archive --format=tar --prefix=fts/ HEAD | gzip > ~/fts.tar.gz\n\nand when I go into the tslib submodule directory after expanding the\narchive, it is empty.\n\n-Whit\n"},{"id":"73320","messageId":"20080329135202.GR4759@spearce.org","threadId":"12911","inReplyTo":"8ec76080803290647h25e86f18k7a86bc4cb2cc3d38@mail.gmail.com","subject":"Re: git-archive and submodules","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-03-29T13:52:02Z","receivedAt":"2008-03-29T13:52:02Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Whit Armstrong <armstrong.whit@gmail.com> wrote:\n> Is there a way to ask git-archive to archive the submodules of the\n> project as well?\n> \n> I have a project that needs it's submoduels distributed with it.\n\nNo.\n\nPatches welcome.  :-)\n \nWe've talked about supporting it, and wouldn't mind having the\ntool do it for exactly the reason you mention, but thus far a\npatch has not been written to implement that.\n\n-- \nShawn.\n"},{"id":"73321","messageId":"8ec76080803290713k71b7cb19xee2361035a71878d@mail.gmail.com","threadId":"12911","inReplyTo":"20080329135202.GR4759@spearce.org","subject":"Re: git-archive and submodules","fromName":"Whit Armstrong","fromEmail":"armstrong.whit@gmail.com","sentAt":"2008-03-29T14:13:34Z","receivedAt":"2008-03-29T14:13:34Z","isPatch":false,"sender":{"key":"armstrong.whit@gmail.com","avatar":"https://gravatar.com/avatar/3977f2e287db4d4de47839714313edee1222fa9d68677e1de922ec243da4b77d?d=mp&s=160"},"body":"as a first patch that might be a bit ambitious for me, but I will give it a try.\n\nanyway, it's good to know that there is additional support for this behavior.\n\n-Whit\n\n\nOn Sat, Mar 29, 2008 at 9:52 AM, Shawn O. Pearce <spearce@spearce.org> wrote:\n> Whit Armstrong <armstrong.whit@gmail.com> wrote:\n>  > Is there a way to ask git-archive to archive the submodules of the\n>  > project as well?\n>  >\n>  > I have a project that needs it's submoduels distributed with it.\n>\n>  No.\n>\n>  Patches welcome.  :-)\n>\n>  We've talked about supporting it, and wouldn't mind having the\n>  tool do it for exactly the reason you mention, but thus far a\n>  patch has not been written to implement that.\n>\n>  --\n>  Shawn.\n>\n"},{"id":"73334","messageId":"20080329210557.GA4837@prefect.vdbonline.net","threadId":"12911","inReplyTo":"20080329135202.GR4759@spearce.org","subject":"Re: git-archive and submodules","fromName":"CJ van den Berg","fromEmail":"cj@vdbonline.com","sentAt":"2008-03-29T21:05:58Z","receivedAt":"2008-03-29T21:05:58Z","isPatch":false,"sender":{"key":"cj@vdbonline.com","avatar":"https://gravatar.com/avatar/cb86d32484d54ed858459f2d284018b85fae4b802d457a85c3ed60448c63f1e5?d=mp&s=160"},"body":"On Sat, Mar 29, 2008 at 09:52:02AM -0400, Shawn O. Pearce wrote:\n> Whit Armstrong <armstrong.whit@gmail.com> wrote:\n> > Is there a way to ask git-archive to archive the submodules of the\n> > project as well?\n> > \n> > I have a project that needs it's submoduels distributed with it.\n> \n> No.\n> \n> Patches welcome.  :-)\n>  \n> We've talked about supporting it, and wouldn't mind having the\n> tool do it for exactly the reason you mention, but thus far a\n> patch has not been written to implement that.\n\nHere's a script I use at work that calls git-archive recursively for\nsubmodules and builds a single tarball for everything. If there is\ninterest in having something like this in git proper I could put some\nwork into cleaning it up for general use. Perhaps something like this\nshould be integrated into git-archive directly. Comments and suggestions\nare welcome.\n\n-- \nCJ van den Berg\n\nmailto:cj@vdbonline.com\n  xmpp:cj@vdbonline.com\n\n\n#!/bin/bash\n\nset -e\n\nTMP_DIR=$(mktemp -t -d $(basename $0).$USER.XXXXX)\nGITMODULES_FILE=${TMP_DIR}/gitmodules\nTHIS_TAR=${TMP_DIR}/this.tar\nSUBMODULE_TAR=${TMP_DIR}/submodule.tar\n\nfunction cleanup() {\n        rm -rf $TMP_DIR\n}\n\nfunction die() {\n        cleanup\n                exit 1\n}\n\ntrap die SIGINT\ntrap die SIGHUP\ntrap die SIGTERM\ntrap die SIGQUIT\ntrap die ERR\ntrap cleanup EXIT\n\nfunction usage() {\n    echo \"Build an archive of a repository and all submodules.\" >&2\n    echo \"\" >&2\n    echo \"usage: $(basename $0) [-r n] repo treeish [prefix]\" >&2\n    echo \"  repo      Repository path or URL.\" >&2\n    echo \"  treeish   Version to archive.\" >&2\n    echo \"  -r n      Maximum recursion level. Default is 1.\" >&2\n    echo \"  -h        Show this message.\" >&2\n    echo \"\" >&2\n    exit 1\n}\n\nwhile [ \"${1:0:1}\" == \"-\" ]\ndo\n    if [ \"$1\" == \"-h\" ] ; then\n        usage\n    fi\n    if [ \"$1\" == \"-r\" ] ; then\n        LEVEL=$2\n        shift\n        if [ -z \"$LEVEL\" ] ; then\n            usage\n        fi\n        if [ ! $LEVEL -lt 0 ] ; then\n            echo -n \"\" >&2\n        else\n            usage\n        fi\n    fi\n    shift\ndone\n\nif [ $# -lt 2 -o $# -gt 3 ] ; then\n    usage\nfi\n\nexport GIT_DIR=$1\nREV=\"$2\"\nPREFIX=\"$3\"\nif [ -z \"$LEVEL\" ] ; then\n    LEVEL=1\nfi\n\nif echo $GIT_DIR | grep -q \":\"\nthen\n    REMOTE_HOST=$(echo $GIT_DIR | cut -d \":\" -f 1)\n    REMOTE_PATH=$(echo $GIT_DIR | cut -d \":\" -f 2)\n    if [ \"$REMOTE_HOST\" == \"$(hostname)\" ] ; then\n        export GIT_DIR=${REMOTE_PATH}\n    else\n        exec ssh -n $REMOTE_HOST $(basename $0) -r $LEVEL $REMOTE_PATH $REV $PREFIX\n    fi\nfi\n\nif [ \"${GIT_DIR:0:2}\" == \"~/\" ] ; then\n    export GIT_DIR=/home/${USER}/${GIT_DIR#\\~/}\nelif [ \"${GIT_DIR:0:1}\" == \"~\" ] ; then\n    export GIT_DIR=/home/${GIT_DIR#\\~}\nfi\n\nREV_NAME=$(git describe ${REV} 2> /dev/null || true)\nif [ -z \"$REV_NAME\" ] ; then\n    REV_NAME=$(git rev-parse ${REV})\nfi\n\nif [ -z \"$PREFIX\" ] ; then\n    PREFIX=$REV_NAME\nfi\n\necho >&2 ${PREFIX} from $(git-make-repo-url) \\(${REV_NAME}\\)\ngit archive --prefix=${PREFIX}/ $REV > $THIS_TAR\n\nmkdir -p $TMP_DIR/$PREFIX\necho ${REV_NAME}> $TMP_DIR/$PREFIX/GITVERSION\necho $(git-make-repo-url)> $TMP_DIR/$PREFIX/GITSOURCE\n(\n    cd $TMP_DIR\n    tar -rf $THIS_TAR $PREFIX\n)\n\nif [ $LEVEL -gt 0 ]\nthen\n    if git show $REV:.gitmodules > $GITMODULES_FILE 2> /dev/null\n    then\n        LEVEL=$(($LEVEL - 1))\n        git ls-tree -r \"$REV\" | grep '^160000 ' |\n        while read mode type sha1 path\n        do\n            (\n            submodule_name=$(git config --file $GITMODULES_FILE --list | \\\n                              grep \"^submodule\\..*\\.path=$path\" | cut -d . -f 2)\n            if [ -z \"$submodule_name\" ] ; then\n                echo >&2 -n \"fatal: No submodule mapping found in .gitmodules \"\n                echo >&2    \"for path '$path'\"\n                exit 1\n            fi\n            url=$(git config --file $GITMODULES_FILE \\\n                            submodule.\"$submodule_name\".url || exit 1)\n            $(basename $0) -r $LEVEL $url $sha1 $PREFIX/$path > $SUBMODULE_TAR || exit 1\n            tar --concatenate --file=$THIS_TAR $SUBMODULE_TAR || exit 1\n            ) < /dev/null\n        done\n    fi\nfi\ncat $THIS_TAR\n"}]}