shithub: libgit

ref: f12b2f1cd7cd26033457a54454456158e1572834
dir: /test/gtest.c/

View raw version
#include <u.h>
#include <libc.h>
#include "../git.h"

char *dir = "/tmp/repo";
char *addfile = "test";

#define test(A, B) if (!A) { sysfatal("%s: %r\n", B); }

void
main(void)
{
	int fd;
	char buf[128];
	
	if (!initgit("/tmp/repo"))
		sysfatal("gitinit: %r");
	
	snprint(buf, sizeof(buf), "%s/%s", dir, addfile);
	
	fd = create(buf, OWRITE, 0666);
	if (fd < 0)
		sysfatal("%r");
	fprint(fd, "hello world\n");
	close(fd);
	
	test(gitadd(addfile, nil), "add file");
	test(gitcommit("add file", addfile, nil), "commit add");
	test(gitrm(addfile, nil), "rm file");
	test(gitcommit("remove file", addfile, nil), "commit rm");
}