Skip to content

Commit

Permalink
Remove GitModule.RunBash()
Browse files Browse the repository at this point in the history
  • Loading branch information
RussKie authored and mstv committed Jul 9, 2020
1 parent 95432ac commit 4b3609f
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 96 deletions.
63 changes: 0 additions & 63 deletions GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -920,69 +920,6 @@ public void RunMergeTool([CanBeNull] string fileName = "")
}
}

/// <summary>Runs a bash or shell command.</summary>
[CanBeNull]
public IProcess RunBash(string bashCommand = null)
{
if (EnvUtils.RunningOnUnix())
{
string[] termEmuCommands =
{
"gnome-terminal",
"konsole",
"Terminal",
"xterm"
};

var which = new Executable("which");
var cmd = termEmuCommands.FirstOrDefault(
termEmuCmd => !string.IsNullOrEmpty(which.GetOutput(termEmuCmd)));
var args = "";

if (string.IsNullOrEmpty(cmd))
{
cmd = "bash";
args = "--login -i";
}

return new Executable(cmd, WorkingDir).Start(args, createWindow: true);
}
else
{
if (PathUtil.TryFindShellPath("git-bash.exe", out var shellPath))
{
return new Executable(shellPath, WorkingDir).Start(createWindow: true);
}

string args;
if (string.IsNullOrWhiteSpace(bashCommand))
{
args = "--login -i\"";
}
else
{
args = "--login -i -c \"" + bashCommand.Replace("\"", "\\\"") + "\"";
}

args = "/c \"\"{0}\" " + args;

if (PathUtil.TryFindShellPath("bash.exe", out shellPath))
{
return new Executable("cmd.exe", WorkingDir)
.Start(string.Format(args, shellPath), createWindow: true);
}

if (PathUtil.TryFindShellPath("sh.exe", out shellPath))
{
return new Executable("cmd.exe", WorkingDir)
.Start(string.Format(args, shellPath), createWindow: true);
}

return new Executable("cmd.exe", WorkingDir)
.Start(@"/K echo git bash command not found! :( Please add a folder containing 'bash.exe' to your PATH...", createWindow: true);
}
}

public string Init(bool bare, bool shared)
{
var args = new GitArgumentBuilder("init")
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ protected override CommandStatus ExecuteCommand(int cmd)
{
switch ((Command)cmd)
{
case Command.GitBash: Module.RunBash(); break;
case Command.GitBash: userShell.PerformButtonClick(); break;
case Command.GitGui: Module.RunGui(); break;
case Command.GitGitK: Module.RunGitK(); break;
case Command.FocusBranchTree: FocusBranchTree(); break;
Expand Down
1 change: 0 additions & 1 deletion GitUI/CommandsDialogs/FormCommandlineHelp.resx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ difftool filename
filehistory filename
fileeditor filename
formatpatch
gitbash
gitignore
help (shows this dialog)
init [path]
Expand Down
2 changes: 0 additions & 2 deletions GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,8 +1484,6 @@ private bool RunCommandBasedOnArgument(IReadOnlyList<string> args, IReadOnlyDict
return StartFileEditorDialog(args[2]);
case "formatpatch":
return StartFormatPatchDialog();
case "gitbash":
return Module.RunBash() != null;
case "gitignore":
return StartEditGitIgnoreDialog(null, false);
case "init": // [path]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,35 +225,6 @@ public void RunCommandBasedOnArgument_fileeditor()
public void RunCommandBasedOnArgument_formatpatch()
=> RunCommandBasedOnArgument<FormFormatPatch>(new string[] { "ge.exe", "formatpatch" });

[Test]
public void RunCommandBasedOnArgument_gitbash()
{
_commands.GetTestAccessor().RunCommandBasedOnArgument(new string[] { "ge.exe", "gitbash" }).Should().BeTrue();

// wait for the shell to be started
Thread.Sleep(5000);

// find and kill the started shell executable
var currentProcessId = Process.GetCurrentProcess().Id;
int numberOfShellChildren = KillChildProcess("git-bash") + KillChildProcess("cmd");
numberOfShellChildren.Should().Be(1);

return;

int KillChildProcess(string name)
{
int number = 0;
Process.GetProcessesByName(name)
.Where(process => process.ParentProcess()?.Id == currentProcessId)
.ForEach(process =>
{
process.TerminateTree();
++number;
});
return number;
}
}

[Test]
public void RunCommandBasedOnArgument_gitignore()
=> RunCommandBasedOnArgument<FormGitIgnore>(new string[] { "ge.exe", "gitignore" });
Expand Down

0 comments on commit 4b3609f

Please sign in to comment.