Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing git <cmd> -h crashes if git doesn't run inside a reporsitory #3688

Closed
1 task done
dodmi opened this issue Feb 7, 2022 · 3 comments
Closed
1 task done

Comments

@dodmi
Copy link

dodmi commented Feb 7, 2022

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
git version 2.35.1.windows.2
cpu: x86_64
built from commit: 5437f0fd368c7faf1a0b5e1fef048232c1f2a3e6
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
Microsoft Windows [Version 10.0.19044.1466]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
I'm using MinGit busybox without installer
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

Not in my environment. But the problem didn't occur with MinGit 2.34.1 busybox (2.34.1.windows.1)
The problem started with version 2.35.0

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

PowerShell 5

With the commands checkout, fetch, pull, restore, switch, pack-objects, run OUTSIDE of a repository:
git <command> -h 

e.g. git switch -h
  • What did you expect to occur after running these commands?

The help for the corresponding command should be displayerd

  • What actually happened instead?

git crashes with error:
BUG: repo-settings.c:23: Cannot add settings for uninitialized repository

  • If the problem was occurring with a specific repository, can you provide the
    URL to that repository to help us with testing?

** insert URL here **

@dscho
Copy link
Member

dscho commented Feb 7, 2022

I'm using MinGit busybox without installer

It also happens with a regular install.

As a matter of fact, it even happens with a Linux version of Git.

dscho added a commit to dscho/git that referenced this issue Feb 7, 2022
When we taught these commands about the sparse index, we did not account
for the fact that the `cmd_*()` functions _can_ be called without a
gitdir, namely when `-h` is passed to show the usage.

This fixes git-for-windows#3688

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/git that referenced this issue Feb 7, 2022
When we taught these commands about the sparse index, we did not account
for the fact that the `cmd_*()` functions _can_ be called without a
gitdir, namely when `-h` is passed to show the usage.

A plausible approach to address this is to move the
`prepare_repo_settings()` calls right after the `parse_options()` calls:
The latter will never return when it handles `-h`, and therefore it is
safe to assume that we have a `gitdir` at that point, as long as the
built-in is marked with the `RUN_SETUP` flag.

However, it is unfortunately not that simple. In `cmd_pack_objects()`,
for example, the repo settings need to be fully populated so that the
command-line options `--sparse`/`--no-sparse` can override them, not the
other way round.

Therefore, we choose to imitate the strategy taken in `cmd_diff()`,
where we simply do not bother to prepare and initialize the repo
settings unless we have a `gitdir`.

This fixes git-for-windows#3688

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Member

dscho commented Feb 7, 2022

I opened gitgitgadget#1139 and plan on sending it to the Git mailing list as soon as the PR build gives me confidence in addition to the passing test suite on my machine.

dscho added a commit to dscho/git that referenced this issue Feb 8, 2022
When we taught these commands about the sparse index, we did not account
for the fact that the `cmd_*()` functions _can_ be called without a
gitdir, namely when `-h` is passed to show the usage.

A plausible approach to address this is to move the
`prepare_repo_settings()` calls right after the `parse_options()` calls:
The latter will never return when it handles `-h`, and therefore it is
safe to assume that we have a `gitdir` at that point, as long as the
built-in is marked with the `RUN_SETUP` flag.

However, it is unfortunately not that simple. In `cmd_pack_objects()`,
for example, the repo settings need to be fully populated so that the
command-line options `--sparse`/`--no-sparse` can override them, not the
other way round.

Therefore, we choose to imitate the strategy taken in `cmd_diff()`,
where we simply do not bother to prepare and initialize the repo
settings unless we have a `gitdir`.

This fixes git-for-windows#3688

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dodmi
Copy link
Author

dodmi commented Feb 9, 2022

Thank you very much for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants