Windows: redirect f[re]open("/dev/null") to f[re]open("nul")
On Windows, the equivalent of "/dev/null" is "nul". This implements compatibility wrappers around fopen() and freopen() that check for this particular file name. The new tests exercise code paths where this is relevant. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Feb 25, 2010 at 21:03 UTC
3fdcdbdf301dadb7af58fe038501f0af6419a2e0
4 files changed
+33
compat/mingw.c
+16
@@ -140,6 +140,22 @@ int mingw_open (const char *filename, int oflags, ...)
140
return fd;
141
}
142
143
+#undef fopen
144
+FILE *mingw_fopen (const char *filename, const char *otype)
145
+{
146
+ if (!strcmp(filename, "/dev/null"))
147
+ filename = "nul";
148
+ return fopen(filename, otype);
149
+}
150
+
151
+#undef freopen
152
+FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
153
+{
154
+ if (filename && !strcmp(filename, "/dev/null"))
155
+ filename = "nul";
156
+ return freopen(filename, otype, stream);
157
+}
158
+
159
/*
160
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
161
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.
compat/mingw.h
+6
@@ -170,6 +170,12 @@ int link(const char *oldpath, const char *newpath);
170
int mingw_open (const char *filename, int oflags, ...);
171
#define open mingw_open
172
173
+FILE *mingw_fopen (const char *filename, const char *otype);
174
+#define fopen mingw_fopen
175
+
176
+FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream);
177
+#define freopen mingw_freopen
178
+
179
char *mingw_getcwd(char *pointer, int len);
180
#define getcwd mingw_getcwd
181
t/t5510-fetch.sh
+7
@@ -341,6 +341,13 @@ test_expect_success 'fetch into the current branch with --update-head-ok' '
341
342
'
343
344
+test_expect_success 'fetch --dry-run' '
345
+
346
+ rm -f .git/FETCH_HEAD &&
347
+ git fetch --dry-run . &&
348
+ ! test -f .git/FETCH_HEAD
349
+'
350
+
351
test_expect_success "should be able to fetch with duplicate refspecs" '
352
mkdir dups &&
353
cd dups &&
t/t6023-merge-file.sh
+4
@@ -64,6 +64,10 @@ cp new1.txt test.txt
64
test_expect_success "merge without conflict" \
65
"git merge-file test.txt orig.txt new2.txt"
66
67
+cp new1.txt test.txt
68
+test_expect_success "merge without conflict (--quiet)" \
69
+ "git merge-file --quiet test.txt orig.txt new2.txt"
70
+
71
cp new1.txt test2.txt
72
test_expect_success "merge without conflict (missing LF at EOF)" \
73
"git merge-file test2.txt orig.txt new2.txt"