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

Gitbash terminal not opening to workspace folder. #23382

Open
dmurphyinsaas opened this issue May 8, 2024 · 24 comments
Open

Gitbash terminal not opening to workspace folder. #23382

dmurphyinsaas opened this issue May 8, 2024 · 24 comments
Assignees
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@dmurphyinsaas
Copy link

Type: Bug

Behaviour

When I open a Gitbash terminal window, rather than the path being set to current workspace directory as before, it is being set to some
C:/Users/myuser/AppData/Local/Programs/Microsoft VS Code path and it appears some venv is active.

Steps to reproduce:

  1. Create new Folder and open this folder in VS code
  2. Open Gitbash terminal window (Opens to workspace folder as expected)
  3. Create venv python -m venv venv
  4. Create a python file touch main.py
  5. Open this file from VS Code file explorer.
  6. Terminal name turns yellow and on hover there is link to relaunch, click this relaunch terminal link.
  7. Terminal relaunches, this time some venv is activated and the path is set to C:/Users/myuser/AppData/Local/Programs/Microsoft VS Code

Diagnostic data

launch.json configuration

no launch.json

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

2024-05-08 11:58:29.486 [info] Experiment 'pythonaacf' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonCreateEnvOnPipInstall' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonREPLSmartSend' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-05-08 11:58:29.486 [info] Experiment 'pythonTestAdapter' is active
2024-05-08 11:58:29.486 [info] Default formatter is set to null for workspace c:\Temp\TestVS3
2024-05-08 11:58:29.486 [info] > hatch env show --json
2024-05-08 11:58:29.486 [info] cwd: .
2024-05-08 11:58:29.486 [info] Python interpreter path: ~\.pyenv\pyenv-win\versions\3.11.3\python.exe
2024-05-08 11:58:29.533 [info] > conda info --json
2024-05-08 11:58:29.567 [info] > ~\.pyenv\pyenv-win\versions\3.11.3\python.exe -I ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\interpreterInfo.py
2024-05-08 11:58:29.601 [info] > .\venv\Scripts\python.exe -I ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\interpreterInfo.py
2024-05-08 11:58:29.788 [info] > ~\.pyenv\pyenv-win\bin\pyenv which python
2024-05-08 11:58:29.788 [info] cwd: .
2024-05-08 11:58:30.316 [info] > . ./venv/Scripts/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.7.11291009/python_files/printEnvVariables.py
2024-05-08 11:58:30.316 [info] shell: bash
2024-05-08 11:58:30.498 [info] > ~\.pyenv\pyenv-win\versions\3.10.11\python.exe ~/.vscode/extensions/ms-python.python-2024.7.11291009/python_files/printEnvVariables.py
2024-05-08 11:58:30.498 [info] shell: bash
2024-05-08 11:58:30.591 [info] Setting environment variable MSYS in collection to disable_pcon disable_pcon {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Prepending environment variable PATH in collection with c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash;C;C:\Temp\TestVS3\venv\Scripts;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\asus\bin; {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Prepending environment variable PS1 in collection with (venv)  {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-05-08 11:58:30.591 [info] Setting environment variable PWD in collection to C:/Users/asus/AppData/Local/Programs/Microsoft VS Code {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable PYTHONIOENCODING in collection to utf-8 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable PYTHONUNBUFFERED in collection to 1 {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable VIRTUAL_ENV in collection to C:\Temp\TestVS3\venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.591 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (venv)  {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-05-08 11:58:30.592 [info] Send text to terminal: C:/Users/asus/.pyenv/pyenv-win/versions/3.10.11/python.exe c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\printEnvVariablesToFile.py c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash\envVars.txt
2024-05-08 11:58:31.789 [info] Starting Pylance language server.
2024-05-08 11:58:31.941 [info] Python interpreter path: c:\Temp\TestVS3\venv\Scripts\python.exe
2024-05-08 11:59:00.599 [error] Failed to initialize deactivate script C:\Program Files\Git\bin\bash.exe Error: "c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash\envVars.txt" file not created
    at Timeout.<anonymous> (c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\out\client\extension.js:2:273765)
    at listOnTimeout (node:internal/timers:569:17)
    at processTimers (node:internal/timers:512:7)

Output for Python Debugger in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python Debugger)

2024-05-08 11:58:29.522 [info] Name: Python Debugger
2024-05-08 11:58:29.523 [info] Module: debugpy

Extension version: 2024.7.11291009
VS Code version: Code 1.89.0 (b58957e67ee1e712cebf466b995adf4c5307b2bd, 2024-05-01T02:09:22.859Z)
OS version: Windows_NT x64 10.0.22631
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.3
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

Installed Extensions
Extension Name Extension Id Version
.NET Install Tool ms-dotnettools.vscode-dotnet-runtime 2.0.5
C# ms-dotnettools.csharp 2.28.11
ChatGPT - Genie AI genieai.chatgpt-vscode 0.0.10
Code Spell Checker streetsidesoftware.code-spell-checker 3.0.1
Dev Containers ms-vscode-remote.remote-containers 0.362.0
Docker ms-azuretools.vscode-docker 1.29.1
DotENV mikestead.dotenv 1.0.1
Draw.io Integration hediet.vscode-drawio 1.6.6
Git History donjayamanne.githistory 0.6.20
GitHub Actions github.vscode-github-actions 0.26.2
GitHub Copilot GitHub.copilot 1.187.0
GitHub Copilot Chat GitHub.copilot-chat 0.15.0
GitHub Pull Requests GitHub.vscode-pull-request-github 0.88.0
GitLens — Git supercharged eamodio.gitlens 14.9.1
IntelliCode VisualStudioExptTeam.vscodeintellicode 1.3.1
IntelliCode API Usage Examples VisualStudioExptTeam.intellicode-api-usage-examples 0.2.8
JavaScript Debugger ms-vscode.js-debug 1.89.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.2
Jupyter ms-toolsai.jupyter 2024.4.0
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.17
Jupyter Slide Show ms-toolsai.vscode-jupyter-slideshow 0.1.6
Mocha sidebar maty.vscode-mocha-sidebar 0.22.2
Pylance ms-python.vscode-pylance 2024.5.1
Python ms-python.python 2024.7.11291009
Python Debugger ms-python.debugpy 2024.6.0
Rainbow CSV mechatroner.rainbow-csv 3.11.0
Swagger Viewer Arjun.swagger-viewer 3.1.2
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
Test Adapter Converter ms-vscode.test-adapter-converter 0.1.9
Test Explorer UI hbenl.vscode-test-explorer 2.21.1
vscode-pdf tomoki1207.pdf 1.2.2
WSL ms-vscode-remote.remote-wsl 0.88.2
YAML redhat.vscode-yaml 1.14.0
System Info
Item Value
CPUs AMD Ryzen 5 5500U with Radeon Graphics (12 x 2096)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 15.38GB (3.25GB free)
Process Argv --folder-uri file:///c%3A/Users/asus/Documents/github/insaas/insaas-notebooks-experiments --crash-reporter-id a9eaff0c-8dbb-48f1-a524-0a5dc444f644
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vstes627:30244334
vscoreces:30445986
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
h48ei257:31000450
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
chatpanelt:31018789
dsvsc021:30996838
01bff139:31013167
pythoncenvptcf:31039767
dwnewjupyter:31039675

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 8, 2024
@anthonykim1 anthonykim1 self-assigned this May 8, 2024
@anthonykim1
Copy link

Hello @dmurphyinsaas Thanks for filing the issue.
Is gitbash set as your default terminal profile? If so, try switching the default to something else like pwsh,bash, etc
Potentially related: #22910 #23008

@anthonykim1 anthonykim1 added area-terminal and removed triage-needed Needs assignment to the proper sub-team labels May 8, 2024
@github-actions github-actions bot added the info-needed Issue requires more information from poster label May 8, 2024
@dmurphyinsaas
Copy link
Author

Thank you for your response.
Yes, I do have gitbash as my default terminal profile. When I change the default profile to pwsh, then I can open bash terminals and they are at the workspace folder path.
This has only been an issue in the past week. Do you guys know the cause ? Is there likely to be a fix ? TIA

@dmurphyinsaas dmurphyinsaas reopened this May 10, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 10, 2024
@hiderline
Copy link

I faced the same problem 3 days ago, after upgrade ms-python from v2024.4.1 to 2024.6.0
Rollback to previous version didn't help. I use git bash and venv as well.
Next day after upgrade, after project opening, there shown some venv is activated and the path is set to

(venv)
user@DESKTOP-NAME MINGW64 C:/Users/userName/AppData/Local/Programs/Microsoft VS Code

'which python' command said that global python is used
print(sys.prefix) - said that project's (venv) is used/activated
but 'pip list' command shows again on global environment
if I run simple script - there shown, that python from (venv) was used.

deactivate command gives following result:
grep: /c/Users/{userName}/.vscode/extensions/ms-python.python-2024.6.0/python_files/deactivate/bash/envVars.txt: No such file or directory - shown triple times and strange (venv) is deactivated then and jumps directly to proper project directory:

user@DESKTOP-NAME MINGW64 C:/Project/Folder
Then after I can activate/deactivate project properly.

By the way, if during terminal start-up or relaunch, when strange (venv) is active, I go 'cd c:/Project/Folder' and try to activate proper project's (venv), than I get 2 (venv) activated! As following:

(venv) (venv)
user@DESKTOP-NAME MINGW64 C:/Users/userName/AppData/Local/Programs/Microsoft VS Code

@oribay-iker
Copy link

Same here, Git Bash with a venv that worked just fine until a couple of weeks ago. In my case I had manually set up a cd to specific folder in bash.bashrc located in "C:\Program Files\Git\etc".

The cd works, if I run pwd I can see i'm in the correct location, but the command prompt of git bash says "C:\Program Files\Microsoft VS Code"

@Okhnovsky
Copy link

Okhnovsky commented May 20, 2024

Hi everyone!
I had the same problem. My git bash was opening to "C:/Users/userName/AppData/Local/Programs/Microsoft VS Code" with active venv.
Its happened after update python extensions to 2024.6.0
To solve this problem you should to do this in VS Code:

  • ctrl + shift + P
  • Terminal: Configure Terminal Settings

  • Scroll down until "Shell Integration"
    image
  • And remove tick

Kill your terminal and launch a new one

@anthonykim1
Copy link

Hello everyone, thanks for looking into this issue. Please note that Gitbash is not currently officially supported by Python extension, so please consider switching your default terminal to other such as cmd, bash, zsh, etc Reference: #22908 We may support Gitbash once we have more time/bandwidth in doing so.

@griffinator76
Copy link

@anthonykim1 Gitbash has been the standard terminal everywhere I have worked using VS Code so it's surprising to hear you don't support this.

@anthonykim1
Copy link

@griffinator76 Yes, it seems pretty obvious how many people want proper Gitbash support, so I will be bringing this up to the team.

@monk-time
Copy link

@anthonykim1 I assumed after VSCode v1.89 enabled shell integration for Git Bash this meant it would become fully supported in the extension too?

I really hope the team would reconsider. I don't know if you have any metrics around this but I expect Git Bash to be the most common shell on Windows, which makes it really strange that it is not properly supported. The UX using it with the Python extension is quite miserable too, with many glitches around venv activation: "Re-activating terminals" taking a long time, sometimes the "(venv)" label is missing, sometimes it is not activated properly or cannot be deactivated cleanly. There have been many issues filed here about those problems but almost all of them got dismissed.

@ZdravekSprite
Copy link

It's a little annoying, but it's incorrect that bash opens the wrong folder. True, at the beginning of the prompt, instead of the current folder, it shows the path to the folder where the vs code is installed (which is the annoying part), but bash itself is opened in the folder where it should be. You can check with a simple ls. The problem is only in the wrong representation.
A quick solution is to just enter a folder and exit (eg cd venv cd ..)

@gabrieljreed
Copy link

@ZdravekSprite I've found that I can actually just do cd . and it refreshes properly!

@NeerajKrGoswami
Copy link

Yes cd . works for me too, but it needs to be fixed.

@TheSylvester
Copy link

@ZdravekSprite I've found that I can actually just do cd . and it refreshes properly!

Thank you! This is much faster than disabling Shell Integration and having to source .venv/Scripts/activate every damned time... cd . is much faster...

super weird that it's just reading the wrong string for the directory, and only initially...

@shivamjagdishsingh
Copy link

Hi everyone! I had the same problem. My git bash was opening to "C:/Users/userName/AppData/Local/Programs/Microsoft VS Code" with active venv. Its happened after update python extensions to 2024.6.0 To solve this problem you should to do this in VS Code:

  • ctrl + shift + P
  • Terminal: Configure Terminal Settings

  • Scroll down until "Shell Integration"
    image
  • And remove tick

Kill your terminal and launch a new one

Worked for me. Thank you. Will update if issue persists.

@TheSylvester
Copy link

TheSylvester commented Jul 4, 2024 via email

@nobleknightt
Copy link

I am also facing the same issue. Turning off the Shell Integration did solved the path issue, but the environment prompt still remains even though environment is not active.

@nobleknightt
Copy link

Did anyone know how use Bash/Zsh on Windows (other than GitBash)?

@sohenze
Copy link

sohenze commented Aug 3, 2024

Facing the same issue here as well, turning off Shell Integration seems to have fixed it. I had this on my other PC a few months ago and I somehow got it to go away without turning off Shell Integration but I am unable to replicate that behaviour on my current PC despite copying all settings

@jingjingan
Copy link

same issue

Copy link

Hey @anthonykim1, this issue might need further attention.

@dmurphyinsaas, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@dmurphyinsaas
Copy link
Author

Hi @anthonykim1

I have been working with that "Shell Integration" option disabled as per @Okhnovsky post above.

If I re-enable that option and perform the steps in my original post, I can still see the issue with the path showing as

C:/Users/myuser/AppData/Local/Programs/Microsoft VS Code after re-launching the terminal.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Sep 30, 2024
@anthonykim1
Copy link

Thanks everyone for the input. Does the problem persist even after disabling Python extension?
If you disable Python extension, restart extensions, reload VS Code and open gitbash terminal, I'm curious what the PS1 (or your prompt) looks like

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Dec 10, 2024
@monk-time
Copy link

monk-time commented Dec 10, 2024

@anthonykim1 No, only when the Python extension is active.

  1. Disabled the extension, killed the terminal, restarted VS Code. Git Bash started in the workspace folder as expected.
Screenshot

Image

  1. Re-enabled the extension. Almost immediately the terminal reloaded by itself and showed a broken prompt with the path of my VS Code installation. Restarting VS Code shows the same broken prompt. As usual, cd . fixes the prompt.
Screenshot

Image

@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Dec 19, 2024
@WimYedema
Copy link

To avoid the cd . you can add declare -r PROMPT_COMMAND="cd .; __vsc_prompt_cmd" to your .bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-terminal bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests