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.
Related
I have a list of bitbucket repositories on a server:
[user#lonapdbitbucket1 repositories]$ ls
1039 1044 1059 2165 2656 3958 3958 9284 9274 8274 7264 7263 8274
If I cd into one of these repositories and run git grep, to search for Ansible encryption strings, then it works fine - git grep manages to find an Ansible encryption string:
[user#lonapdbitbucket1 repositories]$ cd 1044
[user#lonapdbitbucket1 repositories]$ git grep -P '\$ANSIBLE_VAULT;[0-9]\.[0-];AES256' $(git rev-list --all)
To do this across multiple repos, I thought to convert it into a bash script:
# secret_scan.sh
repos_root=/var/lib/docker/volumes/bitbucket/_data/shared/data/repositories
git_grep_cmd=git grep -P '\$ANSIBLE_VAULT;[0-9]\.[0-];AES256' $(git rev-list --all)
for dir in ./*
do
# below line is just to clean up the directory string
repo_dir="$(d{dir#./}"
cd "${repos_root}${repo_dir}"; \
eval "git_grep_cmd"
done
Unfortunately, this does not work:
[user#lonapdbitbucket1 repositories]$ ./secret_scan.sh
fatal: not a git repository (or any parent up to mount point /var/lib)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
fatal: this operation must be run in a work tree
[user#lonapdbitbucket1 repositories]$ _
Would anyone be able to suggest a solution here, to essentially cd into multiple repositories and then run git grep on each, replicating results as if i were doing it on the command line?
I'm not sure what you are trying to achieve with eval and repo_dir. This should be as simple as:
repos_root=/var/lib/docker/volumes/bitbucket/_data/shared/data/repositories
for dir in *
do
cd "$repos_root$dir";
git grep -P '\$ANSIBLE_VAULT;[0-9]\.[0-];AES256' $(git rev-list --all)
done
Since your repos_root is absolute, you don't need to take care of returning to the original directory.
But I'm sceptical that git rev-list --all can be substituted, its output will be huge. Are you trying to find the string in ALL commits? To search the full history for a string, check Search all of Git history for a string and How to grep Git commit diffs or contents for a certain word
I have a cloned directory on a linux server. Keyed access is configured. After some processing on the server, at the output, I get csv files that I need to add to the git. I also need to receive files on the server that have been changed on the git itself (these can be either new added files, or some changes in the code). The adding process happens every day, so I want to automate it. On one of the sites I found an example suitable for me. Two scripts that add and clone changes to the server. Startup automation takes place through crontab.
Code file:
#!/bin/bash
# Go to the GIT category
cd '/home/user/www/'
# Submitting changes to the main branch
git checkout main
git add -A
git commit -m "update main"
git push
and...
#!/bin/bash
# Go to the GIT category
cd '/home/user/www/'
# Loading data from the main branch
git checkout main
git pull
But I get the following errors in the output, what could be the problem?
Cronlog:
/home/user/RFFI-V/Work/start_git_download.sh: line 3: cd: too many arguments
/home/user/RFFI-V/Work/start_git_push.sh: line 3: cd: too many arguments
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
Run each command manually, to see if you receive any issues.
If you dont receive any issues, then is the bash script in the correct folder for crontab and the script by default would run as root, if you want to run the script as a different user, an example syntax to setup the script to run as a different user in crontab is shown below,
1 2 3 4 5 USERNAME /path/to/script.sh
I need to set the permission of script.sh to 755. So
git add -A
git update-index --chmod=+x script.sh
git commit -m 'first commit'
This way the file will be committed with a permission 755 and my remote vm can execute those scripts.
However, next time I do something to the repo and commit the changes the permission of those scripts will be reverted to 644. The message is
[master 171c0cc] second
2 files changed, 1 insertion(+)
mode change 100755 => 100644 script.sh
Anyone know what might be happening here? How do I get rid of this?
First check your git config core.fileMode: if it is set to false, the executable bit of files in the working tree won't be honored anyway.
If it is true or not set, then try a chmod.
Then try also to set core.sharedRepository to group.
And check your umask. umask 002 in your case should work.
I seem to have permissions issue with a git repository.
I git this error when I pull in a directory my Linux user did not create.
fatal: Unable to create '/home/---/.git/ORIG_HEAD.lock': Permission denied
My user is a member of a group called grp. I changed every file to grp:grp and I still cannot pull.
Is there any thought on why this happens? For what it's worth I changed the actual /git/REPOSITORY files also to grp:grp.
Of course, when I use sudo I can pull fine but I prefer not to do it this way.
User: root
1) rm -f ./git/ORIG_HEAD.lock
2) chown -R MY_USER_NAME ./git*
3) chgrp -R MY_USER_NAME ./git*
4) git pull
I have a git repository that I am sharing with several developers. We do regular git pulls and pushes with it. Unfortunately, every time I do a git pull the changed files lose the group write permission. How do I stop git from doing this?
I am running this on Ubuntu 12.04 LTS.
The config on the shared repo looks like this:
[core]
repositoryformatversion = 0
filemode = true
bare = true
sharedRepository = group
I also ran the following commands on it in an attempt to fix it
find repo.git -type d -exec chmod g+rws {} +
sudo chmod -R g+rw repo.git/objects
No matter what I end up with folders with 755 and files with 644 when I want 775 and 664 respectively.
You should use the core.sharedRepository=group or core.sharedRepository=0664 setting.
See e.g. http://criticallog.thornet.net/2010/01/07/sharing-your-git-repository/
you can do this on a git hook with something like that:
#!/bin/sh
#
# .git/hooks/post-merge
sudo chmod -R g+rw *
it is called after every git pull, and file (.git/hooks/post-merge) must be executable
The users in question also need to have their umask set to 002.