Skip to content

Commit 3fdcdbd

Browse files
j6tgitster
authored andcommitted
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>
1 parent 251a495 commit 3fdcdbd

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

compat/mingw.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ int mingw_open (const char *filename, int oflags, ...)
140140
return fd;
141141
}
142142

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+
143159
/*
144160
* The unit of FILETIME is 100-nanoseconds since January 1, 1601, UTC.
145161
* Returns the 100-nanoseconds ("hekto nanoseconds") since the epoch.

compat/mingw.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ int link(const char *oldpath, const char *newpath);
170170
int mingw_open (const char *filename, int oflags, ...);
171171
#define open mingw_open
172172

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+
173179
char *mingw_getcwd(char *pointer, int len);
174180
#define getcwd mingw_getcwd
175181

t/t5510-fetch.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ test_expect_success 'fetch into the current branch with --update-head-ok' '
341341
342342
'
343343

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+
344351
test_expect_success "should be able to fetch with duplicate refspecs" '
345352
mkdir dups &&
346353
cd dups &&

t/t6023-merge-file.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ cp new1.txt test.txt
6464
test_expect_success "merge without conflict" \
6565
"git merge-file test.txt orig.txt new2.txt"
6666

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+
6771
cp new1.txt test2.txt
6872
test_expect_success "merge without conflict (missing LF at EOF)" \
6973
"git merge-file test2.txt orig.txt new2.txt"

0 commit comments

Comments
 (0)