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

Re: [PATCH v4] git-new-workdir: Don't fail if the target directory is empty

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 26, 2014, 21:55 UTC
Message-ID
<xmqq8uixpqyx.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1417034308.23650.51.camel@homebase>
Paul Smith <paul@mad-scientist.net> writes:
Show 7 quoted lines
> Allow new workdirs to be created in an empty directory (similar to "git
> clone").  Provide more error checking and clean up on failure.
>
> Signed-off-by: Paul Smith <paul@mad-scientist.net>
> ---
>
> Hopefully this doesn't contain unwanted stylistic changes.
;-)
Unwanted, no, but unrelated yes.
>  
> +failed () {
> +	die "unable to create new workdir \"$new_workdir\"!"
> +}
Use '$new_workdir' instead to match the existing message below?
Show 17 quoted lines
> -# don't recreate a workdir over an existing repository
> -if test -e "$new_workdir"
> +# make sure the links in the workdir have full paths to the original repo
> +git_dir=$(cd "$git_dir" && pwd) || exit 1
> +
> +# don't recreate a workdir over an existing directory, unless it's empty
> +if test -d "$new_workdir"
>  then
> -	die "destination directory '$new_workdir' already exists."
> +	if test $(ls -a1 "$new_workdir/." | wc -l) -ne 2
> +	then
> +		die "destination directory '$new_workdir' is not empty."
> +	fi
> +	cleandir="$new_workdir/.git"
> +else
> +	cleandir="$new_workdir"
>  fi

The comment in the original is somewhat misleading, but "test -e" was "test -e" and not "test -d" to stop when an existing file was given by mistake as $new_workdir, I think. I do not know what happens in the new code in that case.

Previous: Paul SmithNext: Paul Smith
Message 2 of 6 in “git-new-workdir: Don't fail if the target directory is empty”
  1. git-new-workdir: Don't fail if the target directory is emptyPaul Smith, Nov 26, 2014
  2. Junio C HamanoNov 26, 2014
  3. Paul SmithNov 26, 2014
  4. Junio C HamanoNov 26, 2014
  5. Paul SmithNov 28, 2014
  6. Paul SmithDec 10, 2014

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.