Git push error-(git push 报错)


#1

Gogs 版本(Gogs Version):0.6.1.0325 Beta hypriot/ rpi-gogs-raspbian Docker Container
系统类型及版本(System type and its version):Linux 4.14.79+ (Raspberry Pi)
数据库(Database type):Sqlite3 (安装路径(Installation Path))


问题描述(Question description):
git push报错无法成功。(git push error)

user@machinename : /var/www/docker-gogs/atest $ git push

Username for ‘https://example.com’: arunonman

Password for ‘https://arunonman@example.com’:

Counting objects: 4, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (4/4), 317 bytes | 0 bytes/s, done.

Total 4 (delta 0), reused 0 (delta 0)

remote: hooks/update: line 2: /gogits/gogs: No such file or directory

remote: error: hook declined to update refs/heads/master

To https://example.com/user/atest.git

! [remote rejected] master -> master (hook declined)

error: failed to push some refs to ‘https://example.com/user/atest.git

这是app.ini的设定(This is the app.ini configuration.)

RUN_USER = git

RUN_MODE = prod

[database]

DB_TYPE = sqlite3

HOST = 127.0.0.1:3306

NAME = gogs

USER = root

PASSWD =

SSL_MODE = disable

PATH = data/gogs.db

[repository]

ROOT = /home/git/gogs-repositories

[server]

HTTP_PORT = 3000

ROOT_URL = https://example.com/

DISABLE_SSH = true

[service]

REGISTER_EMAIL_CONFIRM = false

ENABLE_NOTIFY_MAIL = false

[session]

PROVIDER = file

[log]

MODE = file

LEVEL = Info

[security]

INSTALL_LOCK = true

SECRET_KEY = eXIUsLHedrA0PXy

也有见过相似的问题不过无法解。由于是docker我也贴上docker container的根目录。还有预设目录提供更多参考线索。(There is a similar problem but I can’t use the solution to resolve the error. So, I post the docker container its root path and default path for more reference.)

根目录。(root path of docker container.)

user@machinename:/var/www/docker-gogs/atest $ docker exec 0887681c385a ls -alh /
total 92K
drwxr-xr-x 1 root root 4.0K Dec 19 11:09 .
drwxr-xr-x 1 root root 4.0K Dec 19 11:09 …
-rwxr-xr-x 1 root root 0 Dec 19 11:09 .dockerenv
drwxr-xr-x 1 root root 4.0K Jun 25 2015 bin
drwxr-xr-x 2 root root 4.0K Jan 7 2015 boot
drwxrwxr-x 4 git www-data 4.0K Dec 19 11:09 data
drwxr-xr-x 5 root root 320 Dec 20 02:28 dev
drwxr-xr-x 1 root root 4.0K Dec 20 04:52 etc
drwxrwxr-x 1 git www-data 4.0K Dec 19 11:09 gogits
drwxrwxr-x 1 git www-data 4.0K Jun 25 2015 home
drwxr-xr-x 1 root root 4.0K Jun 25 2015 lib
drwxr-xr-x 2 root root 4.0K Jun 24 2015 media
drwxr-xr-x 2 root root 4.0K Jun 24 2015 mnt
drwxr-xr-x 2 root root 4.0K Jun 24 2015 opt
dr-xr-xr-x 96 root root 0 Dec 20 02:28 proc
drwx------ 2 root root 4.0K Jun 24 2015 root
drwxr-xr-x 1 root root 4.0K Dec 19 11:09 run
drwxr-xr-x 1 root root 4.0K Jun 25 2015 sbin
drwxr-xr-x 2 root root 4.0K Jun 24 2015 srv
dr-xr-xr-x 12 root root 0 Dec 20 02:31 sys
drwxrwxrwt 1 root root 4.0K Dec 20 01:20 tmp
drwxr-xr-x 1 root root 4.0K Jun 25 2015 usr
drwxr-xr-x 1 root root 4.0K Jun 25 2015 var

预设目录。(the default path of docker container.)

user@machinename:/var/www/docker-gogs/atest $ docker exec 0887681c385a ls -alh
total 15M
drwxrwxr-x 1 git www-data 4.0K Dec 19 11:09 .
drwxr-xr-x 1 root root 4.0K Dec 19 11:09 …
-rwxrwxr-x 1 git www-data 23 Jun 25 2015 .dockerignore
-rwxrwxr-x 1 git www-data 12 Jun 25 2015 .gitignore
-rwxrwxr-x 1 git www-data 1.2K Jun 25 2015 Dockerfile
lrwxrwxrwx 1 git www-data 15 Dec 19 11:09 data -> /data/gogs/data
-rwxrwxr-x 1 git www-data 15M Jun 25 2015 gogs
lrwxrwxrwx 1 git www-data 14 Dec 19 11:09 log -> /data/gogs/log
drwxrwxr-x 1 git www-data 4.0K Jun 25 2015 public
-rwxrwxr-x 1 git www-data 737 Jun 25 2015 start.sh
drwxrwxr-x 1 git www-data 4.0K Jun 25 2015 templates

我用Nginx的反向代理。(I use Ngninx with its reversed proxy.)

docker run -d --name my-go-git-server --restart=always --publish 127.0.0.1:8022:22 --publish 127.0.0.1:3000:3000 --volume /var/www/docker-gogs/data:/data hypriot/rpi-gogs-raspbian

感谢抽空阅读解惑。谢谢。(Thanks for your time for finding the solution. Thanks again.)


#2

你好,请使用官方镜像!


#3

Hi,
A way is to resolve the problem it’s to delete the “hoods” directory inside the client site repo. The other I didn’t try it is to add the “hooks” in the Nginx configuration.

I post my Nginx configuration.

server {
listen 80 default;
#listen [::]:80 default;
server_name example;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default;
#listen [::]:443 ssl default_server;
server_name example.com;

ssl on;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
# omit SSLv3 because of POODLE (CVE-2014-3566)
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_prefer_server_ciphers on;   

    auth_basic "Restricted Content";
    auth_basic_user_file /etc/nginx/.htpasswd;

      # static repo files for cloning over https
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
    root /home/pi/gogs-repositories/;
    client_max_body_size       10m;
    client_body_buffer_size    128k;
    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;             
    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
}

# requests that need to go to git-http-backend
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)${
    root /home/pi/gogs-repositories/;
    fastcgi_pass  unix:/var/run/fcgiwrap.socket;
    fastcgi_param SCRIPT_FILENAME   /usr/lib/git-core/git-http-backend;
    fastcgi_param PATH_INFO         $uri;
    fastcgi_param GIT_PROJECT_ROOT  $document_root;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param REMOTE_USER $remote_user;
    include fastcgi_params;
}

location / {
    client_max_body_size       10m;
    client_body_buffer_size    128k;
    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;             
    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;

    proxy_set_header   Host             $http_host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_max_temp_file_size 0;

    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Authorization $http_authorization;
    proxy_pass_header  Authorization;
}

}

This is with http auth.
The place is to be added the “hook” in here.
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ => location ~ ^.*\.git/(HEAD|hooks/.*|info/refs|objects/info/.*|git-(upload|receive)-pack)$

I install the latest version of gogs(binary version). This problem is due to the old version “hook feature” making the push error.

I have the reference on how to configure the http auth with Nginx. This article also have a way to make “push” and “clone” properly work with its way.

Reference:
https://stackoverflow.com/questions/6414227/how-to-serve-git-through-http-via-nginx-with-user-password

I post the app.ini for reference either.

APP_NAME = Gogs
RUN_USER = pi
RUN_MODE = prod

[database]
DB_TYPE = sqlite3
HOST = 127.0.0.1:3306
NAME = gogs
USER = root
PASSWD =
SSL_MODE = disable
PATH = data/gogs.db

[repository]
ROOT = /home/pi/gogs-repositories

[server]
HTTP_PORT = 3000
ROOT_URL = https://example.com/
DISABLE_SSH = true

[mailer]
ENABLED = true
HOST = gmail.com:587
FROM = "noreply"noreply@gmail.com
USER = mailer@gmail.com
PASSWD = mailer

[service]
REGISTER_EMAIL_CONFIRM = true
ENABLE_NOTIFY_MAIL = true
DISABLE_REGISTRATION = false
ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = true

[picture]
DISABLE_GRAVATAR = true
ENABLE_FEDERATED_AVATAR = false

[session]
PROVIDER = file

[log]
MODE = file
LEVEL = Info
ROOT_PATH = /home/pi/gogs/log

[security]
INSTALL_LOCK = true
SECRET_KEY = 3JkePy8ATZcQReh