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.