1

I pulled a repository and cleaned irrelevant parts. Locally everything is perfect. I want to keep history from previous repo.

Then I created another repository, a clean one. But push is failing due to pre-receive hook declined

I am quite sure I don't have that kind of stuff on my repository :)

I tried with several commands like --force-with-lease, without a luck.

What can be the problem here, Is there something wrong with previous repository that I pulled from.

git push --verbose --set-upstream origin Last-backup:pushed-from-different-repo --force-with-lease
Pushing to git@gitlab.localhost:tkcn/history-recovery.git
Enter passphrase for key '---/.ssh/id_rsa':
Counting objects: 415402, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (129955/129955), done.
Writing objects: 100% (415402/415402), 78.71 MiB | 271.00 KiB/s, done.
Total 415402 (delta 229277), reused 411834 (delta 226634)
remote: Resolving deltas: 100% (229277/229277), done.
remote: Checking connectivity: 415402, done.
remote: GitLab: Push operation timed out
remote:
remote: Timing information for debugging purposes:
remote: Running checks for ref: pushed-from-different-repo
remote: Checking if you are allowed to push... (5.83ms)
remote: Checking if default branch is being deleted... (0.12ms)
remote: Scanning repository for blobs stored in LFS and verifying their files have been uploaded to GitLab... (25.63ms)
remote: Checking if branch follows the naming patterns defined by the project... (3.38ms)
remote: Validating diff contents... (cancelled after 41262.16ms)
To gitlab.localhost:tkcn/history-recovery.git
 ! [remote rejected]       Last-backup -> pushed-from-different-repo (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.localhost:tkcn/history-recovery.git'

git subtree split and git filter-branch --prune-empty didn't worked since the folders moved several times in the history.

Most suitable solution on stackoverflow looks like https://stackoverflow.com/a/14764368/559873 However I am unable to run this on my windows machine.

tkcn
  • 516
  • 3
  • 10
  • 29
  • 2
    GitLab runs some kind of check on the changes but it's taking too long (hence the "cancelled after 41262.16ms"), so it finally gets killed and the entire operation aborts. – Jan Krüger Feb 22 '19 at 18:53

3 Answers3

4

The pre-receive hooks are executed on the remote git server (gitlab, github or any git server) not the workstation/server where you have your git repository cloned, (do not confuse with pre-commit hooks, pre-commit hooks scripts are executed before you commit to your cloned repo and are located in YOUR_REPO/.git/hooks/)

Basically the git remote server where you are trying to push your Project (repo in github language), has a pre-commit hook enabled, that is usually set up on purpose by the owner/admin of the Group (equivalent to organization in GitHub) in order to ensure that any push event is following certain quality checks.

EDITED:

If you pay attention on the verbosity of the push error of your git push, you can see several check steps have been passed like the branch name, etc but it fails because the validating diff part is taking longer than the timeout.

remote: Validating diff contents... (cancelled after 41262.16ms)

You can also contact the admin of the Group (organization) where your project/repo lives in for further details on the quality checks expected by the pre-receive hook

theraulpareja
  • 496
  • 3
  • 9
  • 1
    Actually I think the problem is the *canceled after* line, which suggests it spent over 40 seconds looking at diffs, and then timed out. Still, the solution is the same: find out from whoever runs the server what they're checking and how to get your stuff allowed by those checks. – torek Feb 22 '19 at 19:51
  • 1
    You are right the "Validating diff contents... (cancelled after 41262.16ms)" is exceeding the timeout I'll edit now, thanks @torek – theraulpareja Feb 22 '19 at 20:03
3

After running garbage collection I was able to push successfully.

git reset --hard
git gc --aggressive
git prune
git clean -df
tkcn
  • 516
  • 3
  • 10
  • 29
  • 1
    Whether that works will be highly dependent on your repository size and state. It didn't work in my case. – Dan Apr 23 '19 at 19:09
  • be carefule before you run this, This can erase all your files in your project.... – KingJoeffrey Feb 12 '22 at 09:42
  • $ git reset --hard HEAD is now at acfbe29e42 SUP-20094: Import flow Initial changes
    $ git gc --aggressive
    Enumerating objects: 350738, done.
    $ git prune
    $ git clean -df
    $ git push origin +Head
    Enumerating objects: 75, done.
    ...
    Compressing objects: 100% (31/31), done.
    ...
    To http://algo-bitbucket.algosec.com:7990/scm/suit/ms-bflow.git ! [remote rejected] Head -> side/***i/S**-20094 (pre-receive hook declined)
    error: failed to push some refs to 'http://algo-bitbucket.algosec.com:7990/scm/suit/ms-bflow.git'
    $
    – Shakti Pravesh Sep 27 '22 at 05:47
0

Check to see what your remote.origin.url is using git config --list. My issue was that my remote.origin.url was set to git https://oauth2:gitAccessToken@gitlab.com/.../user.git. Obviously it doesn't need the '.git' at the end, but I was copying and pasting from Gitlab's dropdown clone options. Once I reset my remote.origin.url correctly with git remote set-url origin <repository-url> it worked!