git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/2] Support marking .git/ (or all files) as hidden on Windows

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 10, 2016, 11:59 UTC
Message-ID
<cover.1462881473.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1462603453.git.johannes.schindelin@gmx.de>

Windows does not share Unix' convention that files and directories whose names start with a dot are hidden. Hence `.git/`, for example, is in plain view, and caused quite a bit of trouble: some users wanted to peek inside and did not understand what it contains, others modified files.

There was a stream of bug reports, until Git for Windows introduced the (opt-out) option to hide at least the .git/ directory by default. The option is configured via the config setting core.hideDotFiles, with the possible values false, true and dotGitOnly (the latter being the default).

This is a heavily version of patches we carried in Git for Windows for way too long without submitting them upstream.

This iteration addresses Junio's most recent round of concerns. Oh, and while at it, it also avoids setting attributes unnecessarily.

Johannes Schindelin (2):
  mingw: introduce the 'core.hideDotFiles' setting
  mingw: remove unnecessary definition
 Documentation/config.txt |  6 ++++
 cache.h                  |  7 +++++
 compat/mingw.c           | 74 ++++++++++++++++++++++++++++++++++++++++++++++++
 compat/mingw.h           |  3 --
 config.c                 |  8 ++++++
 environment.c            |  1 +
 t/t0001-init.sh          | 30 ++++++++++++++++++++
 t/t5611-clone-config.sh  | 20 +++++++++++++
 8 files changed, 146 insertions(+), 3 deletions(-)
Published-As: https://github.com/dscho/git/releases/tag/hide-dotgit-v3
Interdiff vs v2:
 diff --git a/cache.h b/cache.h
 index 743b081..5f72f59 100644
 --- a/cache.h
 +++ b/cache.h
 @@ -704,7 +704,7 @@ extern int auto_comment_line_char;
  enum hide_dotfiles_type {
  	HIDE_DOTFILES_FALSE = 0,
  	HIDE_DOTFILES_TRUE,
 -	HIDE_DOTFILES_DOTGITONLY,
 +	HIDE_DOTFILES_DOTGITONLY
  };
  extern enum hide_dotfiles_type hide_dotfiles;
  
 diff --git a/compat/mingw.c b/compat/mingw.c
 index 3ecde84..a8218e6 100644
 --- a/compat/mingw.c
 +++ b/compat/mingw.c
 @@ -318,12 +318,12 @@ static inline int needs_hiding(const char *path)
  
  static int set_hidden_flag(const wchar_t *path, int set)
  {
 -	DWORD attribs = GetFileAttributesW(path);
 +	DWORD original = GetFileAttributesW(path), modified;
  	if (set)
 -		attribs |= FILE_ATTRIBUTE_HIDDEN;
 +		modified = original | FILE_ATTRIBUTE_HIDDEN;
  	else
 -		attribs &= ~FILE_ATTRIBUTE_HIDDEN;
 -	if (SetFileAttributesW(path, attribs))
 +		modified = original & ~FILE_ATTRIBUTE_HIDDEN;
 +	if (original == modified || SetFileAttributesW(path, modified))
  		return 0;
  	errno = err_win_to_posix(GetLastError());
  	return -1;
 @@ -377,7 +377,7 @@ int mingw_open (const char *filename, int oflags, ...)
  		if (fd < 0 && errno == EACCES)
  			fd = _wopen(wfilename, oflags & ~O_CREAT, mode);
  		if (fd >= 0 && set_hidden_flag(wfilename, 1))
 -			warning("Could not mark '%s' as hidden.", filename);
 +			warning("could not mark '%s' as hidden.", filename);
  	}
  	return fd;
  }
 @@ -419,12 +419,12 @@ FILE *mingw_fopen (const char *filename, const char *otype)
  		xutftowcs(wotype, otype, ARRAY_SIZE(wotype)) < 0)
  		return NULL;
  	if (hide && !access(filename, F_OK) && set_hidden_flag(wfilename, 0)) {
 -		error("Could not unhide %s", filename);
 +		error("could not unhide %s", filename);
  		return NULL;
  	}
  	file = _wfopen(wfilename, wotype);
  	if (file && hide && set_hidden_flag(wfilename, 1))
 -		warning("Could not mark '%s' as hidden.", filename);
 +		warning("could not mark '%s' as hidden.", filename);
  	return file;
  }
  
 @@ -439,12 +439,12 @@ FILE *mingw_freopen (const char *filename, const char *otype, FILE *stream)
  		xutftowcs(wotype, otype, ARRAY_SIZE(wotype)) < 0)
  		return NULL;
  	if (hide && !access(filename, F_OK) && set_hidden_flag(wfilename, 0)) {
 -		error("Could not unhide %s", filename);
 +		error("could not unhide %s", filename);
  		return NULL;
  	}
  	file = _wfreopen(wfilename, wotype, stream);
  	if (file && hide && set_hidden_flag(wfilename, 1))
 -		warning("Could not mark '%s' as hidden.", filename);
 +		warning("could not mark '%s' as hidden.", filename);
  	return file;
  }
  
-- 
2.8.2.463.g99156ee
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 21 of 27 in “mingw: introduce the 'core.hideDotFiles' setting”
  1. mingw: introduce the 'core.hideDotFiles' settingJohannes Schindelin, May 4, 2016
  2. Ramsay JonesMay 4, 2016
  3. Johannes SchindelinMay 6, 2016
  4. Junio C HamanoMay 4, 2016
  5. Johannes SchindelinMay 6, 2016
  6. Junio C HamanoMay 6, 2016
  7. Junio C HamanoMay 6, 2016
  8. Johannes SchindelinMay 7, 2016
  9. Johannes SchindelinMay 7, 2016
  10. 0/2 Support marking .git/ (or all files) as hidden on WindowsJohannes Schindelin, May 7, 2016
  11. 1/2 mingw: introduce the 'core.hideDotFiles' settingJohannes Schindelin, May 7, 2016
  12. Junio C HamanoMay 9, 2016
  13. Johannes SchindelinMay 10, 2016
  14. Junio C HamanoMay 10, 2016
  15. Johannes SchindelinMay 11, 2016
  16. 2/2 mingw: remove unnecessary definitionJohannes Schindelin, May 7, 2016
  17. Junio C HamanoMay 9, 2016
  18. Johannes SchindelinMay 10, 2016
  19. Junio C HamanoMay 10, 2016
  20. Johannes SchindelinMay 11, 2016
  21. 0/2 Support marking .git/ (or all files) as hidden on WindowsJohannes Schindelin, May 10, 2016
  22. 1/2 mingw: introduce the 'core.hideDotFiles' settingJohannes Schindelin, May 10, 2016
  23. 2/2 mingw: remove unnecessary definitionJohannes Schindelin, May 10, 2016
  24. 0/2 Support marking .git/ (or all files) as hidden on WindowsJohannes Schindelin, May 11, 2016
  25. 0/2 Support marking .git/ (or all files) as hidden on WindowsJohannes Schindelin, May 11, 2016
  26. 1/2 mingw: introduce the 'core.hideDotFiles' settingJohannes Schindelin, May 11, 2016
  27. 2/2 mingw: remove unnecessary definitionJohannes Schindelin, May 11, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.