Re: Copy local .gitconfig to VM

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Copy local .gitconfig to VM

Duncan Beevers
I tackled this problem recently and thanks to this thread, came up with a pretty simple solution.

We're using this in a Vagrant/chef-solo setup, but the technique is pretty general.

In our Vagrantfile, we add the git commit config values to the chef json.

    chef.json = {
      'git_info' => {
        'author_name' => `git config user.name`,
        'author_email' => `git config user.email`
      }
    }

Each time the Vagrantfile is executed (on provisioning) it calls out to the system in order to populate the `author_name` and `author_email` values.

In order to consume these values, we have a `.bash_profile.erb` template that is copied to the `vagrant` user's home directory. The template includes slots for the relevant git environment variables.

    export GIT_AUTHOR_NAME="<%= node.git_info[:author_name] %>"
    export GIT_AUTHOR_EMAIL="<%= node.git_info[:author_email] %>"
    export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
    export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"

Obviously this approach doesn't deal with copying over git aliases and other customizations. However, for us it has been sufficient in getting consistent commit information from our team no matter which terminal they submit their commit commands from.

On Wednesday, May 9, 2012 5:53:57 PM UTC-5, Nicholas Canzoneri wrote:
I use the dotfiles method (https://github.com/ryanb/dotfiles) and so keep all my configs stored in git. Then I use a little chef recipe to clone from git and install it on the vm.

On Wednesday, May 9, 2012, Sebastian Schulze wrote:
> The only way I can think of doing this is to mount the user's home
> folder in the VM and use a recipe to symlink `/home/vagrant/.gitconfig
> -> /home/host/.gitconfig`, but that sounds both dangerous and stupid.

Most of the settings can be exported via simple environment variables.
At least GIT_AUTHOR_EMAIL, GIT_AUTHOR_NAME, GIT_COMMITTER_EMAIL,
GIT_COMMITTER_NAME and GIT_EDITOR work for me.

You just have to send them in your client config and accept them on
the Vagrant machine. (AcceptEnv)

Regards,
 Sebastian


--
Nick Canzoneri
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="7Mdd6KRXQ5YJ">ac3...@...
@ac3522

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Copy local .gitconfig to VM

Patrick Connolly
Not sure whether this approach is preferable:
https://github.com/myplanetdigital/vagrant-ariadne/blob/develop/Rakefile#L124-L146

Basically finds each VM (works for multiple) and sends the scp into the machine :)

On Thursday, January 24, 2013 3:18:53 PM UTC-5, Duncan Beevers wrote:
I tackled this problem recently and thanks to this thread, came up with a pretty simple solution.

We're using this in a Vagrant/chef-solo setup, but the technique is pretty general.

In our Vagrantfile, we add the git commit config values to the chef json.

    chef.json = {
      'git_info' => {
        'author_name' => `git config user.name`,
        'author_email' => `git config user.email`
      }
    }

Each time the Vagrantfile is executed (on provisioning) it calls out to the system in order to populate the `author_name` and `author_email` values.

In order to consume these values, we have a `.bash_profile.erb` template that is copied to the `vagrant` user's home directory. The template includes slots for the relevant git environment variables.

    export GIT_AUTHOR_NAME="<%= node.git_info[:author_name] %>"
    export GIT_AUTHOR_EMAIL="<%= node.git_info[:author_email] %>"
    export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
    export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"

Obviously this approach doesn't deal with copying over git aliases and other customizations. However, for us it has been sufficient in getting consistent commit information from our team no matter which terminal they submit their commit commands from.

On Wednesday, May 9, 2012 5:53:57 PM UTC-5, Nicholas Canzoneri wrote:
I use the dotfiles method (https://github.com/ryanb/dotfiles) and so keep all my configs stored in git. Then I use a little chef recipe to clone from git and install it on the vm.

On Wednesday, May 9, 2012, Sebastian Schulze wrote:
> The only way I can think of doing this is to mount the user's home
> folder in the VM and use a recipe to symlink `/home/vagrant/.gitconfig
> -> /home/host/.gitconfig`, but that sounds both dangerous and stupid.

Most of the settings can be exported via simple environment variables.
At least GIT_AUTHOR_EMAIL, GIT_AUTHOR_NAME, GIT_COMMITTER_EMAIL,
GIT_COMMITTER_NAME and GIT_EDITOR work for me.

You just have to send them in your client config and accept them on
the Vagrant machine. (AcceptEnv)

Regards,
 Sebastian


--
Nick Canzoneri
[hidden email]
@ac3522

--