From: Junio C Hamano Date: Wed, 26 Nov 2014 21:55:02 GMT Subject: Re: [PATCH v4] git-new-workdir: Don't fail if the target directory is empty Message-ID: In-Reply-To: <1417034308.23650.51.camel@homebase> Paul Smith writes: > 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 > --- > > 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? > -# 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.