Re: [PATCH v2 2/2] checkout: fix regression in checkout -b on intitial checkout
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 22, 2019, 14:35 UTC
- Message-ID
- <nycvar.QRO.7.76.6.1901221529210.41@tvgsbejvaqbjf.bet>
- In-Reply-To
- <20190121195008.8700-3-peartben@gmail.com>
Hi,
On Mon, 21 Jan 2019, Ben Peart wrote:
Show 13 quoted lines
> diff --git a/builtin/checkout.c b/builtin/checkout.c > index 6fadf412e8..9c6e94319e 100644 > --- a/builtin/checkout.c > +++ b/builtin/checkout.c > @@ -592,6 +592,13 @@ static int skip_merge_working_tree(const struct checkout_opts *opts, > * Remaining variables are not checkout options but used to track state > */ > > + /* > + * Do the merge if this is the initial checkout > + * > + */ > + if (!file_exists(get_index_file()))
We had a little internal discussion whether to use `access()` or `file_exists()`, and I was pretty strongly in favor of `file_exists()` because it says what we care about.
And when I looked, I found quite a few callers to `access()` that look like they simply want to test whether a file exists.
I also looked at the implementation of `file_exists()` and found that it uses `lstat()`. Peff, you introduced this (using `stat()`) in c91f0d92efb3 (git-commit.sh: convert run_status to a C builtin, 2006-09-08), could you enlighten me why you chose `stat()` over `access()` (the latter seems more light-weight to me)? Also, Junio, you changed it to use `lstat()` in a50f9fc5feb0 (file_exists(): dangling symlinks do exist, 2007-11-18), do you think we can/should use `access()` instead?
Thanks, Dscho
Show 22 quoted lines
> + return 0; > + > return 1; > } > > diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh > index 6da2d4e68f..c5014ad9a6 100755 > --- a/t/t2018-checkout-branch.sh > +++ b/t/t2018-checkout-branch.sh > @@ -198,7 +198,7 @@ test_expect_success 'checkout -B to the current branch works' ' > test_dirty_mergeable > ' > > -test_expect_failure 'checkout -b after clone --no-checkout does a checkout of HEAD' ' > +test_expect_success 'checkout -b after clone --no-checkout does a checkout of HEAD' ' > git init src && > test_commit -C src a && > rev="$(git -C src rev-parse HEAD)" && > -- > 2.19.1.gvfs.1.16.g9d1374d > >