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

Fix subtree on Windows #3264

Merged
merged 2 commits into from
Jul 5, 2021
Merged

Conversation

dscho
Copy link
Member

@dscho dscho commented Jun 9, 2021

This fixes #3260.

@dscho dscho mentioned this pull request Jun 9, 2021
1 task
@dscho dscho requested a review from rimrul June 9, 2021 19:53
@dscho
Copy link
Member Author

dscho commented Jun 10, 2021

GitGitGadget companion: gitgitgadget#978.

In 22d5507 (subtree: don't fuss with PATH, 2021-04-27), `git
subtree` was broken thoroughly on Windows.

The reason is that it assumes Unix semantics, where `PATH` is
colon-separated, and it assumes that `$GIT_EXEC_PATH:` is a verbatim
prefix of `$PATH`. Neither are true, the latter in particular because
`GIT_EXEC_PATH` is a Windows-style path, while `PATH` is a Unix-style
path list.

Let's make extra certain that `$GIT_EXEC_PATH` and the first component
of `$PATH` refer to different entities before erroring out.

We do that by using the `test <path1> -ef <path2>` command that verifies
that the inode of `<path1>` and of `<path2>` is the same.

Sadly, this construct is non-portable, according to
https://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html.
However, it does not matter in practice because we still first look
whether `$GIT_EXEC_PREFIX` is string-identical to the first component of
`$PATH`. This will give us the expected result everywhere but in Git for
Windows, and Git for Windows' own Bash _does_ handle the `-ef` operator.

Just in case that we _do_ need to show the error message _and_ are
running in a shell that lacks support for `-ef`, we simply suppress the
error output for that part.

This fixes git-for-windows#3260

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
On Windows, both forward and backslash are valid separators. In
22d5507 (subtree: don't fuss with PATH, 2021-04-27), however, we
added code that assumes that it can only be the forward slash.

Let's fix that.

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

dscho commented Jul 5, 2021

This topic has finally advanced to upstream's next branch.

@dscho dscho merged commit ef510a3 into git-for-windows:main Jul 5, 2021
@dscho dscho added this to the Next release milestone Jul 5, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 5, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 5, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 5, 2021
dscho added a commit that referenced this pull request Jul 5, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 6, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 6, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 6, 2021
@dscho dscho deleted the fix-subtree-on-windows branch July 9, 2021 04:34
dscho added a commit that referenced this pull request Jul 10, 2021
dscho added a commit that referenced this pull request Jul 10, 2021
dscho added a commit that referenced this pull request Jul 14, 2021
dscho added a commit that referenced this pull request Jul 14, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 15, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 15, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 19, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 19, 2021
dscho added a commit that referenced this pull request Jul 19, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 21, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 22, 2021
dscho added a commit that referenced this pull request Jul 23, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 24, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 24, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 24, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 26, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 28, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 28, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 29, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 29, 2021
git-for-windows-ci pushed a commit that referenced this pull request Jul 29, 2021
dscho added a commit that referenced this pull request Aug 2, 2021
git-for-windows-ci pushed a commit that referenced this pull request Aug 2, 2021
git-for-windows-ci pushed a commit that referenced this pull request Aug 2, 2021
git-for-windows-ci pushed a commit that referenced this pull request Aug 2, 2021
git-for-windows-ci pushed a commit that referenced this pull request Aug 2, 2021
git-for-windows-ci pushed a commit that referenced this pull request Aug 2, 2021
dscho added a commit that referenced this pull request Aug 3, 2021
dscho added a commit that referenced this pull request Aug 11, 2021
dscho added a commit that referenced this pull request Aug 13, 2021
dscho added a commit that referenced this pull request Aug 18, 2021
dscho added a commit that referenced this pull request Aug 23, 2021
git-for-windows-ci pushed a commit that referenced this pull request Aug 24, 2021
@r-ryabyy
Copy link

r-ryabyy commented Aug 17, 2022

I still have issues on Windows

$ git --version
git version 2.37.2.windows.2

I'm using a bash (git bash) and there are multiple cases where the issue reproduces.

Case 1
System PATH contains "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
user PATH doesn't contain "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
GIT_EXEC_PATH is not exist.

a) from bash terminal command "git subtree" results correctly
b) when i run shell.exec('git subtree') from npm task end up with:

It looks like either your git installation or your
git-subtree installation is broken.

Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;).
  • You should run git-subtree as git subtree,
    not as git-subtree.

Case 2
System PATH doesn't contain "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
user PATH doesn't contain "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
GIT_EXEC_PATH is not exist.

a) from bash terminal command "git subtree" results correctly
b) when i run shell.exec('git subtree') from npm task end up with:

It looks like either your git installation or your
git-subtree installation is broken.

Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:/Program Files/Git/mingw64/libexec/git-core).
  • You should run git-subtree as git subtree,
    not as git-subtree.

Case 3
System PATH doesn't contain "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
user PATH contains "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
GIT_EXEC_PATH is not exist.

a) from bash terminal command "git subtree" results correctly
b) when i run shell.exec('git subtree') from npm task end up with:

It looks like either your git installation or your
git-subtree installation is broken.

Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:/Program Files/Git/mingw64/libexec/git-core).
  • You should run git-subtree as git subtree,
    not as git-subtree.

Case 4
System PATH doesn't contain "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
user PATH doesn't contain "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
GIT_EXEC_PATH contains "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"

a) from bash terminal command "git subtree" end up with:

It looks like either your git installation or your
git-subtree installation is broken.

Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;).
  • You should run git-subtree as git subtree,
    not as git-subtree.

b) when i run shell.exec('git subtree') from npm task end up with:

It looks like either your git installation or your
git-subtree installation is broken.

Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;).
  • You should run git-subtree as git subtree,
    not as git-subtree.

Case 5
System PATH doesn't contain "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
user PATH contains "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"
GIT_EXEC_PATH contains "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"

a) from bash terminal command "git subtree" end up with:

It looks like either your git installation or your
git-subtree installation is broken.

Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;).
  • You should run git-subtree as git subtree,
    not as git-subtree.

b) when i run shell.exec('git subtree') from npm task end up with:

It looks like either your git installation or your
git-subtree installation is broken.

Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;).
  • You should run git-subtree as git subtree,
    not as git-subtree.

And the cherry on the pie - almost in all use cases Windows Powershell executes all commands correctly (both in shell and inside npm task)

Any thoughts ?

@dscho
Copy link
Member Author

dscho commented Aug 18, 2022

b) when i run shell.exec('git subtree') from npm task end up with:

It looks like either your git installation or your
git-subtree installation is broken.
Tips:

  • If git --exec-path does not print the correct path to
    your git install directory, then set the GIT_EXEC_PATH
    environment variable to the correct directory.
  • Make sure that your git-subtree file is either in your
    PATH or in your git exec path (C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;).
  • You should run git-subtree as git subtree,
    not as git-subtree.

That error message comes from here.

If I were you, I would edit C:\Program Files\Git\mingw64\libexec\git-core\git-subtree and insert a set -x after the first line, and potentially also echo "$GIT_EXEC_PATH" and similar debug print statements, then try to run it again to diagnose this further, then iterate on that until I know what exactly is going wrong.

@dscho
Copy link
Member Author

dscho commented Aug 18, 2022

System PATH contains "C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\libexec\git-core;"

Please note that it is recommended to add C:\Program Files\Git\cmd and no other directory from within C:\Program Files\Git, as the exact names and locations of those files are implementation details and hence subject to change. The only guarantee is that C:\Program Files\Git\cmd\git.exe will work.

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

Successfully merging this pull request may close these issues.

git-subtree installation is broken
6 participants