Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default git hook does not work out of the box #876

Closed
jazzl0ver opened this issue Sep 24, 2018 · 13 comments · May be fixed by #913
Closed

Default git hook does not work out of the box #876

jazzl0ver opened this issue Sep 24, 2018 · 13 comments · May be fixed by #913
Assignees
Milestone

Comments

@jazzl0ver
Copy link

Hi,

Enabling

hook = ([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m "Changes by "%(user)s)

leads to:

[7fa9f2c42ae8] DEBUG: Running hook
[7fa9f2c42ae8] DEBUG: Captured stderr hook:

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'radicale@9009506c3d73.(none)')

[7fa9f2c42ae8] ERROR: An exception occurred during MKCOL request on '/myuser/0527aa01-08d0-01d4-4793-692bece1feeb/': Command '([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m "Changes by "myuser)' returned non-zero exit status 128.
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/radicale/__init__.py", line 332, in __call__
    status, headers, answers = self._handle_request(environ)
  File "/usr/lib/python3.6/site-packages/radicale/__init__.py", line 505, in _handle_request
    environ, base_prefix, path, user)
  File "/usr/lib/python3.6/site-packages/radicale/__init__.py", line 721, in do_MKCOL
    return client.CREATED, {}, None
  File "/usr/lib/python3.6/contextlib.py", line 88, in __exit__
    next(self.gen)
  File "/usr/lib/python3.6/site-packages/radicale/storage.py", line 1587, in acquire_lock
    raise subprocess.CalledProcessError(p.returncode, p.args)
subprocess.CalledProcessError: Command '([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m "Changes by "myuser)' returned non-zero exit status 128.

Workaround is to run

git config user.email "[email protected]"

in the collections folder.

Would be great if you could fix that!

@ikwyl6
Copy link

ikwyl6 commented Oct 14, 2018

Even though I iniitially did the "git init" in the collections dir, when I run:

sudo -u radicale git config user [email protected]

I get:

fatal: not in a git directory

# ls -al
total 20
drwxrwx--- 4 radicale radicale 4096 Oct 13 22:18 .
drwxrwx--- 3 radicale radicale 4096 Oct 13 21:19 ..
-rw-r----- 1 radicale radicale    0 Oct 13 22:35 .Radicale.lock
drwxrwx--- 7 radicale radicale 4096 Oct 13 21:24 .git
-rwxrwx--- 1 radicale alarm      47 Oct 13 21:26 .gitignore
drwxr-x--- 4 radicale radicale 4096 Oct 13 22:23 collection-root

@mookie-
Copy link
Contributor

mookie- commented Nov 26, 2018

@ikwyl6 you initialized the git repository in the wrong directory. It has to be one directory "up", e.g. /var/lib/radicale/ if your path is /var/lib/radicale/collections.

@mpasternak
Copy link

This is a documentation issue and I'm working on it (expect the PR soon)

@mookie-
Copy link
Contributor

mookie- commented Dec 21, 2018

@mpasternak I've already did a PR (#883)

@mpasternak
Copy link

@mookie- I commented it!

@mpasternak
Copy link

mpasternak commented Dec 31, 2018

@mookie- this is how I would do that: #913 #914

mpasternak added a commit to mpasternak/Radicale that referenced this issue Dec 31, 2018
@mookie-
Copy link
Contributor

mookie- commented Jan 9, 2019

@mpasternak You are right, this is much better. Thank you! I'll close my PR.

@vmario89
Copy link

vmario89 commented Jan 13, 2019

Hi,
i has some trouble too and messed with configuration. I solved it for me by:

vim /etc/radicale/config
[storage]
filesystem_folder = /var/lib/radicale/collections
hook = ([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m "Changes by "%(user)s)

cd /var/lib/radicale/collections
git init

vim .gitignore
.Radicale.cache
.Radicale.lock
.Radicale.tmp-*

cd /var/lib
chown -R radicale:radicale radicale/
sudo -u radicale git config user.name YourName
sudo -u radicale git config user.email [email protected]
service radicale restart

#make some new entry in calendar and then check radicale log and git commit history
tail -f /etc/radicale/radicale.log
cd /var/lib/radicale/collections
git log

regards, Mario

@mpasternak
Copy link

@vmario89 this is great, feel free to submit a pull request to my branch and I'll merge it so Kozea devs can merge just that PR. #913 #914

@fractalf
Copy link

fractalf commented Dec 1, 2019

Hi, I solved this in another way if anyone's interested.

I'm using a docker-compose.yml file to set up radicale (note the 2 GIT_* entries). This is slightly stripped, as I use an nginx/lets encrypt proxy also.

version: "3.7"

services:
    radicale:
        image: <user>/radicale
        build: ./
        container_name: radicale
        restart: always
        environment:
            GIT_NAME: <user>
            GIT_EMAIL: <email>
        volumes:
            - radicale:/data
            - ./config:/etc/radicale:ro
        ports:
            - 5232

volumes:
    radicale:
        driver_opts:
            type: none
            o: bind
            device: /mnt/ssd-data/docker-data/radicale

I'm using a slightly modified Dockerfile (added git + a user other than root)

FROM alpine:latest

# Version of Radicale (e.g. 2.0.0)
ARG VERSION=master
ARG USER=radicale

# Install dependencies
RUN apk add --no-cache \
      python3 \
      python3-dev \
      build-base \
      libffi-dev \
      ca-certificates \
      openssl \
      git

# Install Radicale
RUN wget --quiet https://github.com/Kozea/Radicale/archive/${VERSION}.tar.gz --output-document=radicale.tar.gz && \
    tar xzf radicale.tar.gz && \
    pip3 install ./Radicale-${VERSION}[md5,bcrypt] && \
    rm -r radicale.tar.gz Radicale-${VERSION}
# Install dependencies for Radicale<2.1.9
RUN pip3 install passlib[bcrypt]
# Remove build dependencies
RUN apk del \
      python3-dev \
      build-base \
      libffi-dev

RUN adduser -HD ${USER}
RUN mkdir /data && chown ${USER}.${USER} /data
USER radicale

# Run Radicale (Configure it here or provide a "config" file!)
CMD ["radicale", "--hosts", "0.0.0.0:5232"]

My config

[server]
hosts = 0.0.0.0:5232

[auth]
type = htpasswd
htpasswd_filename = /etc/radicale/users
htpasswd_encryption = bcrypt
delay = 1

[storage]
filesystem_folder = /data/collections
hook = /etc/radicale/git.sh

Note the git.sh which I'm calling in the hook here. It calls a small shell script which fixes all the git stuff so you don't need to do anything when booting up the docker container

#!/bin/sh
cd /data/collections

if [ ! -d .git ]; then
    git init
    git config user.name "$GIT_NAME"
    git config user.email "$GIT_EMAIL"
    echo -e ".Radicale.cache\n.Radicale.lock\n.Radicale.props\n.Radicale.tmp-*" > .gitignore
fi

git add -A
git diff --cached --quiet || git commit -m "Update"

@allo-
Copy link

allo- commented Jul 5, 2021

You may want to add, that configuring user.name and user.email is not only for having nice names in the commit log, but that git breaks when they are unset.

And it would be good to merge it soon. I had the issue for months until I found the problem myself after quite a bit of debugging (and came here after I wanted to create an issue about it).

@oscarcarlsson
Copy link

So the issue here is a small typo at the end of the line in the documentation. The current line is:

hook = ([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m "Changes by "%(user)s)

The line is missing a quote sign at the end, and should escape the quotation sign in the commit message. It should look like this to work:

hook = ([ -d .git ] || git init) && git add -A && (git diff --cached --quiet || git commit -m "Changes by \"%(user)s\"")

Maybe I should have a look at a PR (new or present), but in case some one else ends up here looking for the same thing, the above might help.

@pbiering pbiering added the bug label Mar 14, 2024
@pbiering pbiering self-assigned this Mar 14, 2024
@pbiering pbiering added this to the 3.1.9 milestone Mar 14, 2024
@pbiering
Copy link
Collaborator

Maybe I should have a look at a PR (new or present), but in case some one else ends up here looking for the same thing, the above might help.

doc fixed now, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants