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

Change git idm automatically based on project directory location #1

Closed
samrocketman opened this issue May 15, 2020 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@samrocketman
Copy link
Owner

samrocketman commented May 15, 2020

https://dev.to/maxlmator/maintaining-different-git-identities

It would be nice for identities to auto-select based on a local directory (optionally given).

[includeIf "gitdir:~/git/github/"]
    path = /home/sam/.gitconfig_idm_github

And the contents of /home/sam/.gitconfig_idm_github would be...

[user]
    name = Sam Gleske
    email = me@example.com
[core]
    sshCommand = ssh -i /home/sam/.ssh/id_rsa -o IdentitiesOnly=yes -F /dev/null

Assuming that the git idm identity is...

[user]
    name = Sam Gleske
    email = me@example.com
    activeidm = github
[gitidm "github"]
    name = Sam Gleske
    email = me@example.com
    sshKey = /home/sam/.ssh/id_rsa
    sshCommand = ssh -i /home/sam/.ssh/id_rsa -o IdentitiesOnly=yes -F /dev/null

This will require a minimum version of git 2.13.0 for this.

Brainstorming feature

I think it makes sense to add this as a sub-command git idm directory which associates the identity name with the directory.

# personal projects
git idm directory add github ~/git/github/

# work projects
git idm directory add work ~/git/work/

# generically
git idm directory [add|remove] [git idm identity] [project path to apply identity]

We could tie the identity with an idm subkey in .gitconfig like:

[includeIf "gitdir:~/git/github/"]
    idm = github
    path = /home/sam/.gitconfig_idm_github

When removing an identity we'll want it to search for all includeIf settings where idm key is equal to the identity being removed. We'll also want to delete the file.

Using the prefix .gitconfig_idm_[git idm identity] for the file seems like the best way to avoid clashing with potential user configuration files.

@samrocketman samrocketman added the enhancement New feature or request label May 15, 2020
@samrocketman
Copy link
Owner Author

This feature has been implemented in 0.7 release. I changed around the option names based on limitations in current program design. I tried making sense of the option naming as much as possible. I don't think the result is that bad and is helpful for configuring an advanced git feature easily.

Let's say you have a work identity and a personal identity.

git idm track work --directory ~/git/work
git idm track work --directory ~/git/work2
git idm track personal --directory ~/git/github

List directories associated with a given identity. The directories will auto-switch to the identity for git commit authorship and private key for pushing over SSH.

git idm list work --tracked

Removing identities and running git idm uninstall will have expected cleanup behavior.

samrocketman pushed a commit that referenced this issue Jun 22, 2021
Corrected typo, added signing example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant