mingw: drop Windows 7-specific work-around

In ac33519ddfa8 (mingw: restrict file handle inheritance only on Windows 7 and later, 2019-11-22), I introduced code to safe-guard the defense-in-depth handling that restricts handles' inheritance so that it would work with Windows 7, too. Let's revert this patch: Git for Windows dropped supporting Windows 7 (and Windows 8) directly after Git for Windows v2.46.2. For full details, see https://gitforwindows.org/requirements#windows-version. Actually, on second thought: revert only the part that makes this handle inheritance restriction logic optional and that suggests to open a bug report if it fails, but keep the fall-back to try again without said logic: There have been a few false positives over the past few years (where the warning was triggered e.g. because Defender was still accessing a file that Git wanted to overwrite), and the fall-back logic seems to have helped occasionally in such situations. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 3, 2025 at 21:25 UTC ce6ccbaf92ec41743d83c386cad4dba77f768f13
2 files changed +4 -70
Documentation/config/core.adoc
-6
@@ -696,12 +696,6 @@ core.unsetenvvars::
696 Defaults to `PERL5LIB` to account for the fact that Git for
697 Windows insists on using its own Perl interpreter.
698
699 -core.restrictinheritedhandles::
700 - Windows-only: override whether spawned processes inherit only standard
701 - file handles (`stdin`, `stdout` and `stderr`) or all handles. Can be
702 - `auto`, `true` or `false`. Defaults to `auto`, which means `true` on
703 - Windows 7 and later, and `false` on older Windows versions.
704 -
699 core.createObject::
700 You can set this to 'link', in which case a hardlink followed by
701 a delete of the source are used to make sure that object creation
compat/mingw.c
+4 -64
@@ -244,7 +244,6 @@ enum hide_dotfiles_type {
244 HIDE_DOTFILES_DOTGITONLY
245 };
246
247 -static int core_restrict_inherited_handles = -1;
247 static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY;
248 static char *unset_environment_variables;
249
@@ -268,15 +267,6 @@ int mingw_core_config(const char *var, const char *value,
267 return 0;
268 }
269
271 - if (!strcmp(var, "core.restrictinheritedhandles")) {
272 - if (value && !strcasecmp(value, "auto"))
273 - core_restrict_inherited_handles = -1;
274 - else
275 - core_restrict_inherited_handles =
276 - git_config_bool(var, value);
277 - return 0;
278 - }
279 -
270 return 0;
271 }
272
@@ -1667,7 +1657,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1657 const char *dir,
1658 int prepend_cmd, int fhin, int fhout, int fherr)
1659 {
1670 - static int restrict_handle_inheritance = -1;
1660 STARTUPINFOEXW si;
1661 PROCESS_INFORMATION pi;
1662 LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL;
@@ -1687,16 +1676,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1676 /* Make sure to override previous errors, if any */
1677 errno = 0;
1678
1690 - if (restrict_handle_inheritance < 0)
1691 - restrict_handle_inheritance = core_restrict_inherited_handles;
1692 - /*
1693 - * The following code to restrict which handles are inherited seems
1694 - * to work properly only on Windows 7 and later, so let's disable it
1695 - * on Windows Vista and 2008.
1696 - */
1697 - if (restrict_handle_inheritance < 0)
1698 - restrict_handle_inheritance = GetVersion() >> 16 >= 7601;
1699 -
1679 do_unset_environment_variables();
1680
1681 /* Determine whether or not we are associated to a console */
@@ -1798,7 +1777,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1777 wenvblk = make_environment_block(deltaenv);
1778
1779 memset(&pi, 0, sizeof(pi));
1801 - if (restrict_handle_inheritance && stdhandles_count &&
1780 + if (stdhandles_count &&
1781 (InitializeProcThreadAttributeList(NULL, 1, 0, &size) ||
1782 GetLastError() == ERROR_INSUFFICIENT_BUFFER) &&
1783 (attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST)
@@ -1819,52 +1798,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1798 &si.StartupInfo, &pi);
1799
1800 /*
1822 - * On Windows 2008 R2, it seems that specifying certain types of handles
1823 - * (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
1824 - * error. Rather than playing finicky and fragile games, let's just try
1825 - * to detect this situation and simply try again without restricting any
1826 - * handle inheritance. This is still better than failing to create
1827 - * processes.
1801 + * On the off-chance that something with the file handle restriction
1802 + * went wrong, silently fall back to trying without it.
1803 */
1829 - if (!ret && restrict_handle_inheritance && stdhandles_count) {
1804 + if (!ret && stdhandles_count) {
1805 DWORD err = GetLastError();
1806 struct strbuf buf = STRBUF_INIT;
1807
1833 - if (err != ERROR_NO_SYSTEM_RESOURCES &&
1834 - /*
1835 - * On Windows 7 and earlier, handles on pipes and character
1836 - * devices are inherited automatically, and cannot be
1837 - * specified in the thread handle list. Rather than trying
1838 - * to catch each and every corner case (and running the
1839 - * chance of *still* forgetting a few), let's just fall
1840 - * back to creating the process without trying to limit the
1841 - * handle inheritance.
1842 - */
1843 - !(err == ERROR_INVALID_PARAMETER &&
1844 - GetVersion() >> 16 < 9200) &&
1845 - !getenv("SUPPRESS_HANDLE_INHERITANCE_WARNING")) {
1846 - DWORD fl = 0;
1847 - int i;
1848 -
1849 - setenv("SUPPRESS_HANDLE_INHERITANCE_WARNING", "1", 1);
1850 -
1851 - for (i = 0; i < stdhandles_count; i++) {
1852 - HANDLE h = stdhandles[i];
1853 - strbuf_addf(&buf, "handle #%d: %p (type %lx, "
1854 - "handle info (%d) %lx\n", i, h,
1855 - GetFileType(h),
1856 - GetHandleInformation(h, &fl),
1857 - fl);
1858 - }
1859 - strbuf_addstr(&buf, "\nThis is a bug; please report it "
1860 - "at\nhttps://github.com/git-for-windows/"
1861 - "git/issues/new\n\n"
1862 - "To suppress this warning, please set "
1863 - "the environment variable\n\n"
1864 - "\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1865 - "\n");
1866 - }
1867 - restrict_handle_inheritance = 0;
1808 flags &= ~EXTENDED_STARTUPINFO_PRESENT;
1809 ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL,
1810 TRUE, flags, wenvblk, dir ? wdir : NULL,