threads / bug / 58286

Bug: Git-Alias is callable from outside a git repo

Subject: Bug: Git-Alias is callable from outside a git repo

## tl;dr

3 messages between Aug 10, 2022 and Aug 12, 2022.

replies: 2people: 3as markdown or json

Niklas· Aug 10, 2022, 17:03 UTC · lore
Steps to reproduce:
1. Having the following global .gitconfig
[alias]
     f = "!echo "test""
2. Calling `git f` in a folder which does not belong to a git repo
Expected Behavior: 

Seeing some message like like `fatal: not a git repository (or any parent up to mount point /)`

Actual Behavior:
Prints "test"
Git 2.37.1 under Arch Linux
rsbecker@nexbridge.com· Aug 10, 2022, 19:14 UTC · re: Niklas · lore

RE: Git-Alias is callable from outside a git repo

On August 10, 2022 1:03 PM, Niklas wrote:
Show 19 quoted lines
>Steps to reproduce:
>
>1. Having the following global .gitconfig
>
>[alias]
>     f = "!echo "test""
>
>2. Calling `git f` in a folder which does not belong to a git repo
>
>Expected Behavior:
>
>Seeing some message like like
>`fatal: not a git repository (or any parent up to mount point /)`
>
>Actual Behavior:
>
>Prints "test"
>
>Git 2.37.1 under Arch Linux

I do not think this is a bug. There are git commands that do not require repositories, like git version. Git has know knowledge of what your alias is going to do without executing it. If your alias wanted to run git version or git hash-object, it would not need a repository to do so. --Randall

Johannes Schindelin· Aug 12, 2022, 21:09 UTC · re: Niklas · lore

Re: Bug: Git-Alias is callable from outside a git repo

Hi Niklas,
On Wed, 10 Aug 2022, Niklas wrote:
Show 6 quoted lines
> Steps to reproduce:
>
> 1. Having the following global .gitconfig
>
> [alias]
>     f = "!echo "test""
That quoting is a big bogus.
Show 10 quoted lines
>
> 2. Calling `git f` in a folder which does not belong to a git repo
>
> Expected Behavior:
> Seeing some message like like
> `fatal: not a git repository (or any parent up to mount point /)`
>
> Actual Behavior:
>
> Prints "test"

This is by design, and definitely not a bug. It even allows you to build relatively complex aliases that work on multiple worktrees, or even no worktree at all.

Why would a Git alias have to be bound to any specific Git repository?

Ciao, Johannes

← back to recent threads