git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] Trap exit to clean up created directory if clone fails.

From
Carl Worth <cworth@cworth.org>
Date
Feb 17, 2006, 21:33 UTC
Message-ID
<11402120042011-git-send-email-cworth@cworth.org>
In-Reply-To
<11402120031687-git-send-email-cworth@cworth.org>
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
Previous: Carl WorthNext: Carl Worth
Message 2 of 4 in “Making git-clone clean up when it fails”
  1. Carl WorthFeb 17, 2006
  2. 1/3 Trap exit to clean up created directory if clone fails.Carl Worth, Feb 17, 2006
  3. 2/3 Abstract test_create_repo out for use in tests.Carl Worth, Feb 17, 2006
  4. 3/3 New test to verify that when git-clone fails it cleans up the new directory.Carl Worth, Feb 17, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.