Commit 5ad739e8328c665b629e2285abaec7e12ea8397c

Vicent Marti 2011-07-04T20:05:11

fileops: Drop `git_fileops_prettify_path` The old `git_fileops_prettify_path` has been replaced with `git_path_prettify`. This is a much simpler method that uses the OS's `realpath` call to obtain the full path for directories and resolve symlinks. The `realpath` syscall is the original POSIX call in Unix system and an emulated version under Windows using the Windows API.

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
diff --git a/src/fileops.c b/src/fileops.c
index 486ea3b..275934c 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -125,18 +125,16 @@ int git_futils_isfile(const char *path)
 	struct stat st;
 	int stat_error;
 
-	if (!path)
-		return git__throw(GIT_ENOTFOUND, "No path given to git_futils_isfile");
-
+	assert(path);
 	stat_error = p_stat(path, &st);
 
 	if (stat_error < GIT_SUCCESS)
-		return git__throw(GIT_ENOTFOUND, "%s does not exist", path);
+		return -1;
 
 	if (!S_ISREG(st.st_mode))
-		return git__throw(GIT_ENOTFOUND, "%s is not a file", path);
+		return -1;
 
-	return GIT_SUCCESS;
+	return 0;
 }
 
 int git_futils_exists(const char *path)
@@ -149,7 +147,8 @@ git_off_t git_futils_filesize(git_file fd)
 {
 	struct stat sb;
 	if (p_fstat(fd, &sb))
-		return git__throw(GIT_EOSERR, "Failed to get size of file. File missing or corrupted");
+		return GIT_ERROR;
+
 	return sb.st_size;
 }
 
@@ -273,22 +272,6 @@ int git_futils_direach(
 	return GIT_SUCCESS;
 }
 
-int git_futils_root_offset(const char *path)
-{
-	int offset = 0;
-
-#ifdef GIT_WIN32
-	/* Does the root of the path look like a windows drive ? */
-	if (isalpha(path[0]) && (path[1] == ':'))
-		offset += 2;
-#endif
-
-	if (*(path + offset) == '/')
-		return offset;
-
-	return -1;	/* Not a real error. Rather a signal than the path is not rooted */
-}
-
 int git_futils_mkdir_r(const char *path, int mode)
 {
 	int error, root_path_offset;
@@ -301,7 +284,7 @@ int git_futils_mkdir_r(const char *path, int mode)
 	error = GIT_SUCCESS;
 	pp = path_copy;
 
-	root_path_offset = git_futils_root_offset(pp);
+	root_path_offset = git_path_root(pp);
 	if (root_path_offset > 0)
 		pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */
 
@@ -338,7 +321,7 @@ static int retrieve_previous_path_component_start(const char *path)
 {
 	int offset, len, root_offset, start = 0;
 
-	root_offset = git_futils_root_offset(path);
+	root_offset = git_path_root(path);
 	if (root_offset > -1)
 		start += root_offset;
 
@@ -373,7 +356,7 @@ int git_futils_prettify_dir(char *buffer_out, size_t size, const char *path, con
 	buffer_end = path + strlen(path);
 	buffer_out_start = buffer_out;
 
-	root_path_offset = git_futils_root_offset(path);
+	root_path_offset = git_path_root(path);
 	if (root_path_offset < 0) {
 		if (base_path == NULL) {
 			error = p_getcwd(buffer_out, size);
@@ -446,7 +429,6 @@ int git_futils_prettify_dir(char *buffer_out, size_t size, const char *path, con
 	}
 
 	*buffer_out = '\0';
-
 	return GIT_SUCCESS;
 }
 
@@ -472,7 +454,7 @@ int git_futils_prettyify_file(char *buffer_out, size_t size, const char *path, c
 		return error;	/* The callee already takes care of setting the correct error message. */
 
 	path_len = strlen(buffer_out);
-	root_offset = git_futils_root_offset(buffer_out) + 1;
+	root_offset = git_path_root(buffer_out) + 1;
 	if (path_len == root_offset)
 		return git__throw(GIT_EINVALIDPATH, "Failed to normalize file path `%s`. The path points to a folder", path);
 
diff --git a/src/fileops.h b/src/fileops.h
index 52eb229..c9ede49 100644
--- a/src/fileops.h
+++ b/src/fileops.h
@@ -198,6 +198,5 @@ int git_futils_prettify_dir(char *buffer_out, size_t size, const char *path, con
  */
 int git_futils_prettyify_file(char *buffer_out, size_t size, const char *path, const char *base_path);
 
-int git_futils_root_offset(const char *path);
 
 #endif /* INCLUDE_fileops_h__ */
diff --git a/src/path.c b/src/path.c
index 766f674..1f7a166 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1,4 +1,7 @@
 #include "common.h"
+#include "path.h"
+#include "posix.h"
+
 #include <stdarg.h>
 #include <stdio.h>
 #include <ctype.h>
@@ -202,3 +205,50 @@ void git_path_join_n(char *buffer_out, int count, ...)
 	*buffer_out = '\0';
 }
 
+int git_path_root(const char *path)
+{
+	int offset = 0;
+
+#ifdef GIT_WIN32
+	/* Does the root of the path look like a windows drive ? */
+	if (isalpha(path[0]) && (path[1] == ':'))
+		offset += 2;
+#endif
+
+	if (*(path + offset) == '/')
+		return offset;
+
+	return -1;	/* Not a real error. Rather a signal than the path is not rooted */
+}
+
+int git_path_prettify(char *path_out, const char *path, const char *base)
+{
+	char *result;
+
+	if (base == NULL || git_path_root(path) >= 0) {
+		result = p_realpath(path, path_out);
+	} else {
+		char aux_path[GIT_PATH_MAX];
+		git_path_join(aux_path, base, path);
+		result = p_realpath(aux_path, path_out);
+	}
+
+	return result ? GIT_SUCCESS : GIT_EOSERR;
+}
+
+int git_path_prettify_dir(char *path_out, const char *path, const char *base)
+{
+	size_t end;
+
+	if (git_path_prettify(path_out, path, base) < GIT_SUCCESS)
+		return GIT_EOSERR;
+
+	end = strlen(path_out);
+
+	if (end && path_out[end - 1] != '/') {
+		path_out[end] = '/';
+		path_out[end + 1] = '\0';
+	}
+
+	return GIT_SUCCESS;
+}
diff --git a/src/path.h b/src/path.h
index 1bae9df..36e22a7 100644
--- a/src/path.h
+++ b/src/path.h
@@ -59,6 +59,11 @@ GIT_INLINE(void) git_path_join(char *buffer_out, const char *path_a, const char 
 	git_path_join_n(buffer_out, 2, path_a, path_b);
 }
 
+int git_path_root(const char *path);
+
+int git_path_prettify(char *path_out, const char *path, const char *base);
+int git_path_prettify_dir(char *path_out, const char *path, const char *base);
+
 #ifdef GIT_WIN32
 GIT_INLINE(void) git_path_mkposix(char *path)
 {
diff --git a/src/repository.c b/src/repository.c
index a8ead3a..48c8e2b 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -39,7 +39,6 @@
 #define GIT_OBJECTS_PACK_DIR GIT_OBJECTS_DIR "pack/"
 
 #define GIT_FILE_CONTENT_PREFIX "gitdir: "
-#define GIT_FILE_CONTENT_PREFIX_LENGTH 8
 
 #define GIT_BRANCH_MASTER "master"
 
@@ -135,7 +134,7 @@ static int check_repository_dirs(git_repository *repo)
 
 	/* Ensure HEAD file exists */
 	git_path_join(path_aux, repo->path_repository, GIT_HEAD_FILE);
-	if (git_futils_exists(path_aux) < 0)
+	if (git_futils_isfile(path_aux) < 0)
 		return git__throw(GIT_ENOTAREPO, "HEAD file is missing");
 
 	return GIT_SUCCESS;
@@ -160,6 +159,26 @@ static int guess_repository_dirs(git_repository *repo, const char *repository_pa
 	return assign_repository_dirs(repo, repository_path, NULL, NULL, path_work_tree);
 }
 
+static int quickcheck_repository_dir(const char *repository_path)
+{
+	char path_aux[GIT_PATH_MAX];
+
+	/* Ensure HEAD file exists */
+	git_path_join(path_aux, repository_path, GIT_HEAD_FILE);
+	if (git_futils_isfile(path_aux) < 0)
+		return GIT_ERROR;
+
+	git_path_join(path_aux, repository_path, GIT_OBJECTS_DIR);
+	if (git_futils_isdir(path_aux) < 0)
+		return GIT_ERROR;
+
+	git_path_join(path_aux, repository_path, GIT_REFS_DIR);
+	if (git_futils_isdir(path_aux) < 0)
+		return GIT_ERROR;
+
+	return GIT_SUCCESS;
+}
+
 static git_repository *repository_alloc()
 {
 	int error;
@@ -352,23 +371,6 @@ cleanup:
 	return git__rethrow(error, "Failed to open repository");
 }
 
-static int abspath(char *buffer_out, size_t size, const char *path)
-{
-	assert(buffer_out && size >= GIT_PATH_MAX);
-
-	#ifdef GIT_WIN32
-		if (_fullpath(buffer_out, path, size) == NULL)
-			return git__throw(GIT_EOSERR, "Failed to retrieve real path: %s causing errors", buffer_out);
-	#else
-		if (realpath(path, buffer_out) == NULL)
-			return git__throw(GIT_EOSERR, "Failed to retrieve real path: %s causing errors", buffer_out);
-	#endif
-
-	git_path_mkposix(buffer_out);
-
-	return GIT_SUCCESS;
-}
-
 static int retrieve_device(dev_t *device_out, const char *path)
 {
 	struct stat path_info;
@@ -393,7 +395,7 @@ static int retrieve_ceiling_directories_offset(const char *path, const char *cei
 
 	assert(path);
 
-	min_len = git_futils_root_offset(path) + 1;
+	min_len = git_path_root(path) + 1;
 
 	if (ceiling_directories == NULL || min_len == 0)
 		return min_len;
@@ -402,13 +404,13 @@ static int retrieve_ceiling_directories_offset(const char *path, const char *cei
 		for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
 		len = sep - ceil;
 
-		if (len == 0 || len > GIT_PATH_MAX || git_futils_root_offset(ceil) == -1)
+		if (len == 0 || len > GIT_PATH_MAX || git_path_root(ceil) == -1)
 			continue;
 
 		strncpy(buf, ceil, len);
 		buf[len] = '\0';
 
-		if (abspath(buf2, sizeof(buf2), buf) < GIT_SUCCESS)
+		if (p_realpath(buf, buf2) == NULL)
 			continue;
 
 		len = strlen(buf2);
@@ -426,13 +428,13 @@ static int retrieve_ceiling_directories_offset(const char *path, const char *cei
 	return max_len <= min_len ? min_len : max_len;
 }
 
-static int read_gitfile(char *path_out, size_t size, const char *file_path, const char *base_path)
+static int read_gitfile(char *path_out, const char *file_path, const char *base_path)
 {
 	git_fbuffer file;
 	int error, end_offset;
 	char *data;
 
-	assert(file_path && path_out && size > 0);
+	assert(path_out && file_path && path_out);
 
 	error = git_futils_readbuffer(&file, file_path);
 
@@ -451,22 +453,19 @@ static int read_gitfile(char *path_out, size_t size, const char *file_path, cons
 	for (;data[end_offset] == '\r' || data[end_offset] == '\n'; --end_offset);
 	data[end_offset + 1] = '\0';
 
-	if (GIT_FILE_CONTENT_PREFIX_LENGTH == end_offset + 1) {
+	if (STRLEN(GIT_FILE_CONTENT_PREFIX) == end_offset + 1) {
 		git_futils_freebuffer(&file);
 		return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
 	}
 
-	error = git_futils_prettify_dir(path_out, size, data + GIT_FILE_CONTENT_PREFIX_LENGTH, base_path);
-	if (error == GIT_SUCCESS) {
-		end_offset = strlen(path_out);
-
-		if (end_offset > 0 && path_out[end_offset - 1] == '/')
-			path_out[end_offset - 1 ] = '\0';
-	}
-
+	data = data + STRLEN(GIT_FILE_CONTENT_PREFIX);
+	error = git_path_prettify_dir(path_out, data, base_path);
 	git_futils_freebuffer(&file);
 
-	return error;
+	if (error == 0 && git_futils_exists(path_out) == 0)
+		return GIT_SUCCESS;
+
+	return git__throw(GIT_EOBJCORRUPTED, "The `.git` file points to an inexisting path");
 }
 
 static void git_repository__free_dirs(git_repository *repo)
@@ -498,7 +497,6 @@ void git_repository_free(git_repository *repo)
 
 int git_repository_discover(char *repository_path, size_t size, const char *start_path, int across_fs, const char *ceiling_dirs)
 {
-	git_repository repo;
 	int error, ceiling_offset;
 	char bare_path[GIT_PATH_MAX];
 	char normal_path[GIT_PATH_MAX];
@@ -506,80 +504,70 @@ int git_repository_discover(char *repository_path, size_t size, const char *star
 	dev_t current_device = 0;
 
 	assert(start_path && repository_path);
-	memset(&repo, 0x0, sizeof(git_repository));
-
-	error = abspath(bare_path, sizeof(bare_path), start_path);
 
+	error = git_path_prettify_dir(bare_path, start_path, NULL);
 	if (error < GIT_SUCCESS)
-		goto cleanup;
+		return error;
 
 	if (!across_fs) {
 		error = retrieve_device(&current_device, bare_path);
-
 		if (error < GIT_SUCCESS)
-			goto cleanup;
+			return error;
 	}
 
 	ceiling_offset = retrieve_ceiling_directories_offset(bare_path, ceiling_dirs);
 	git_path_join(normal_path, bare_path, DOT_GIT);
 
-	while(1){
-		//look for .git file
+	while(1) {
+		/**
+		 * If the `.git` file is regular instead of
+		 * a directory, it should contain the path of the actual git repository
+		 */
 		if (git_futils_isfile(normal_path) == GIT_SUCCESS) {
-			error = read_gitfile(repository_path, size, normal_path, bare_path);
-
-			if (error < GIT_SUCCESS) {
-				git__rethrow(error, "Unable to read git file `%s`", normal_path);
-				goto cleanup;
-			}
+			error = read_gitfile(repository_path, normal_path, bare_path);
 
-			error = discover_repository_dirs(&repo, repository_path);
 			if (error < GIT_SUCCESS)
-				goto cleanup;
+				return git__rethrow(error, "Unable to read git file `%s`", normal_path);
 
-			git_repository__free_dirs(&repo);
+			error = quickcheck_repository_dir(repository_path);
+			if (error < GIT_SUCCESS)
+				return git__throw(GIT_ENOTFOUND, "The `.git` file found at '%s' points"
+					"to an inexisting Git folder", normal_path);
 
 			return GIT_SUCCESS;
 		}
 
-		//look for .git repository
-		error = discover_repository_dirs(&repo, normal_path);
-		if (error < GIT_SUCCESS && error != GIT_ENOTAREPO)
-			goto cleanup;
-
-		if (error == GIT_SUCCESS) {
-			found_path = normal_path;
-			break;
+		/**
+		 * If the `.git` file is a folder, we check inside of it
+		 */
+		if (git_futils_isdir(normal_path) == GIT_SUCCESS) {
+			error = quickcheck_repository_dir(normal_path);
+			if (error == GIT_SUCCESS) {
+				found_path = normal_path;
+				break;
+			}
 		}
 
-		git_repository__free_dirs(&repo);
-
-		//look for bare repository in current directory
-		error = discover_repository_dirs(&repo, bare_path);
-		if (error < GIT_SUCCESS && error != GIT_ENOTAREPO)
-			goto cleanup;
-
+		/**
+		 * Otherwise, the repository may be bare, let's check
+		 * the root anyway
+		 */
+		error = quickcheck_repository_dir(bare_path);
 		if (error == GIT_SUCCESS) {
 			found_path = bare_path;
 			break;
 		}
 
-		git_repository__free_dirs(&repo);
-
 		if (git_path_dirname_r(normal_path, sizeof(normal_path), bare_path) < GIT_SUCCESS)
-			goto cleanup;
+			return git__throw(GIT_EOSERR, "Failed to dirname '%s'", bare_path);
 
 		if (!across_fs) {
 			dev_t new_device;
 			error = retrieve_device(&new_device, normal_path);
 
-			if (error < GIT_SUCCESS)
-				goto cleanup;
-
-			if (current_device != new_device) {
-				error = git__throw(GIT_ENOTAREPO,"Not a git repository (or any parent up to mount parent %s)\n"
-					"Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM_ENVIRONMENT not set).", bare_path);
-				goto cleanup;
+			if (error < GIT_SUCCESS || current_device != new_device) {
+				return git__throw(GIT_ENOTAREPO,"Not a git repository (or any parent up to mount parent %s)\n"
+					"Stopping at filesystem boundary.", bare_path);
 			}
 			current_device = new_device;
 		}
@@ -587,27 +575,18 @@ int git_repository_discover(char *repository_path, size_t size, const char *star
 		strcpy(bare_path, normal_path);
 		git_path_join(normal_path, bare_path, DOT_GIT);
 
-		//nothing has been found, lets try the parent directory
+		// nothing has been found, lets try the parent directory
 		if (bare_path[ceiling_offset] == '\0') {
-			error = git__throw(GIT_ENOTAREPO,"Not a git repository (or any of the parent directories): %s", start_path);
-			goto cleanup;
+			return git__throw(GIT_ENOTAREPO,"Not a git repository (or any of the parent directories): %s", start_path);
 		}
-
 	}
 
-	if (size < (strlen(found_path) + 1) * sizeof(char)) {
-		error = git__throw(GIT_EOVERFLOW, "The repository buffer is not long enough to handle the repository path `%s`", found_path);
-		goto cleanup;
+	if (size < (strlen(found_path) + 2) * sizeof(char)) {
+		return git__throw(GIT_EOVERFLOW, "The repository buffer is not long enough to handle the repository path `%s`", found_path);
 	}
 
-	strcpy(repository_path, found_path);
-	git_repository__free_dirs(&repo);
-
+	git_path_join(repository_path, found_path, "");
 	return GIT_SUCCESS;
-
-	cleanup:
-		git_repository__free_dirs(&repo);
-		return git__rethrow(error, "Failed to discover repository");
 }
 
 git_odb *git_repository_database(git_repository *repo)
@@ -689,15 +668,17 @@ static int repo_init_structure(repo_init *results)
 static int repo_init_find_dir(repo_init *results, const char* path)
 {
 	char temp_path[GIT_PATH_MAX];
-	int error = GIT_SUCCESS;
+	int error;
 
 	error = git_futils_prettify_dir(temp_path, sizeof(temp_path), path, NULL);
 	if (error < GIT_SUCCESS)
-		return git__rethrow(error, "Failed to find directory to initialize repository");
+		return git__throw(GIT_ENOTFOUND, "Invalid directory to initialize repository");
 
-	if (!results->is_bare) {
+//	if (p_realpath(path, temp_path) == NULL)
+//		return git__throw(GIT_ENOTFOUND, "Invalid directory to initialize repository");
+
+	if (!results->is_bare)
 		git_path_join(temp_path, temp_path, GIT_DIR);
-	}
 
 	results->path_repository = git__strdup(temp_path);
 	if (results->path_repository == NULL)
diff --git a/src/unix/posix.h b/src/unix/posix.h
index ab98c45..0793739 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -9,6 +9,6 @@
 #define p_unlink(p) unlink(p)
 #define p_mkdir(p,m) mkdir(p, m)
 #define p_fsync(fd) fsync(fd)
-#define p_realpath(p, r) realpath(p, r)
+#define p_realpath(p, po) realpath(p, po)
 
 #endif
diff --git a/src/win32/posix.c b/src/win32/posix.c
index 003ce1f..610a416 100644
--- a/src/win32/posix.c
+++ b/src/win32/posix.c
@@ -1,4 +1,5 @@
 #include "posix.h"
+#include "path.h"
 #include <errno.h>
 
 int p_unlink(const char *path)
@@ -189,3 +190,13 @@ int p_hide_directory__w32(const char *path)
 	return error;
 }
 
+int p_realpath(const char *orig_path, char *buffer)
+{
+	int ret = GetFullPathName(orig_path, GIT_PATH_MAX, buffer, NULL);
+	if (!ret || ret > GIT_PATH_MAX)
+		return GIT_EOSERR;
+
+	git_path_mkposix(buffer);
+	return GIT_SUCCESS;
+}
+
diff --git a/src/win32/posix.h b/src/win32/posix.h
index 31ee720..3b5bff8 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -21,5 +21,6 @@ extern int p_unlink(const char *path);
 extern int p_lstat(const char *file_name, struct stat *buf);
 extern int p_readlink(const char *link, char *target, size_t target_len);
 extern int p_hide_directory__w32(const char *path);
+extern int p_realpath(const char *orig_path, char *buffer);
 
 #endif
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index 3b3c7c0..4881e75 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -431,15 +431,15 @@ BEGIN_TEST(discover0, "test discover")
 	must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
 	must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
 	must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs));
-	must_be_true(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO);
+	must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs));
 
 	must_pass(append_ceiling_dir(ceiling_dirs, SUB_REPOSITORY_FOLDER));
 	//this must pass as ceiling_directories cannot predent the current
 	//working directory to be checked
 	must_pass(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
-	must_be_true(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs) == GIT_ENOTAREPO);
-	must_be_true(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs) == GIT_ENOTAREPO);
-	must_be_true(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs) == GIT_ENOTAREPO);
+	must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs));
+	must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs));
+	must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
 
 	//.gitfile redirection should not be affected by ceiling directories
 	must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path));