Re: [PATCH 04/18] t1401-symbolic-ref: avoid direct filesystem access
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Apr 22, 2021, 04:59 UTC
- Message-ID
- <20210422045953.GC2947267@szeder.dev>
- In-Reply-To
- <CAFQ2z_MMAM6jZ0+zRi+8fyS69Qw4fKQSsXgQW2zW7tcMdmN=QQ@mail.gmail.com>
On Wed, Apr 21, 2021 at 11:09:07AM +0200, Han-Wen Nienhuys wrote:
Show 15 quoted lines
> > > diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
> > > index a4ebb0b65fec..fd5980d3fb40 100755
> > > --- a/t/t1401-symbolic-ref.sh
> > > +++ b/t/t1401-symbolic-ref.sh
> > > @@ -7,18 +7,13 @@ test_description='basic symbolic-ref tests'
> > > # the git repo, meaning that further tests will operate on
> > > # the surrounding git repo instead of the trash directory.
> > > reset_to_sane() {
> > > - echo ref: refs/heads/foo >.git/HEAD
> > > + git --git-dir .git symbolic-ref HEAD refs/heads/foo
> >
> > Isn't that "--git-dir .git" entirely redundant?
>
> See the comment above the changed line: we don't want auto-detection
> to clobber the surrounding git repo.Indeed, but then this is not a faithful conversion of the original. That 'echo' will write sane content to HEAD no matter what state the repository is in. That 'symbolic-ref' command, however, won't, because 'git --git-dir .git' turns off only repository discovery, but not repository verification, and in case of a corrupt '.git/HEAD' it will bail out.
$ cd test $ git init Initialized empty Git repository in /home/szeder/src/git/test/.git/ $ git commit --allow-empty -m initial [master (root-commit) ec0df0b] initial $ echo "foo bar baz" >.git/HEAD $ git --git-dir .git symbolic-ref HEAD refs/heads/master fatal: not a git repository: '.git'