git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Making git-clone clean up when it fails
@ 2006-02-17 21:33 Carl Worth
  2006-02-17 21:33 ` [PATCH 1/3] Trap exit to clean up created directory if clone fails Carl Worth
  0 siblings, 1 reply; 4+ messages in thread
From: Carl Worth @ 2006-02-17 21:33 UTC (permalink / raw)
  To: git

So instead of just making noise, I'll start actually contributing to
git. The first patch here is designed to fix the annoying bug that
when git-clone fails it still leaves the created directory around, (so
that a subsequent git-clone will be guaranteed to fail since the
directory already exists).

The second and third patches provide a new test case for the new
behavior. I had to guess at the number for the new test, since the
distinction of the various numbers in t/README was too vague for me to
know where a git-clone test should go. Feel free to adjust that as
you might see fit.

-Carl

-- 
cworth@redhat.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] Trap exit to clean up created directory if clone fails.
  2006-02-17 21:33 Making git-clone clean up when it fails Carl Worth
@ 2006-02-17 21:33 ` Carl Worth
  2006-02-17 21:33   ` [PATCH 2/3] Abstract test_create_repo out for use in tests Carl Worth
  0 siblings, 1 reply; 4+ messages in thread
From: Carl Worth @ 2006-02-17 21:33 UTC (permalink / raw)
  To: git; +Cc: Carl Worth

Signed-off-by: Carl Worth <cworth@cworth.org>


---

 git-clone.sh |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

589b68168e3dad89238b879b06680c662a99ad8d
diff --git a/git-clone.sh b/git-clone.sh
index e192b08..d184ceb 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -118,6 +118,7 @@ dir="$2"
 [ -e "$dir" ] && echo "$dir already exists." && usage
 mkdir -p "$dir" &&
 D=$(cd "$dir" && pwd) &&
+trap 'err=$?; rm -r $D; exit $err' exit
 case "$bare" in
 yes) GIT_DIR="$D" ;;
 *) GIT_DIR="$D/.git" ;;
@@ -255,3 +256,6 @@ Pull: $head_points_at:$origin" &&
 		git checkout
 	esac
 fi
+
+trap - exit
+
-- 
1.2.0.gf6e8

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] Abstract test_create_repo out for use in tests.
  2006-02-17 21:33 ` [PATCH 1/3] Trap exit to clean up created directory if clone fails Carl Worth
@ 2006-02-17 21:33   ` Carl Worth
  2006-02-17 21:33     ` [PATCH 3/3] New test to verify that when git-clone fails it cleans up the new directory Carl Worth
  0 siblings, 1 reply; 4+ messages in thread
From: Carl Worth @ 2006-02-17 21:33 UTC (permalink / raw)
  To: git; +Cc: Carl Worth

Signed-off-by: Carl Worth <cworth@cworth.org>


---

 t/test-lib.sh |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

6110a439c2b1962c6f128cdaac3a2ee8450ac22c
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7a58a86..66f62b9 100755
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -149,6 +149,21 @@ test_expect_code () {
 	fi
 }
 
+# Most tests can use the created repository, but some amy need to create more.
+# Usage: test_create_repo <directory>
+test_create_repo () {
+	test "$#" = 1 ||
+	error "bug in the test script: not 1 parameter to test-create-repo"
+	owd=`pwd`
+	repo="$1"
+	mkdir "$repo"
+	cd "$repo" || error "Cannot setup test environment"
+	"$GIT_EXEC_PATH/git" init-db --template=$GIT_EXEC_PATH/templates/blt/ 2>/dev/null ||
+	error "cannot run git init-db -- have you built things yet?"
+	mv .git/hooks .git/hooks-disabled
+	cd "$owd"
+}
+	
 test_done () {
 	trap - exit
 	case "$test_failure" in
@@ -196,9 +211,5 @@ test -d ../templates/blt || {
 # Test repository
 test=trash
 rm -fr "$test"
-mkdir "$test"
-cd "$test" || error "Cannot setup test environment"
-"$GIT_EXEC_PATH/git" init-db --template=../../templates/blt/ 2>/dev/null ||
-error "cannot run git init-db -- have you built things yet?"
-
-mv .git/hooks .git/hooks-disabled
+test_create_repo $test
+cd "$test"
-- 
1.2.0.gf6e8

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] New test to verify that when git-clone fails it cleans up the new directory.
  2006-02-17 21:33   ` [PATCH 2/3] Abstract test_create_repo out for use in tests Carl Worth
@ 2006-02-17 21:33     ` Carl Worth
  0 siblings, 0 replies; 4+ messages in thread
From: Carl Worth @ 2006-02-17 21:33 UTC (permalink / raw)
  To: git; +Cc: Carl Worth

Signed-off-by: Carl Worth <cworth@cworth.org>


---

 t/t5600-clone-fail-cleanup.sh |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100755 t/t5600-clone-fail-cleanup.sh

0d8852c105e5f910ba53fc974a5d929a2136aecd
diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh
new file mode 100755
index 0000000..0c6a363
--- /dev/null
+++ b/t/t5600-clone-fail-cleanup.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Copyright (C) 2006 Carl D. Worth <cworth@cworth.org>
+#
+
+test_description='test git-clone to cleanup after failure
+
+This test covers the fact that if git-clone fails, it should remove
+the directory it created, to avoid the user having to manually
+remove the directory before attempting a clone again.'
+
+. ./test-lib.sh
+
+test_expect_failure \
+    'clone of non-existent source should fail' \
+    'git-clone foo bar'
+
+test_expect_failure \
+    'failed clone should not leave a directory' \
+    'cd bar'
+
+# Need a repo to clone
+test_create_repo foo
+
+# clone doesn't like it if there is no HEAD. Is that a bug?
+(cd foo && touch file && git add file && git commit -m 'add file' >/dev/null 2>&1)
+
+test_expect_success \
+    'clone should work now that source exists' \
+    'git-clone foo bar'
+
+test_expect_success \
+    'successfull clone must leave the directory' \
+    'cd bar'
+
+test_done
-- 
1.2.0.gf6e8

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-02-17 21:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-17 21:33 Making git-clone clean up when it fails Carl Worth
2006-02-17 21:33 ` [PATCH 1/3] Trap exit to clean up created directory if clone fails Carl Worth
2006-02-17 21:33   ` [PATCH 2/3] Abstract test_create_repo out for use in tests Carl Worth
2006-02-17 21:33     ` [PATCH 3/3] New test to verify that when git-clone fails it cleans up the new directory Carl Worth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).