Error when pushing to synced git repository on gitlab

git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 485 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: 
remote: SubGit ERROR REPORT (SubGit version 3.3.5 ('Bobique') build #4042):
remote: 
remote: You've received this message because SubGit (http://subgit.com/) is installed in your repository
remote: and an error that needs to be dealt with has occurred in SubGit translation engine.
remote: 
remote: TEMPORARY ERROR:
remote:         Cannot stat file '/opt/gitlab/embedded/service/gitlab-shell/svn/.svngit/svngitkit.config' : No such file or directory
remote: 
remote: CURRENT STATE:
remote:         Both Git and Subversion repository are open for pushes or commits.
remote:         Your commit was not committed, but you may retry it.
remote: 
remote: TO RECOVER:
remote:           A) Address the problem if possible and then retry commit
remote:         OR
remote:           B) Run on the server
remote:              $ subgit uninstall SVN_REPOS_PATH
remote: 
remote:         IMPORTANT: As soon as SubGit is uninstalled, both Git and Subversion repositories
remote:                    will become open, but no synchronization will take place.
remote: 
remote: TO REPORT:
remote:         Report an issue at http://issues.tmatesoft.com/
remote:         You may find logs on the server at 'SVN_REPOS_PATH/subgit/logs'
remote: 
remote: THANK YOU!
remote: [2019-07-05 20:39:15.739][pre-receive] SubGit version 3.3.5 ('Bobique')
remote: [2019-07-05 20:39:15.739][pre-receive] Command name: pre-receive.
remote: [2019-07-05 20:39:15.739][pre-receive] Current user: git.
remote: [2019-07-05 20:39:15.739][pre-receive] Cannot stat file '/opt/gitlab/embedded/service/gitlab-shell/svn/.svngit/svngitkit.config' : No such file or directory
remote: [2019-07-05 20:39:15.739][pre-receive]   at hook_config_load (config.c:498)
remote: [2019-07-05 20:39:15.739][pre-receive]   at hook_repository_area_detect (repository.c:72)
remote: [2019-07-05 20:39:15.739][pre-receive]   at hook_git_resolve_paths (hook.c:442)
remote: [2019-07-05 20:39:15.739][pre-receive]   at internal_pre_receive (pre-receive.c:120)
remote: [2019-07-05 20:39:15.740][pre-receive] 
To ssh://git@url
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@url'

Hello! May I ask you what GitLab version are you using?
Normally this file can be found in
{code}
GIT_REPO/svn/.svngit/svngitkit.config
{code}

where GIT_REPO is the path to the Git repository on the filesystem, afair, it’s somewhere in /var/… directory. The directory the output
{code}
/opt/gitlab/embedded/service/gitlab-shell
{code}
is the directory where GitLab scripts are located.

Normally SubGit hooks use the “current” directory (which is GIT_REPO/hooks/) to find GIT_REPO path. In your case it is resolved incorrectly.

I have an idea what could go wrong if your GitLab version is 12 or later.

Since version 12 SubGit incorrectly detects GitLab. It is important that SubGit detects GitLab correctly, see https://subgit.com/documentation/gitlab.html#mirror_configure :

Make sure you see the line
{code}
Git repository is served by GitLab, hooks will be installed into ‘custom_hooks’ directory.
{code}

This is because unlike other Git server software, GitLab keeps per-repository hooks at ‘custom_hooks’ instead of ‘hooks’ directory. This is controlled by
{code}
[hooks]
directory = custom_hooks
{code}
option in GIT_REPO/subgit/config which is auto-generated if SubGit detects GitLab and should be added manually if SubGit fails to detect GitLab (SubGit <= 3.3.6 fails to detect GitLab >= 12).

If the option is not set, SubGit tries to install its hooks into GIT_REPO/hooks directory. For the most of the server this is correct behaviour, but in case of GitLab, GIT_REPO/hooks is a symlink to a location (afair, /opt/gitlab/embedded/service/gitlab-shell ) where GitLab hooks reside.

I suspect that you tried to install SubGit and it complained that it couldn’t write to the directory by GIT_REPO/hooks because of permissions issue. Then probably (just a guess) you used ‘root’ system user or another user to overcome this issue and have just overwritten GitLab’s own hooks (which are common for all repositories). This shouldn’t be done as this could break the whole GitLab.

If this is what happened to you, I would recommend you to

  1. To analyze the content of /opt/gitlab/embedded/service/gitlab-shell directory and its subdirectories, it should contain no SubGit-specific hooks (I guess it does).
  2. To check GIT_REPO/ directory whether it
  • has ‘hooks’ symlink; were does it point?
  • has ‘custom_hooks’ directory; what is the content?
  1. On some another machine or container install GitLab from scratch (just temporary).
  2. Have a look at /opt/gitlab/embedded/service/gitlab-shell directory files and their permissions on the fresh GitLab installation. On your original machine remove everything SubGit-specific from /opt/gitlab/embedded/service/gitlab-shell and make sure that
  • your original machine content and permissions of /opt/gitlab/embedded/service/gitlab-shell
  • is the same as content and permissions of /opt/gitlab/embedded/service/gitlab-shell on the fresh installation (copy the files from the fresh installation, if they are missing or differ)
  1. In your Git repository directory (I denote it as GIT_REPO) edit SubGit config file to set:
    {code}
    [hooks]
    directory = custom_hooks
    {code}
  2. Make sure all GIT_REPO files and directories belong to ‘git’ system user and that GIT_REPO/hooks is a symlink that points to a correct place. To find out what is the correct place you can create a repository on your temporary fresh GitLab installation.
  3. Run “subgit install GIT_REPO” on behalf of ‘git’ system user.
  4. Make sure the previous step creates GIT_REPO/custom_hooks directory with SubGit-specific hooks.

Now your GitLab installation should be repaired.

If you have further problems, contact us again and attach
“ls -l” output of your GIT_REPO, GIT_REPO/hooks, and GIT_REPO/custom_hooks directories and also

“ls -lR” of /opt/gitlab/embedded/service/gitlab-shell directory.

I hope this helps.

Hi Dmitry,

Yes you were right. I clobbered the gitlab hooks.

I updated to v12 and added to the configuration and it is working now.

What’s strange is that I copied stuff from another test project I started several months ago with subgit 3.3.5 and gitlab v11.7.5. Somehow the ‘hooks’ directory is not a link in that project but has the subgit hooks in it, and the subgit/conf does not have the [hooks] section.

It’s still working migrated to gitlab 12. Not sure how that happened or how it was working with gitlab 11 if the hooks link got clobbered.

# cd old_project.git/hooks
# ls
fast-post-receive  post-receive  user-post-receive.sample
fast-pre-receive   pre-receive   user-pre-receive.sample

just checked and it’s syncing fine…