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

Re: [PATCH 4/4] clone: do not clean up directories we didn't create

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 4, 2018, 23:48 UTC
Message-ID
<xmqq7esxdw2x.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20180102211139.GD22556@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 45 quoted lines
> diff --git a/builtin/clone.c b/builtin/clone.c
> index 04b0d7283f..284651797e 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -502,12 +504,12 @@ static void remove_junk(void)
>  
>  	if (junk_git_dir) {
>  		strbuf_addstr(&sb, junk_git_dir);
> -		remove_dir_recursively(&sb, 0);
> +		remove_dir_recursively(&sb, junk_git_dir_flags);
>  		strbuf_reset(&sb);
>  	}
>  	if (junk_work_tree) {
>  		strbuf_addstr(&sb, junk_work_tree);
> -		remove_dir_recursively(&sb, 0);
> +		remove_dir_recursively(&sb, junk_work_tree_flags);
>  	}
>  	strbuf_release(&sb);
>  }
> @@ -972,14 +974,24 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  		if (safe_create_leading_directories_const(work_tree) < 0)
>  			die_errno(_("could not create leading directories of '%s'"),
>  				  work_tree);
> -		if (!dest_exists && mkdir(work_tree, 0777))
> +		if (dest_exists)
> +			junk_work_tree_flags |= REMOVE_DIR_KEEP_TOPLEVEL;
> +		else if (mkdir(work_tree, 0777))
>  			die_errno(_("could not create work tree dir '%s'"),
>  				  work_tree);
>  		junk_work_tree = work_tree;
>  		set_git_work_tree(work_tree);
>  	}
>  
> -	junk_git_dir = real_git_dir ? real_git_dir : git_dir;
> +	if (real_git_dir) {
> +		if (dir_exists(real_git_dir))
> +			junk_git_dir_flags |= REMOVE_DIR_KEEP_TOPLEVEL;
> +		junk_git_dir = real_git_dir;
> +	} else {
> +		if (dest_exists)
> +			junk_git_dir_flags |= REMOVE_DIR_KEEP_TOPLEVEL;
> +		junk_git_dir = git_dir;
> +	}
>  	if (safe_create_leading_directories_const(git_dir) < 0)
>  		die(_("could not create leading directories of '%s'"), git_dir);
The changes all look reasonable.
Thanks.
Previous: Junio C Hamano
Message 16 of 16 in “Git removes existing folder when cancelling clone”
  1. Stephan JanssenJan 2, 2018
  2. Robert P. J. DayJan 2, 2018
  3. Jeff KingJan 2, 2018
  4. 0/4 Git removes existing folder when cancelling cloneJeff King, Jan 2, 2018
  5. 1/4 t5600: fix outdated comment about unborn HEADJeff King, Jan 2, 2018
  6. 2/4 t5600: modernize styleJeff King, Jan 2, 2018
  7. 3/4 clone: factor out dir_exists() helperJeff King, Jan 2, 2018
  8. Junio C HamanoJan 4, 2018
  9. Jeff KingJan 4, 2018
  10. Jeff KingJan 5, 2018
  11. Junio C HamanoJan 5, 2018
  12. 4/4 clone: do not clean up directories we didn't createJeff King, Jan 2, 2018
  13. Eric SunshineJan 2, 2018
  14. Jeff KingJan 2, 2018
  15. Junio C HamanoJan 5, 2018
  16. Junio C HamanoJan 4, 2018

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.