Git annex can't add a single file - git-annex

After running git init and git annex init "test" on a directory, I created a file with some text and proceeded to execute git annex add . but I'm getting the following errors:
$ git annex add .
add file1.txt
file1.txt: setFileMode: permission denied (Operation not permitted)
failed
git-annex: add: 1 failed
And using sudo:
$ sudo git annex add .
add file1.txt
100% 8 B 2 KiB/s 0s
git-annex: .git/annex/othertmp/file1.txt.0/file1.txt: rename: permission denied (Permission denied)
failed
git-annex: add: 1 failed

Related

Permission denied in Gitlab Runner

I have a Gitlab runner running in a VPS, now is facing this error:
Running on vps...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/-Jgf7oJG/0/agency/project/app/.git/
Checking out 67b23db2 as testing...
Removing .env
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ mkdir -p ~/.ssh
$ echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
$ chmod 700 ~/.ssh/id_rsa
$ eval "$(ssh-agent -s)"
Agent pid 929369
$ ssh-add ~/.ssh/id_rsa
Identity added: /home/gitlab-runner/.ssh/id_rsa (/home/gitlab-runner/.ssh/id_rsa)
$ ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
bash: line 133: /home/gitlab-runner/.ssh/known_hosts: Permission denied
Cleaning up file based variables
00:00
ERROR: Job failed: exit status 1
I've tryed with the following commands inside the vps that have the runner:
$ sudo usermod -a -G sudo gitlab-runner
$ sudo visudo
And adding this to the bottom of the file.
gitlab-runner ALL=(ALL) NOPASSWD: ALL
make sure that your known_hosts file has the following group & permissions.
-rw-r--r-- 1 gitlab-runner gitlab-runner 444 Aug 2 00:00 known_hosts
from sshd manual
~/.ssh/known_hosts
Contains a list of host keys for all hosts the user has logged into that are not already in the systemwide list of known host keys. The format of this file is described above. This file should be writable only by root/the owner and
can, but need not be, world-readable.
chmod 600/644 for ~/.ssh/known_hosts

Prevent git from failing on filesystems without chmod permissions in Linux

I am trying to initialize a git repro on a samba mount with very limited permissions.
Trying to init I will receive:
$ git init .
error: chmod on /mnt/server/subfolder/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'
Which is surprising as filemode is already globally set to false
$ git config --get core.filemode
false
The Problem in general is that /mnt/server is a samba mount to a folder to which I have very limited access.
Also I am not able to change any permission for the /mnt/server mount as I am working on shared server with on which several users need the access to the /mnt/server mount.
So changing mounting permission like suggested here is not an option.
Also creating a symlink like suggested here does not work, as symlinks are not enabled on the samba drive.
So the question is how to prevent git from failing a chmod error or prevent it from doing chmod at all?
Is this possible?
Or how do I init a git in the environment?
A bit hacky solution is:
Init the an empty repro at destiantion with sufficient permission i.e. mktemp -d.
$ tempdir = $(mktemp -d)
$ git init $tempdir
Initialized empty Git repository in /tmp/tmp.pREa198fnx/.git/
Move the created .git folder to target destination.
$ mv $tempdir/.git /srv/server/sub/
mv: preserving times for './.git/branches': Operation not permitted
mv: preserving permissions for ‘./.git/branches’: Operation not permitted
mv: preserving times for './.git/hooks/applypatch-msg.sample': Operation not permitted
mv: preserving permissions for ‘./.git/hooks/applypatch-msg.sample’: Operation not permitted
mv: preserving times for './.git/hooks/commit-msg.sample': Operation not permitted
...
There will some error during moving but it won't stop mv from moving the files.
In the end the git works as expected:
$ echo "Foo" > bar.txt
$ git add bar.txt
$ git commit -m "Added Foobar"
[master (root-commit) e232039] bar.txt
1 file changed, 1 insertion(+)
create mode 100755 bar.txt
$ git status
On branch master
nothing to commit, working tree clean
branch and checkout seems to work to, didn't test push/pull.
Would still appreciate a cleaner solution.

"Read-only file system" error when Git tries to access index.lock

I haven't touched my local Git repository for a couple of days. Now when I cd to the root and type
git add -A :/
I get:
fatal: Unable to create '/home/james/code/winescan/Prototype/.git/index.lock': Read-only file system
Adding sudo to the command gives the same error. Then I tried ls -al:
drwxr-xr-x 8 james james 4096 Jul 28 16:24 .git
Then I tried changing the mode for the directory:
$ sudo chmod 0777 .git
[sudo] password for james:
chmod: changing permissions of '.git': Read-only file system
Nothing seems to work, what do I do?

Benchmark cp + git on linux v.s. Windows: why such differences?

I have created a large amount of files using this Python script that I used primarily to benchmark Git.
The result is very surprising especially the differences between Windows and Linux.
Basically my script creates 12 directories with 512 files in each of them. Each file is about 2 to 4 kB. With the Git objects the repository is about 12k files.
I benchmarked:
Time to add all the files to git git add .
Time to checkout a previous branch
Time to copy the repository on the same SSD
Time to copy the repository to an external Sata HDD (NTFS)
I did this with the very same repository on both Windows 10 and Linux:
Operation Linux Windows Ratio
--------- ----- ------- -----
1. git add . 0.47s 21.7s x46
2. git checkout HEAD~1 0.35s 16.2s x46
3. git checkout . 0.40s 20.5s x50
4. cp -r ssd->ssd 0.35s 1m14s x211
5. cp -r ssd->hdd 4.90s 6m25s x78
The operation was done in this order:
$ mkdir test
$ cp test.py test && cd test
$ ./test.py # Creation of the files
$ git init
$ time git add . # (1)
$ git commit -qam 1
$ ./test.py # Alter some files
$ commit -qam 2
$ cd ..
$ time cp -r test /media/hdd/ # (4)
$ time cp -r test test2 # (5)
$ cd test
$ time git checkout HEAD~1 # (2)
$ ./test.py
$ git checkout master
$ git reset --soft head~1
$ time git checkout . # (3)
The benchmark was done on the same PC (using dual boot).
Why such differences? I can not believe it.

Script for root to git pull as another user

I have a script that I would like to have do a git pull inside another user's git directory. This script is run by the root user. For example:
cd /home/username/GitProject
sudo -u username -i git pull
When I run this, I get:
fatal: Not a git repository (or any of the parent directories): .git
Is there a way to have my script do a git pull as username?
Try without the -i option to sudo. That option is documented as first changing to the target user's home directory, which undoes the directory change you so carefully do before that. Alternatively, use the appropriate options to git to specify the directory, something like this:
sudo -u username -i git --git-dir=/home/username/GitProject/.git --work-tree=/home/username/GitProject pull
This can be done without sudo. This assumes you have password-less ssh keys since you are talking about a script. Here's the failure:
# git clone <user>#<host>:/path/to/repo
Cloning into 'repo'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
This shows that ~ properly expands to the user's homedir:
# MYUSER=somebody
# su - $MYUSER -c "echo ~"
/home/somebody
And here's the actual command used to clone into the home directory along with some extra proofs:
# su - $MYUSER -c "git clone <user>#<host>:/path/to/repo"
Cloning into 'repo'...
remote: Counting objects: 13, done.
<..>
# ls -l /home/$MYUSER/repo/.git/config
-rw-r--r-- 1 somebody somebody 275 Nov 8 23:55 /home/somebody/repo/.git/config
# su - $MYUSER -c "cd ~/repo; git remote -v"
origin <user>#<host>:/path/to/repo (fetch)
origin <user>#<host>:/path/to/repo (push)
# su - $MYUSER -c "cd ~/repo; git pull"
Already up-to-date.

Resources