From 2328ceef54b7b2e40ad66ecd74a3451bf7c3c6d5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 9 Aug 2009 19:12:17 +0200 Subject: [PATCH] Windows: mark newly-created files whose name starts with a dot as hidden Signed-off-by: Johannes Schindelin Acked-by: Johannes Sixt --- Documentation/config.txt | 2 +- compat/mingw.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 7c6f7fcb87..30ab22b840 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -120,7 +120,7 @@ core.fileMode:: core.hideDotFiles:: (Windows-only) If true (which is the default), mark newly-created - directories whose name starts with a dot as hidden. + directories and files whose name starts with a dot as hidden. core.ignoreCygwinFSTricks:: This option is only used by Cygwin implementation of Git. If false, diff --git a/compat/mingw.c b/compat/mingw.c index 665d861389..a68ef11696 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3,6 +3,7 @@ #include #include "../strbuf.h" +extern int hide_dotfiles; unsigned int _CRT_fmode = _O_BINARY; static int err_win_to_posix(DWORD winerr) @@ -130,7 +131,6 @@ static int make_hidden(const char *path) #undef mkdir int mingw_mkdir(const char *path, int mode) { - extern int hide_dotfiles; int ret = mkdir(path); if (!ret && hide_dotfiles) { /* @@ -162,6 +162,16 @@ int mingw_open (const char *filename, int oflags, ...) if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) errno = EISDIR; } + if ((oflags & O_CREAT) && fd >= 0 && hide_dotfiles) { + /* + * In Windows a file or dir starting with a dot is not + * automatically hidden. So lets mark it as hidden when + * such a file is created. + */ + const char *start = basename((char*)filename); + if (*start == '.' && make_hidden(filename)) + warning("Could not mark '%s' as hidden.", filename); + } return fd; }