Merge branch 'jk/relative-directory-fix'
[git] / t / helper / test-write-cache.c
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "lockfile.h"
4
5 static struct lock_file index_lock;
6
7 int cmd__write_cache(int argc, const char **argv)
8 {
9         int i, cnt = 1, lockfd;
10         if (argc == 2)
11                 cnt = strtol(argv[1], NULL, 0);
12         setup_git_directory();
13         read_cache();
14         for (i = 0; i < cnt; i++) {
15                 lockfd = hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
16                 if (0 <= lockfd) {
17                         write_locked_index(&the_index, &index_lock, COMMIT_LOCK);
18                 } else {
19                         rollback_lock_file(&index_lock);
20                 }
21         }
22
23         return 0;
24 }