2011-02-11

Denying non-fast-forward and SourceForge

Well, I have it from good source that deleting commits, on a public source, is actually fine if you have a good reason to do so. But what if that public source happens to be a git repositoty on SourceForge?

Let's say you wanted to push some code modifications, so you added a source (or so you thought), but realize after commit & push, that what you really added was the binary rather than the .c. Don't want your public repo to be polluted by unneeded binaries.

So you tried:
git reset --hard HEAD~1
git push origin +master:master
or
git commit --amend
but every time you push you get the error:
error: denying non-fast-forward refs/heads/master (you should pull first)
To ssh://USER@PROJECT.git.sourceforge.net/gitroot/PROJECT
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://USER@PROJECT.git.sourceforge.net/gitroot/PROJECT'
What gives?

A good search will of course lead you to ticket #9187 and receive.denyNonFastforwards being set to true by default on the remote git repository provided by SourceForge.

How can you edit your remote config to unset denyNonFastforwards? Easy:
ssh -t USER,PROJECT@shell.sourceforge.net create
[USER@shell-24010 ~]$ sf-help
(...) 
Your project DSCM repositories are here (use adminrepo for CVS and SVN):

    /home/scm_git/U/US/USER.u
    /home/scm_git/P/PR/PROJECT
(...)
[USER@shell-24010 ~]$ cd /home/scm_git/P/PR/PROJECT
[USER@shell-24010 PROJECT]$ ls -alFh
total 12K
drwxrwsr-x 3 dummy PROJECT   80 Nov 29 19:15 ./
drwxr-xr-x 3 root  root    4.0K Feb 10 21:58 ../
drwxrwsr-x 7 dummy PROJECT 1.0K Nov 29 19:15 PROJECT/
[USER@shell-24010 PROJECT]$ cd PROJECT
[USER@shell-24010 PROJECT]$ ls -alFh
total 48K
drwxrwsr-x   7 dummy PROJECT 1.0K Nov 29 19:15 ./
drwxrwsr-x   3 dummy PROJECT   80 Nov 29 19:15 ../
-rw-rw-r--   1 dummy PROJECT   23 Nov 29 19:15 HEAD
drwxrwsr-x   2 dummy PROJECT   80 Nov 29 19:15 branches/
-rw-rw-r--   1 dummy PROJECT  126 Nov 29 19:15 config
-rw-rw-r--   1 dummy PROJECT    5 Nov 29 19:15 description
drwxrwsr-x   2 dummy PROJECT 1.0K Nov 29 19:15 hooks/
drwxrwsr-x   2 dummy PROJECT   80 Nov 29 19:15 info/
drwxrwsr-x 133 dummy PROJECT 5.0K Feb 10 21:41 objects/
drwxrwsr-x   4 dummy PROJECT   80 Nov 29 19:15 refs/
Yay, there's a config there:
[USER@shell-24010 PROJECT]$ vi config
Then remove/unset that pesky denyNonFastforwards and you're good to go.

4 comments:

  1. Hi Pete,
    Thanks a lot for the post, it was just what I was looking for. Even after resetting the option, I am still not able to push an earlier commit to rewrite history, do I need to do something like load the config file ?
    Thanks again,
    Avinash

    ReplyDelete
  2. Hi Avinash,
    Make sure you use --force when pushing. I recently found that one could get the non-fast-forward error when trying to push tags, even with the edited config. All that was needed was to add the --force option when pushing then.

    ReplyDelete
  3. Thank you very much for this post!

    ReplyDelete
  4. Thank you! It worked for me, but not exactly with the same path.

    I should edit 'config' in /home/git/... instead of /home/scm_git/...

    The 'config' file exists in both paths but the one in /home/scm_git/... seems to have no effect, at least for non-fast-forward.

    I found this solution in this post: http://stackoverflow.com/questions/12450703/source-forge-repo-gives-denying-non-fast-forward-refs-heads-master-error

    Then it works fine for me.

    ReplyDelete