2

I have a project on my vagrant machine that I would like to push into my github repository. But I cannot add objects without using sudo.

  1. I have initialized git
    vagrant@vagrant:/vagrant/testDir$ git init
    Initialized empty Git repository in /vagrant/testDir/.git/`
    
  2. After that if I run the command to add contents
    vagrant@vagrant:/vagrant/testDir$ git add .`
    
    Then I am getting this error:

error: insufficient permission for adding an object to repository database .git/objects

error: file1: failed to insert into database

error: unable to index file file1

fatal: adding files failed

Although I can run the command without any errors if I run with sudo, i.e., sudo git add ..

I have confirmed the permission inside the project, and they are are okay:

vagrant@vagrant:/vagrant/testDir$ ls -al
total 0
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 10:33 .
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 10:33 ..
drwxr-xr-x 1 vagrant vagrant 352 Dec 23 10:33 .git
-rw-r--r-- 1 vagrant vagrant   0 Dec 23 10:33 file1
-rw-r--r-- 1 vagrant vagrant   0 Dec 23 10:33 file2.txt

I have ubuntu 18.04 on my vagrant machine running on macOS High Sierra. Vagrant = 2.2.2 Virtual box = 6.0.8 r130520

Could you please help me out?

Update 1

Also, the permission on .git/ directory are fine

vagrant@vagrant:/vagrant/testDir/.git$ ls -al
total 12
drwxr-xr-x 1 vagrant vagrant 320 Dec 23 10:52 .
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 04:12 ..
-rw-r--r-- 1 vagrant vagrant  23 Dec 23 04:12 HEAD
drwxr-xr-x 1 vagrant vagrant  64 Dec 23 04:12 branches
-rw-r--r-- 1 vagrant vagrant 111 Dec 23 04:12 config
-rw-r--r-- 1 vagrant vagrant  73 Dec 23 04:12 description
drwxr-xr-x 1 vagrant vagrant 416 Dec 23 04:12 hooks
drwxr-xr-x 1 vagrant vagrant  96 Dec 23 04:12 info
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 04:12 objects
drwxr-xr-x 1 vagrant vagrant 128 Dec 23 04:12 refs

Update 2

The permission inside the .git/objects directory are also okay.

vagrant@vagrant:/vagrant/testDir/.git/objects$ ls -al
total 0
drwxr-xr-x 1 vagrant vagrant 160 Dec 23 11:06 .
drwxr-xr-x 1 vagrant vagrant 320 Dec 23 11:06 ..
drwxr-xr-x 1 vagrant vagrant  96 Dec 23 11:06 e6
drwxr-xr-x 1 vagrant vagrant  64 Dec 23 11:06 info
drwxr-xr-x 1 vagrant vagrant  64 Dec 23 11:06 pack
Kakar
  • 5,354
  • 10
  • 55
  • 93

2 Answers2

2

These are the steps I took to solve my problem:

  1. I downgraded the virtualbox on my macOS from 6.0.8 r130520 to 6.0.4 r128413.
  2. Installed vagrant-vbguest plugin

    $ vagrant plugin install vagrant-vbguest

  3. Reload the vagrant machine.

    user@MacBook-Pro vagrant-project-machine $ vagrant reload ==> default: Attempting graceful shutdown of VM... ==> default: Checking if box 'bento/ubuntu-18.04' is up to date... ... ... ==> default: Machine booted and ready! ... [default] GuestAdditions versions on your host (6.0.4) and guest (6.0.8) do not match. ... ... The following additional packages will be installed: linux-headers-4.15.0-51 ... ...

Finally you can confirm it by running this command:

user@MacBook-Pro vagrant-project-machine $ vagrant vbguest --status
...
...
[default] GuestAdditions 6.0.4 running --- OK.

You can also confirm inside the vagrant machine by running this command:

vagrant@vagrant:/vagrant/testDir$ modinfo vboxguest
filename:       /lib/modules/4.15.0-51-generic/misc/vboxguest.ko
version:        6.0.4 r128413
license:        GPL
description:    Oracle VM VirtualBox Guest Additions for Linux Module
author:         Oracle Corporation
srcversion:     95F53B9B95BC6E03156A1D8
alias:          pci:v000080EEd0000CAFEsv00000000sd00000000bc*sc*i*
depends:        
retpoline:      Y
name:           vboxguest
vermagic:       4.15.0-51-generic SMP mod_unload 

Now I can run the git commands without using sudo.

Kakar
  • 5,354
  • 10
  • 55
  • 93
1

if the check the permission of the contents, the permissions are okay:

They are, on the first level.
But are they in .git/objects?

You might want to do, to be sure, a sudo chown -R vagrant:vagrant .git

Add also the core.sharedRepository setting:

git config --global core.sharedRepository group

The OP Kakar mentions in the comments the hashicorp/vagrant issue 10913, which states:

I believe the bug is in the Guest Additions so you need to make sure the correct version of those are installed.
Run modinfo vboxguest in Ubuntu to find out the version that is installed.

I appear to have solved this by updating my Virtualbox Guest Additions from 6.0.10 to 6.0.12, using dotless-de/vagrant-vbguest.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250