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

Using / as a value for a parameter becomes a path after parse_args() in gitbash #4798

Closed
ewongbb opened this issue Feb 8, 2024 · 3 comments

Comments

@ewongbb
Copy link

ewongbb commented Feb 8, 2024

  • [x ] 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 --build-options

git version 2.41.0.windows.3
cpu: x86_64
built form commit:  4a1821dfb0c2160a4fcc85d2845f095c54339578
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?
    Windows 8.1 pro 64 bit (this is also reproducible in Windows 11 using the same version of git-for-windows)
$ cmd.exe /c ver

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

  • What options did you set as part of the installation? Or did you choose the
    defaults?
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
> type "$env:USERPROFILE\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt
Editor Option: VIM
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Merge
Use Credential Manager: Disabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Disabled
Enable FSMonitor: Disabled

  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

Details

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

git bash

import argparse
import sys

def get_options():
    opts = argparse.ArgumentParser(description="get options")
    opts.add_argument("-d",
                                   help="specify dir",
                                   dest="use_dir",
                                   default=None,
                                   type=str)
    return opts.parse_args()


def main():
    opts = get_options()
    if opts.use_dir is not None:
        print("use_dir : %s" % opts.use_dir)
        print(sys.argv)


if __name__ == "__main__":
    main()
  • What did you expect to occur after running these commands?

I expected the following to be printed:

/
['t2.py', '-d', '/']

  • What actually happened instead?
    the following was printed instead:
j:/git/
['t2.py', '-d', 'j:/git/']
@dscho
Copy link
Member

dscho commented Feb 8, 2024

From our Release Notes' "Known Issues" section:

  • If you specify command-line options starting with a slash, POSIX-to-Windows path conversion will kick in converting e.g. "/usr/bin/bash.exe" to "C:\Program Files\Git\usr\bin\bash.exe". When that is not desired -- e.g. "--upload-pack=/opt/git/bin/git-upload-pack" or "-L/regex/" -- you need to set the environment variable MSYS_NO_PATHCONV temporarily, like so:

MSYS_NO_PATHCONV=1 git blame -L/pathconv/ msys2_path_conv.cc

Alternatively, you can double the first slash to avoid POSIX-to-Windows path conversion, e.g. "//usr/bin/bash.exe".

@dscho dscho closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2024
@ewongbb
Copy link
Author

ewongbb commented Feb 8, 2024

My apologies for missing that release note.

@dscho
Copy link
Member

dscho commented Feb 11, 2024

My apologies for missing that release note.

TBH it's easy to miss. If you have any idea how to make these hints easier to find, please mention it here.

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

No branches or pull requests

2 participants