ref: 254e6855efd805fda2826f324169009c8b0a4105
dir: /test/gtest.c/
#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); \ } else { \ print("√ %s\n", B); \ } void main(void) { int fd; char buf[128]; Gitlog *logs; 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), "git add file"); test(gitcommit("add file\n\nsecond line\nthird line", addfile, nil), "git commit add"); test(gitrm(addfile, nil), "git rm file"); test(gitcommit("remove file", addfile, nil), "git commit rm"); test(gitlog(&logs, 2, nil, nil), "git log 2"); print("PRINT LOGS:\n"); for (Gitlog *l = logs; l->hash; l++) { print("hash: %s\n", l->hash); print("author: %s\n", l->author); print("date: %s\n", l->date); print("msg: %s\n-\n", l->message); } print("END PRINT LOGS\n"); test(freegitlogs(logs), "free gitlogs"); logs = nil; }