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.
Related
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
Starting point:
Ubuntu 20.04
Gitolite (/home/git/)
Webspace /var/www/webspace (usually owned by www-data:www-data)
Git user (in www-data group and also tried without beeing in group)
I want to update the webspace as git user with post-receive to a www-data directory. I had it archived before I installed Gitolite, but it doesn't seem to work the same way as it did before (or I am missing something). To make it clear: post-receive is executed after pushing (which it's normally not on Gitolite) ... was a hard time too to archive that.
Edit: To make it clear: I want to archive that Git and www-data can access and modify the same files.
What Ive tried:
chmod 777 -R /var/www/webspace (after this git can access but nginx returns with 403?)
Adding Git-User to www-data group
chown www-data:git -R /var/www/webspace
chown git:www-data -R /var/www/webspace
chown git:git -R /var/www/webspace
chown www-data:www-data -R /var/www/webspace (with and without git inside group)(with and without 777)
Executing post-receive manually (Operation not permitted)
Executing post-receive manually as root (well ... works of course, but thats not the point)
... maybe also some steps more which Im maybe missing rn
What Ive noticed so far:
On the contrary to Git, Gitolite checks the repo out with -rw------ (If i remember correctly), maybe that is why its not working with gitolite but with Git
The code (not that it would be important, but just to list everything):
post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/webspace git checkout -f
Maybe Im just missing something, but please help me.
Try and follow "adding other (non-update) hooks" in order for Gitolite to call the relevant post-receive hook.
add this line in the rc file, within the %RC block, if it's not already present, or uncomment it if it's already present and commented out:
LOCAL_CODE => "$ENV{HOME}/local",
put your hooks into that directory, in a sub-sub-directory called "hooks/common":
# log on to gitolite hosting user on the server, then:
cd $HOME
mkdir -p local/hooks/common
cp your-post-receive-hook local/hooks/common/post-receive
chmod +x local/hooks/common/post-receive
run gitolite setup to have the hooks propagate to existing repos (repos created after this will get them anyway).
Add user (git in my case) to group of webspace (www-data for me)
sudo usermod -a -G www-data git
If you were logged in as user logout to reload the group.
logout
#or
exit
#or
CTRL+A+D
(If you want to recheck the group login as this user and type "groups" to see the groups the user is in)
Make sure the webspace is owned by the correct group. For me:
sudo chown www-data:www-data -R /var/www/webspace
(If you want to recheck this you can go in the directory and type "ls -g")
In my case I had to modify my "post-receive" a bit, because the permissions were always -rw----- after checking out, so here is my "post-receive":
#!/bin/sh
GIT_WORK_TREE=/var/www/webspace git checkout -f #default line to checkout
chmod -R a+r /var/www/webspace #added by me because of permission issues
For convenience I had my "post-receive" in the repo directory (/home/git/repositories/repo/hooks/post-receive). The docs tell you to create a new folder (/home/git/local/specific-hooks/repo/post-receive (but they tell to name it on your own))
*All paths, names, groups and permissions written above only apply to me. They may differ for you installation.
What really solved my problem:
Logout after you change groups
Change permission (chmod) in post-receive
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.
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.