File: iki-git-hook-update.c

package info (click to toggle)
ikiwiki-hosting 0.20140613
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 788 kB
  • ctags: 283
  • sloc: perl: 5,124; sh: 182; ansic: 168; makefile: 50
file content (48 lines) | stat: -rw-r--r-- 1,176 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * git update hook that allows trusted sources to make any change,
 * while untrusted sources may only push changes that seem safe.
 *
 * (iki-git-shell sets UNTRUSTED_COMMIT=1 for commits pushed from external
 * sources)
 *
 * In C for speed.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main (int argc, char **argv) {
	char *untrusted=getenv("UNTRUSTED_COMMIT");

	if (argc != 4) {
		fprintf(stderr, "expected: <ref> <oldrev> <newrev>\n");
		exit(1);
	}

	if (! untrusted || strcmp(untrusted, "1") != 0) {
		exit(0);
	}

	if (strcmp(argv[3], "0000000000000000000000000000000000000000") == 0) {
		/* don't allow deletion of master branch or the setup
		 * branch, which would hose the site */
		if (strcmp(argv[1], "refs/heads/master") == 0 ||
		    strcmp(argv[1], "refs/heads/setup") == 0) {
			fprintf(stderr, "you are not allowed to delete %s\n", argv[1]);
			exit(1);
		}
	}

	/* Use ikisite to check modifications of the setup branch. */
	if (strcmp(argv[1], "refs/heads/setup") == 0) {
		unsetenv("GIT_DIR");
		execlp("ikisite", "ikisite", "checksetup", argv[3], NULL);
		perror("ikisite");
		exit(1);
	}

	exit(0);
}