Run the git command specified in `*args` and return the output of the git command as a string. If stdin is provided, it should be a string and will be piped to the git process. If `working_dir` is provided, set this as the current working directory for the
(
self,
git_cmd,
*args, # type: Optional[str]
stdin=None,
working_dir=None,
show_panel=None,
show_panel_on_error=True,
throw_on_error=True,
decode=True,
stdin_encoding="utf-8",
custom_environ=None,
just_the_proc=False,
timeout=NOT_SET
)
| 227 | """ |
| 228 | |
| 229 | def git( |
| 230 | self, |
| 231 | git_cmd, |
| 232 | *args, # type: Optional[str] |
| 233 | stdin=None, |
| 234 | working_dir=None, |
| 235 | show_panel=None, |
| 236 | show_panel_on_error=True, |
| 237 | throw_on_error=True, |
| 238 | decode=True, |
| 239 | stdin_encoding="utf-8", |
| 240 | custom_environ=None, |
| 241 | just_the_proc=False, |
| 242 | timeout=NOT_SET |
| 243 | ): |
| 244 | """ |
| 245 | Run the git command specified in `*args` and return the output |
| 246 | of the git command as a string. |
| 247 | |
| 248 | If stdin is provided, it should be a string and will be piped to |
| 249 | the git process. If `working_dir` is provided, set this as the |
| 250 | current working directory for the git process; otherwise, |
| 251 | the `repo_path` value will be used. |
| 252 | """ |
| 253 | if timeout == NOT_SET: |
| 254 | try: |
| 255 | timeout = auto_timeout.value |
| 256 | except AttributeError: |
| 257 | timeout = DEFAULT_TIMEOUT |
| 258 | window = self.some_window() |
| 259 | final_args = self._add_global_flags(git_cmd, list(args)) |
| 260 | command = [self.git_binary_path] + list(filter_(final_args)) |
| 261 | command_str = util.debug.pretty_git_command(command[1:]) |
| 262 | |
| 263 | if show_panel is None: |
| 264 | show_panel = git_cmd in self.savvy_settings.get("show_panel_for") |
| 265 | |
| 266 | if show_panel: |
| 267 | panel = util.log.init_panel(window) |
| 268 | log = partial(util.log.append_to_panel, panel) |
| 269 | log("$ {}\n".format(command_str)) |
| 270 | |
| 271 | if not working_dir: |
| 272 | try: |
| 273 | working_dir = self.repo_path |
| 274 | except DetachedView as e: |
| 275 | # do not show panel when the window does not exist |
| 276 | GitSavvyError(str(e), show_panel=False, window=window) # just for logging |
| 277 | raise |
| 278 | except Exception as e: |
| 279 | raise GitSavvyError(str(e), show_panel=show_panel_on_error, window=window) |
| 280 | |
| 281 | stdout, stderr = None, None |
| 282 | vars_for_replace = ChainMap( |
| 283 | custom_environ or {}, |
| 284 | window.extract_variables(), |
| 285 | os.environ |
| 286 | ) |