Automatically updating version control!

There is no logical reason why I am THIS excited about getting my post-commit hook working. But I am! Now when I commit changes from my working copy, the post-commit hook will automatically update the working copy in the folder serving the “beta” sub-domain.
 
In order to get the post-commit hook working with svn, I had to create a small C program (as recommended by the official documentation). I copied it (modifying the paths), compiled it via SSH on my web host and tested it through SSH and found it to work successfully. However, when I made a commit, the post-commit hook failed with exit code 255 with no output.
 
I double-checked my permissions on the C program and tried again, but still the same error. I then tried commenting out the call to the C program and added a simple “whoami >> [path]/whoami.txt” to see who was executing the post-commit hook.
 
Post-commit hook failed with exit code (255) and no output.
 
Ok, NOW we’re getting somewhere. Whatever user account that’s trying to access the post-commit hook script can’t even access the script. I tried chmod-ing the repository, recursively, to 777 (read/write/execute for all) and did another commit. SUCCESS! I found a “whoami.txt” file, but surprisingly, it was my login (which had permissions to begin with).
 
Un-commenting the line that executes the C program to update a different working copy, I made another commit. This time, I started getting meaningful failure messages. The first message stated an authentication failure, so I modified the C program to include my username and password and recompiled it. Another error but this time it was due to requesting interaction (“are you sure you want to overwrite…”). Modified the C program one last time, adding the no-interaction flag, compiled and tested one last commit.
 
Bingo!
 
No error messages and the beta section of the website was updated automatically!
 
In short, to get the post-commit hooks working with svn I needed to:
 

  1. (via SSH) CHMOD -R 777 [path to repo]
  2. Create the following C program:
    #include <stddef.h>
    #include <stdlib.h>
    #include <unistd.h>
    int main(void) {
       execl("[path to svn executable]", "svn", "update", "[path to WC to update]", "--non-interactive", "--username", "[username]", "--password", "[password]",(const char *) NULL);
       return(EXIT_FAILURE);
    }

    Note: MUST have blank line at the end (at least my gcc compiler complained about the lack of one the first time). The code formatter above removes it.

  3. Upload the C-source to my website and compile
  4. (via SSH) CHMOD +s [compiled C-program]
  5. Since my host is a linux host, create a file in the “hooks” directory of the repo named “post-commit”
  6. Add the following two lines to the “post-commit” file:
    #!/bin/sh
    [path to repo]/hooks/[compiled C-program]
  7. Test the post-commit hook by performing a commit
Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *