<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Ticket search results</title><link>https://forge-allura.apache.org/p/allura/tickets/</link><description>You searched for labels:"curl"</description><language>en</language><lastBuildDate>Thu, 20 Aug 2015 22:07:10 -0000</lastBuildDate><item><title>SVN/Git refresh hooks fail for redirects</title><link>https://forge-allura.apache.org/p/allura/tickets/6894/</link><description>*Originally created by:* rferreira-itav

Hi

I've been having a problem where repositories in an Allura instance failed to refresh after a git or svn commit was pushed into the repository. It turns out that the curl call in the repository hooks was hitting an HTTP redirect which caused it to never call the /auth/repo_refresh/ API.


Here is a detailed walkthrough.
Whenever a commit is pushed, a hook invokes curl to do a refresh, e.g.

    curl http://staging.hostname.com//auth/refresh_repo/p/test/code/

Notice that this particular URL starts with a double slash (__//__). This happened because the **base_url** option in the settings file had a trailing slash i.e.

    base_url = http://staging.hostname.com/

Since the hook generators in *ForgeGit/forgegit/model/git_repo.py* and *ForgeSVN/forgesvn/model/svn.py* generate the URL by appending the path to the base_url 

    url=tg.config.get('base_url', 'http://localhost:8080')
            + '/auth/refresh_repo' + self._repo.url())

the URL path will start with a double slash(**//**).

This will cause the webserver to return a 301 redirect with a fixed path

    &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
    &lt;html&gt;&lt;head&gt;
    &lt;title&gt;301 Moved Permanently&lt;/title&gt;
    &lt;/head&gt;&lt;body&gt;
    &lt;h1&gt;Moved Permanently&lt;/h1&gt;
    &lt;p&gt;The document has moved &lt;a href="http://staging.hostname.com/auth/refresh_repo/p/test/code/"&gt;here&lt;/a&gt;.&lt;/p&gt;
    &lt;/body&gt;&lt;/html&gt;

This will cause curl to immediately stop, because curl does not follow redirects by default.

A couple of solutions come to mind, but I don't know if the current behaviour is intentional or not, so they might not make sense:

1. The quickest solution (for my case at least) was to fix the **base_url**, removing the trailing slash. But it might make sense in other setups for a redirect to be there. Also this does not fix existing repositories, since the hooks were already saved.
2. Changing the hooks to pass the **-L** parameter to curl, causes curl to follow redirects
3. Change *ForgeGit/forgegit/model/git_repo.py* and *ForgeSVN/forgesvn/model/svn.py* to sanitise the URL before generating the hook

Like I said, I don't know if the current behaviour (no redirects) is intentional or not, but at least (3.) would easily avoid trailing slash issues.

Hope this helps, cheers.

</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Anonymous</dc:creator><pubDate>Thu, 20 Aug 2015 22:07:10 -0000</pubDate><guid>https://forge-allura.apache.org/p/allura/tickets/6894/</guid></item></channel></rss>