@@ -30,17 +30,19 @@ def git_executable(root: Path) -> str:
3030 return str (portable_git )
3131 return os .environ .get ("GIT" ) or shutil .which ("git" ) or "git"
3232
33+ _GIT_CREATION_FLAGS = subprocess .CREATE_NO_WINDOW if os .name == "nt" else 0
3334
34- def git_output (
35+
36+ def _run_git (
3537 root : Path ,
3638 args : list [str ],
3739 * ,
38- timeout : float = 15 ,
40+ timeout : float ,
3941 executable : str | None = None ,
40- ) -> str | None :
41- """Run a Git read command and return trimmed stdout on success ."""
42+ ) -> subprocess . CompletedProcess [ str ] | None :
43+ """Run Git without creating a console window in the desktop application ."""
4244 try :
43- result = subprocess .run (
45+ return subprocess .run (
4446 [executable or git_executable (root ), * args ],
4547 cwd = root ,
4648 capture_output = True ,
@@ -49,10 +51,22 @@ def git_output(
4951 timeout = timeout ,
5052 encoding = "utf-8" ,
5153 errors = "ignore" ,
54+ creationflags = _GIT_CREATION_FLAGS ,
5255 )
5356 except (OSError , subprocess .SubprocessError ):
5457 return None
55- if result .returncode != 0 :
58+
59+
60+ def git_output (
61+ root : Path ,
62+ args : list [str ],
63+ * ,
64+ timeout : float = 15 ,
65+ executable : str | None = None ,
66+ ) -> str | None :
67+ """Run a Git read command and return trimmed stdout on success."""
68+ result = _run_git (root , args , timeout = timeout , executable = executable )
69+ if result is None or result .returncode != 0 :
5670 return None
5771 return result .stdout .strip ()
5872
@@ -70,20 +84,13 @@ def remote_url(root: Path, *, executable: str | None = None) -> str:
7084
7185def set_origin_url (root : Path , url : str , * , executable : str | None = None ) -> bool :
7286 """Persist a new origin URL for both the UI and maintenance launcher."""
73- try :
74- result = subprocess .run (
75- [executable or git_executable (root ), "remote" , "set-url" , "origin" , url ],
76- cwd = root ,
77- capture_output = True ,
78- text = True ,
79- check = False ,
80- timeout = 15 ,
81- encoding = "utf-8" ,
82- errors = "ignore" ,
83- )
84- except (OSError , subprocess .SubprocessError ):
85- return False
86- return result .returncode == 0
87+ result = _run_git (
88+ root ,
89+ ["remote" , "set-url" , "origin" , url ],
90+ timeout = 15 ,
91+ executable = executable ,
92+ )
93+ return result is not None and result .returncode == 0
8794
8895
8996def mirror_index (url : str ) -> int :
@@ -132,20 +139,13 @@ def fetch_origin(
132139 executable : str | None = None ,
133140) -> bool :
134141 """Fetch one origin branch, returning whether the remote ref is current."""
135- try :
136- result = subprocess .run (
137- [executable or git_executable (root ), "fetch" , "origin" , branch ],
138- cwd = root ,
139- capture_output = True ,
140- text = True ,
141- check = False ,
142- timeout = timeout ,
143- encoding = "utf-8" ,
144- errors = "ignore" ,
145- )
146- except (OSError , subprocess .SubprocessError ):
147- return False
148- return result .returncode == 0
142+ result = _run_git (
143+ root ,
144+ ["fetch" , "origin" , branch ],
145+ timeout = timeout ,
146+ executable = executable ,
147+ )
148+ return result is not None and result .returncode == 0
149149
150150
151151def current_commit (root : Path , * , short : bool = False , executable : str | None = None ) -> str :
0 commit comments