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

Creating batch script to start Git-SDK, is it possible to specify a specific $HOME directory? #736

Closed
EdenWise opened this issue Apr 19, 2016 · 19 comments
Labels

Comments

@EdenWise
Copy link

Setup

  • Type: Git-SDK 32 bit and up to date
  • Git: git version 2.8.0
  • Windows 7 32 bit

Details

  • Bash

Question

I am trying to create a batch script to start start_shell.cmd with a specific (i.e. alternate $HOME directory). Is this possible to do? Here is my script:

:
@echo off

set HOMEDRIVE=%cd:~0,2%
set HOMEPATH=\
set HOME=%HOMEDRIVE%

call "%APPDATA%\git-sdk\start_shell.cmd" -msys %*

This will set my $HOMEDRIVE, $HOMEPATH, and $HOME to D:, \, and /d respectively. The script does start the shell knowing the D drive. Unfortunately... for this to work with SSH is going to take more knowledge:

$ git push
Could not create directory '/home/public/.ssh...

Is there something I can do to make this happen? The only relavent information I have found is this article and not enough details exist for me to attempt it.

If their is time available for help, I would be much appreciated.

@EdenWise
Copy link
Author

Ok, I found this issue here and here. Sorry I missed this before. Was this issue ever resolved?

@dscho
Copy link
Member

dscho commented Apr 20, 2016

I am trying to create a batch script to start start_shell.cmd

What is start_shell.cmd? Where did you get it from?

set HOMEDRIVE=%cd:~0,2%
set HOMEPATH=\
set HOME=%HOMEDRIVE%

I think you meant set HOME=%HOMEDRIVE%%HOMEPATH%

call "%APPDATA%\git-sdk\start_shell.cmd" -msys %*

Why not just call ...\git-sdk\git-bash.exe?

I would be much appreciated.

Yes, you are! 😃

@EdenWise
Copy link
Author

EdenWise commented Apr 20, 2016

OK, have fixed the variable $HOME and set it to: set HOME=%HOMEDRIVE%%HOMEPATH%.

And I have set the executable to be git-bash.exe... still having a problem with SSH incorrectly knowing the home directory.

Update:

I discovered even if I don't use my script I am still having this problem:

  1. Start Git SDK 32 bit from Start Menu
  2. Clone a repository:
$ git clone git@github.com:Todd-Weed/arpa.git
Cloning into 'arpa'...
Could not create directory '/home/public/.ssh'.
The authenticity of host 'github.com (192.30.252.130)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/public/.ssh/known_hosts).
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.```

@dscho
Copy link
Member

dscho commented Apr 20, 2016

Do you know where this /home/public thing comes from? Is your account name public, perchance?

@EdenWise
Copy link
Author

Yes the account name is public:

PUBLIC=C:\Users\Public
USER=public
USERNAME=public

@Dirk1966
Copy link

Dirk1966 commented Apr 20, 2016

I usually start my git-bash inside of the SDK with
Z:\Prg\git-sdk-32\git-bash.exe --cd=%USERPROFILE%
so that the HOME directory is set to the USERPROFILE directory, which worked better in all the computers we had in our companies (I had a lot of trouble with HOMEDRIVE and HOMEPATH).
I am always recommending using this "--cd" switch.
You can also configure different shells with different home dirs/settings.

Remark: Public is a special account which is used as something like a base for all users. It should not be used for working. The public directory / user / group is always there, without creating it.

@dscho
Copy link
Member

dscho commented Apr 21, 2016

I usually start my git-bash inside of the SDK with
Z:\Prg\git-sdk-32\git-bash.exe --cd=%USERPROFILE%
so that the HOME directory is set to the USERPROFILE directory

This does not set HOME, it only switches the initial working directory.

@EdenWise
Copy link
Author

From what I can gather this all is dependent on nsswitch.conf. This file defines the $HOME directory. I am able to override it by providing that detail in the start script I use, however SSH (for security reasons) uses another method... perhaps through nsswitch.conf?!

SSH does provide a configuration option to specify the identity file:

$ cat ~/.ssh/config
IdentityFile  ~/.ssh/id_rsa

This may be a short-term solution as other problems may crop up from this nsswitch.conf setting (it appears it uses /home/$USER). I hope this will be all there is because I like having my home directory on an external drive.

@EdenWise
Copy link
Author

I apologize from the start—my previous post is in error. I had forgot that I had edited the nsswitch.conf to the previous /etc/nsswitch.conf setting (prior to the filesystem-2016.04-3 package) where db_home is define as such:

db_home: env windows cygwin desc

And forgot that I had done so before making that ssh configuration.

When I use the current setting:

db_home: cygwin desc

... there is still a problem. Therefore the answer on the previous post, if the user wants to define a custom $HOME directory, not working when using SSH.

Apologize for any inconvenience that this may have caused.

@dscho
Copy link
Member

dscho commented Apr 27, 2016

@Todd-Weed sorry, I lost track and do not have time to re-read the entire thread carefully. Is the original report still valid, i.e. is there a bug we need to fix in Git for Windows (or its SDK)?

@dscho dscho added the sdk label Apr 27, 2016
@EdenWise
Copy link
Author

EdenWise commented Apr 27, 2016

Setting a custom $HOME won't be possible with nsswitch.conf pointing db_home to cygwin desc — SSH will require /home/$USER. Since past discussion has pretty much decided the db_home setting of env windows can be at times unreliable, I think you have to stick your course unless SSH can be compiled to used the $HOME variable... and I saw one mention that doing this might be a SSH security issue. So I will just edit nsswitch.conf so that I can have a custom home directory.

@dscho
Copy link
Member

dscho commented Apr 28, 2016

the db_home setting of env windows can be at times unreliable

Well, this is what we have to fix, then. Give me access to a machine where this is a problem and I'll fix it. Alternatively, I can help you debug it (but this is not something for the lazy of heart, it will require a little bit of work and effort).

@go2null
Copy link

go2null commented Aug 10, 2016

Happening to me - neither the default db_home: env windows cygwin desc nor db_home: env.
I have to set it to db_home: /j/.

My setup:

  • PortableGit-2.9.2-32-bit.7z.exe installed.
  • Have a skeleton $USERPROFILE/.bashrc
export HOME='J:\'
cd "$HOME"
. "$HOME/.config/sh/shrc"

Note that setting HOME per http://stackoverflow.com/a/2840909/3366962 works as well. However, I wish to maintain a Portable installation.

@dscho
Copy link
Member

dscho commented Aug 18, 2016

For the record: the git-wrapper.c could be taught to understand the --home=... option. I simply do not find the time to do it.

Patches welcome.

@PhilipOakley
Copy link

Just making some notes...

https://github.com/git-for-windows/git/blob/master/compat/win32/git-wrapper.c#L56-L58 is the comment that starts the setting of Homedrive etc.

https://github.com/git-for-windows/git/blob/master/compat/win32/git-wrapper.c#L389-L429 look to be the checking of the cmd line arguments for options.

Looks like it won't be that hard for a volunteer to have a go. All the framework examples are there to copy...

@dogancelik
Copy link

dogancelik commented Dec 12, 2016

I can't set my $HOME using nsswitch.conf, I use PortableGit 2.11.0.

I tried setting db_home the following values:

db_home: /home/%U
db_home: /e/Tools/git/home/dogan
db_home: cygwin desc

When I start git-bash.exe in the root directory then do:

dogan@dogan-pc MINGW64 /
$ echo $HOME
/c/Users/dogan # I always get this

I really want my Git setup to be 100% portable and don't want it to rely on Windows environment variables.

@dscho
Copy link
Member

dscho commented Dec 12, 2016

@dogancelik it is really not nice to hide a request for help in a different ticket. A much better venue would have been the Git for Windows mailing list/forum.

As to your question, HOME is set by git-bash.exe. That is by design. What your changes in nsswitch.conf do is to give OpenSSH a different idea of what "home" is.

The proper way to address your problem would be to patch the git-wrapper to set HOME in a portable manner, as an opt-in feature (it must be opt-in for backwards compatibility).

One such way would be to add another resource setting (similar to APPEND_QUOTE) and to set that via edit-git-bash.exe. Another way to make this an opt-in would be to test specifically for README.portable in the same directory as git-bash.exe (but this test must be limited to git-bash.exe, i.e. triggered through git-bash.exe's resources).

@dogancelik
Copy link

@dscho I'm sorry about that, I didn't want to open up a new issue so I asked here, so I have to set HOME.

@dscho
Copy link
Member

dscho commented Dec 25, 2016

I'll close this for now. If anybody feels strongly enough about this issue, there is tons of information in my comments above how to fix this, and I'll still be here if anybody gets stuck implementing the new feature.

@dscho dscho closed this as completed Dec 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants