Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66ff4c1

Browse files
committed
Omit CWD in search for bash.exe to run hooks on Windows
This uses the same NoDefaultCurrentDirectoryInExePath technique forthe Popen call in git.index.fun.run_commit_hook on Windows as isalready used in git.cmd.Git.execute.The code is simpler in run_commit_hook because a shell is neverused to run bash.exe. (bash.exe is itself a shell, but we neverrun it *via* a shell by passing shell=True to Popen.) Nonetheless,it may make sense to extract out a helper function both can call.This commit does not do that, so there is some code duplication.
1 parent61b4dda commit66ff4c1

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

‎git/index/fun.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Standalone functions to accompany the index implementation and make it more versatile."""
55

6+
importcontextlib
67
fromioimportBytesIO
78
importos
89
importos.pathasosp
@@ -26,7 +27,7 @@
2627
traverse_trees_recursive,
2728
tree_to_stream,
2829
)
29-
fromgit.utilimportIndexFileSHA1Writer,finalize_process
30+
fromgit.utilimportIndexFileSHA1Writer,finalize_process,patch_env
3031
fromgitdb.baseimportIStream
3132
fromgitdb.typimportstr_tree_type
3233

@@ -90,6 +91,10 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
9091
env=os.environ.copy()
9192
env["GIT_INDEX_FILE"]=safe_decode(str(index.path))
9293
env["GIT_EDITOR"]=":"
94+
ifos.name=="nt":
95+
maybe_patch_caller_env=patch_env("NoDefaultCurrentDirectoryInExePath","1")
96+
else:
97+
maybe_patch_caller_env=contextlib.nullcontext()
9398
cmd= [hp]
9499
try:
95100
ifos.name=="nt"andnot_has_file_extension(hp):
@@ -98,14 +103,15 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
98103
relative_hp=Path(hp).relative_to(index.repo.working_dir).as_posix()
99104
cmd= ["bash.exe",relative_hp]
100105

101-
process=subprocess.Popen(
102-
cmd+list(args),
103-
env=env,
104-
stdout=subprocess.PIPE,
105-
stderr=subprocess.PIPE,
106-
cwd=index.repo.working_dir,
107-
creationflags=PROC_CREATIONFLAGS,
108-
)
106+
withmaybe_patch_caller_env:
107+
process=subprocess.Popen(
108+
cmd+list(args),
109+
env=env,
110+
stdout=subprocess.PIPE,
111+
stderr=subprocess.PIPE,
112+
cwd=index.repo.working_dir,
113+
creationflags=PROC_CREATIONFLAGS,
114+
)
109115
exceptExceptionasex:
110116
raiseHookExecutionError(hp,ex)fromex
111117
else:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp