{"thread":{"id":"7988","subject":"[PATCH] simple submodule checkout support","startedAt":"2007-05-05T19:16:21Z","lastAt":"2007-05-05T19:16:21Z","messageCount":1,"participants":["Martin Waitz"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"41156","messageId":"20070505191621.GC30511@admingilde.org","threadId":"7988","inReplyTo":null,"subject":"[PATCH] simple submodule checkout support","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2007-05-05T19:16:21Z","receivedAt":"2007-05-05T19:16:21Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"Add the ability to move a submodule to a commit which is referenced by a\nnew supermodule version.\n\nThis is not yet a full submodule checkout support -- you can't checkout any\ncommit which is not yet available in the submodule object database.\nThis means you can't create new submodules yet.\n\nSigned-off-by: Martin Waitz <tali@admingilde.org>\n---\n .gitignore                      |    1 +\n Makefile                        |    2 +-\n entry.c                         |   16 +++++++++++-----\n git-dirlink-checkout.sh         |   27 +++++++++++++++++++++++++++\n t/t3041-subprojects-checkout.sh |   39 +++++++++++++++++++++++++++++++++++++++\n 5 files changed, 79 insertions(+), 6 deletions(-)\n create mode 100644 git-dirlink-checkout.sh\n create mode 100755 t/t3041-subprojects-checkout.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex 4dc0c39..8436a83 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -37,6 +37,7 @@ git-diff\n git-diff-files\n git-diff-index\n git-diff-tree\n+git-dirlink-checkout\n git-describe\n git-fast-import\n git-fetch\ndiff --git a/Makefile b/Makefile\nindex 2fea115..fcd0125 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -196,7 +196,7 @@ SCRIPT_SH = \\\n \tgit-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \\\n \tgit-pull.sh git-rebase.sh \\\n \tgit-repack.sh git-request-pull.sh git-reset.sh \\\n-\tgit-sh-setup.sh \\\n+\tgit-sh-setup.sh git-dirlink-checkout.sh \\\n \tgit-tag.sh git-verify-tag.sh \\\n \tgit-applymbox.sh git-applypatch.sh git-am.sh \\\n \tgit-merge.sh git-merge-stupid.sh git-merge-octopus.sh \\\ndiff --git a/entry.c b/entry.c\nindex 82bf725..6e85e81 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"blob.h\"\n+#include \"run-command.h\"\n \n static void create_directories(const char *path, const struct checkout *state)\n {\n@@ -79,6 +80,13 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout\n {\n \tint fd;\n \tlong wrote;\n+\tconst char *dirlink_checkout[] = {\n+\t\t\"dirlink-checkout\", path, sha1_to_hex(ce->sha1), NULL\n+\t};\n+\tstruct child_process cmd = {\n+\t\t.argv = dirlink_checkout,\n+\t\t.git_cmd = 1\n+\t};\n \n \tswitch (ntohl(ce->ce_mode) & S_IFMT) {\n \t\tchar *buf, *new;\n@@ -148,7 +156,7 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout\n \tcase S_IFDIRLNK:\n \t\tif (to_tempfile)\n \t\t\treturn error(\"git-checkout-index: cannot create temporary subproject %s\", path);\n-\t\tif (mkdir(path, 0777) < 0)\n+\t\tif (run_command(&cmd) != 0)\n \t\t\treturn error(\"git-checkout-index: cannot create subproject directory %s\", path);\n \t\tbreak;\n \tdefault:\n@@ -192,10 +200,8 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t\n \t\t * just do the right thing)\n \t\t */\n \t\tunlink(path);\n-\t\tif (S_ISDIR(st.st_mode)) {\n-\t\t\t/* If it is a gitlink, leave it alone! */\n-\t\t\tif (S_ISDIRLNK(ntohl(ce->ce_mode)))\n-\t\t\t\treturn 0;\n+\t\tif (S_ISDIR(st.st_mode) &&\n+\t\t    access(mkpath(\"%s/.git/HEAD\", path), R_OK)!=0) {\n \t\t\tif (!state->force)\n \t\t\t\treturn error(\"%s is a directory\", path);\n \t\t\tremove_subtree(path);\ndiff --git a/git-dirlink-checkout.sh b/git-dirlink-checkout.sh\nnew file mode 100644\nindex 0000000..2e63970\n--- /dev/null\n+++ b/git-dirlink-checkout.sh\n@@ -0,0 +1,27 @@\n+#!/bin/sh -e\n+\n+USAGE=\"<dirlink-path> <new-ref>\"\n+\n+path=\"$1\"\n+sha1=\"$2\"\n+\n+test -n \"$sha1\" || usage\n+unset GIT_DIR\n+\n+if test ! -d \"$path/.git\"; then\n+\tmkdir \"$path\"\n+\tcd \"$path\"\n+\t# FIXME talk about what the user can do here\n+\techo \"This git submodule has not been populated yet.\" > README.git\n+\texit 0\n+fi\n+\n+cd \"$path\"\n+. git-sh-setup\n+\n+if git rev-parse --verify \"$sha1\" >/dev/null 2>&1; then\n+\tgit checkout \"$sha1\"\n+else\n+\t# FIXME try to fetch it\n+\techo >&2 \"Cannot checkout $sha1 for $path.\"\n+fi\ndiff --git a/t/t3041-subprojects-checkout.sh b/t/t3041-subprojects-checkout.sh\nnew file mode 100755\nindex 0000000..4b3cea9\n--- /dev/null\n+++ b/t/t3041-subprojects-checkout.sh\n@@ -0,0 +1,39 @@\n+#!/bin/sh\n+\n+test_description='submodule checkout'\n+. ./test-lib.sh\n+\n+test_expect_success 'submodule creation' \\\n+    '(mkdir A && cd A &&\n+      git init &&\n+      echo 1 > a &&\n+      git add a &&\n+      git commit -m \"create submodule\" || exit $? )'\n+\n+test_expect_success 'Super module creation' \\\n+    'git add A &&\n+     git commit -m \"supermodule creation\" &&\n+     git branch one'\n+\n+test_expect_success 'submodule change' \\\n+    '(cd A &&\n+      echo 2 > a &&\n+      git add a &&\n+      git commit -m \"create submodule\" || exit $? )'\n+\n+test_expect_success 'supermodule change' \\\n+    'git add A &&\n+     git commit -m \"supermodule creation\"'\n+\n+test_expect_success 'supermodule switching branch' \\\n+    'git checkout one &&\n+     echo 1 > expected &&\n+     git diff expected A/a'\n+\n+test_expect_success 'supermodule reset' \\\n+    'git reset --hard master &&\n+     echo 2 > expected &&\n+     git diff expected A/a'\n+\n+\n+test_done\n-- \n1.5.1.2.247.gaef5a\n\n-- \nMartin Waitz\n"}]}