{"thread":{"id":"3376","subject":"[PATCH 1/3] Trap exit to clean up created directory if clone fails.","startedAt":"2006-02-17T21:33:23Z","lastAt":"2006-02-17T21:33:28Z","messageCount":4,"participants":["Carl Worth"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"16340","messageId":"11402120031687-git-send-email-cworth@cworth.org","threadId":"3376","inReplyTo":null,"subject":"Making git-clone clean up when it fails","fromName":"Carl Worth","fromEmail":"cworth@cworth.org","sentAt":"2006-02-17T21:33:23Z","receivedAt":"2006-02-17T21:33:23Z","isPatch":false,"sender":{"key":"cworth@cworth.org","avatar":"https://gravatar.com/avatar/3746dc28cde609bdbd7f939058356e7e2bbd16d21e32274df0725eb3d998bc5b?d=mp&s=160"},"body":"So instead of just making noise, I'll start actually contributing to\ngit. The first patch here is designed to fix the annoying bug that\nwhen git-clone fails it still leaves the created directory around, (so\nthat a subsequent git-clone will be guaranteed to fail since the\ndirectory already exists).\n\nThe second and third patches provide a new test case for the new\nbehavior. I had to guess at the number for the new test, since the\ndistinction of the various numbers in t/README was too vague for me to\nknow where a git-clone test should go. Feel free to adjust that as\nyou might see fit.\n\n-Carl\n\n-- \ncworth@redhat.com\n"},{"id":"16339","messageId":"11402120042011-git-send-email-cworth@cworth.org","threadId":"3376","inReplyTo":"11402120031687-git-send-email-cworth@cworth.org","subject":"[PATCH 1/3] Trap exit to clean up created directory if clone fails.","fromName":"Carl Worth","fromEmail":"cworth@cworth.org","sentAt":"2006-02-17T21:33:24Z","receivedAt":"2006-02-17T21:33:24Z","isPatch":true,"sender":{"key":"cworth@cworth.org","avatar":"https://gravatar.com/avatar/3746dc28cde609bdbd7f939058356e7e2bbd16d21e32274df0725eb3d998bc5b?d=mp&s=160"},"body":"Signed-off-by: Carl Worth <cworth@cworth.org>\n\n\n---\n\n git-clone.sh |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\n589b68168e3dad89238b879b06680c662a99ad8d\ndiff --git a/git-clone.sh b/git-clone.sh\nindex e192b08..d184ceb 100755\n--- a/git-clone.sh\n+++ b/git-clone.sh\n@@ -118,6 +118,7 @@ dir=\"$2\"\n [ -e \"$dir\" ] && echo \"$dir already exists.\" && usage\n mkdir -p \"$dir\" &&\n D=$(cd \"$dir\" && pwd) &&\n+trap 'err=$?; rm -r $D; exit $err' exit\n case \"$bare\" in\n yes) GIT_DIR=\"$D\" ;;\n *) GIT_DIR=\"$D/.git\" ;;\n@@ -255,3 +256,6 @@ Pull: $head_points_at:$origin\" &&\n \t\tgit checkout\n \tesac\n fi\n+\n+trap - exit\n+\n-- \n1.2.0.gf6e8\n"},{"id":"16341","messageId":"1140212006127-git-send-email-cworth@cworth.org","threadId":"3376","inReplyTo":"11402120042011-git-send-email-cworth@cworth.org","subject":"[PATCH 2/3] Abstract test_create_repo out for use in tests.","fromName":"Carl Worth","fromEmail":"cworth@cworth.org","sentAt":"2006-02-17T21:33:26Z","receivedAt":"2006-02-17T21:33:26Z","isPatch":true,"sender":{"key":"cworth@cworth.org","avatar":"https://gravatar.com/avatar/3746dc28cde609bdbd7f939058356e7e2bbd16d21e32274df0725eb3d998bc5b?d=mp&s=160"},"body":"Signed-off-by: Carl Worth <cworth@cworth.org>\n\n\n---\n\n t/test-lib.sh |   23 +++++++++++++++++------\n 1 files changed, 17 insertions(+), 6 deletions(-)\n\n6110a439c2b1962c6f128cdaac3a2ee8450ac22c\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 7a58a86..66f62b9 100755\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -149,6 +149,21 @@ test_expect_code () {\n \tfi\n }\n \n+# Most tests can use the created repository, but some amy need to create more.\n+# Usage: test_create_repo <directory>\n+test_create_repo () {\n+\ttest \"$#\" = 1 ||\n+\terror \"bug in the test script: not 1 parameter to test-create-repo\"\n+\towd=`pwd`\n+\trepo=\"$1\"\n+\tmkdir \"$repo\"\n+\tcd \"$repo\" || error \"Cannot setup test environment\"\n+\t\"$GIT_EXEC_PATH/git\" init-db --template=$GIT_EXEC_PATH/templates/blt/ 2>/dev/null ||\n+\terror \"cannot run git init-db -- have you built things yet?\"\n+\tmv .git/hooks .git/hooks-disabled\n+\tcd \"$owd\"\n+}\n+\t\n test_done () {\n \ttrap - exit\n \tcase \"$test_failure\" in\n@@ -196,9 +211,5 @@ test -d ../templates/blt || {\n # Test repository\n test=trash\n rm -fr \"$test\"\n-mkdir \"$test\"\n-cd \"$test\" || error \"Cannot setup test environment\"\n-\"$GIT_EXEC_PATH/git\" init-db --template=../../templates/blt/ 2>/dev/null ||\n-error \"cannot run git init-db -- have you built things yet?\"\n-\n-mv .git/hooks .git/hooks-disabled\n+test_create_repo $test\n+cd \"$test\"\n-- \n1.2.0.gf6e8\n"},{"id":"16342","messageId":"11402120081238-git-send-email-cworth@cworth.org","threadId":"3376","inReplyTo":"1140212006127-git-send-email-cworth@cworth.org","subject":"[PATCH 3/3] New test to verify that when git-clone fails it cleans up the new directory.","fromName":"Carl Worth","fromEmail":"cworth@cworth.org","sentAt":"2006-02-17T21:33:28Z","receivedAt":"2006-02-17T21:33:28Z","isPatch":true,"sender":{"key":"cworth@cworth.org","avatar":"https://gravatar.com/avatar/3746dc28cde609bdbd7f939058356e7e2bbd16d21e32274df0725eb3d998bc5b?d=mp&s=160"},"body":"Signed-off-by: Carl Worth <cworth@cworth.org>\n\n\n---\n\n t/t5600-clone-fail-cleanup.sh |   36 ++++++++++++++++++++++++++++++++++++\n 1 files changed, 36 insertions(+), 0 deletions(-)\n create mode 100755 t/t5600-clone-fail-cleanup.sh\n\n0d8852c105e5f910ba53fc974a5d929a2136aecd\ndiff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh\nnew file mode 100755\nindex 0000000..0c6a363\n--- /dev/null\n+++ b/t/t5600-clone-fail-cleanup.sh\n@@ -0,0 +1,36 @@\n+#!/bin/sh\n+#\n+# Copyright (C) 2006 Carl D. Worth <cworth@cworth.org>\n+#\n+\n+test_description='test git-clone to cleanup after failure\n+\n+This test covers the fact that if git-clone fails, it should remove\n+the directory it created, to avoid the user having to manually\n+remove the directory before attempting a clone again.'\n+\n+. ./test-lib.sh\n+\n+test_expect_failure \\\n+    'clone of non-existent source should fail' \\\n+    'git-clone foo bar'\n+\n+test_expect_failure \\\n+    'failed clone should not leave a directory' \\\n+    'cd bar'\n+\n+# Need a repo to clone\n+test_create_repo foo\n+\n+# clone doesn't like it if there is no HEAD. Is that a bug?\n+(cd foo && touch file && git add file && git commit -m 'add file' >/dev/null 2>&1)\n+\n+test_expect_success \\\n+    'clone should work now that source exists' \\\n+    'git-clone foo bar'\n+\n+test_expect_success \\\n+    'successfull clone must leave the directory' \\\n+    'cd bar'\n+\n+test_done\n-- \n1.2.0.gf6e8\n"}]}