Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormCreateWorktree: Build potential worktree path using repository path #10290

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed partial class FormCreateWorktree : GitModuleForm
private readonly AsyncLoader _branchesLoader = new();
private readonly char[] _invalidCharsInPath = Path.GetInvalidFileNameChars();

private string? _initialDirectoryPath;
private readonly string? _initialDirectoryPath;

public string WorktreeDirectory => newWorktreeDirectory.Text;
public bool OpenWorktree => openWorktreeCheckBox.Checked;
Expand All @@ -22,22 +22,19 @@ private FormCreateWorktree()
InitializeComponent();
}

public FormCreateWorktree(GitUICommands commands)
public FormCreateWorktree(GitUICommands commands, string? path)
: base(commands)
{
InitializeComponent();
InitializeComplete();
_initialDirectoryPath = path;
mstv marked this conversation as resolved.
Show resolved Hide resolved
}

private void FormCreateWorktree_Load(object sender, EventArgs e)
{
_initialDirectoryPath = GetWorktreeDirectory();
LoadBranchesAsync();

string GetWorktreeDirectory()
{
return UICommands.GitModule.WorkingDir.TrimEnd('\\', '/');
}
UpdateWorktreePathAndValidateWorktreeOptions();

void LoadBranchesAsync()
{
Expand Down Expand Up @@ -160,6 +157,9 @@ private void ValidateWorktreeOptions(object sender, EventArgs e)
}

private void UpdateWorktreePathAndValidateWorktreeOptions(object sender, EventArgs e)
=> UpdateWorktreePathAndValidateWorktreeOptions();

private void UpdateWorktreePathAndValidateWorktreeOptions()
{
UpdateWorktreePath();

Expand All @@ -170,15 +170,12 @@ private void UpdateWorktreePathAndValidateWorktreeOptions(object sender, EventAr
void UpdateWorktreePath()
{
var branchNameNormalized = NormalizeBranchName(radioButtonCheckoutExistingBranch.Checked
? ((IGitRef)comboBoxBranches.SelectedItem).Name
? ((IGitRef)comboBoxBranches.SelectedItem)?.Name ?? string.Empty
: textBoxNewBranchName.Text);
newWorktreeDirectory.Text = $"{_initialDirectoryPath}_{branchNameNormalized}";
}

string NormalizeBranchName(string branchName)
{
return string.Join("_", branchName.Split(_invalidCharsInPath, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
}
string NormalizeBranchName(string branchName) => string.Join("_", branchName.Split(_invalidCharsInPath, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have branch normalisation strategies we use in the branch dialog. Should we use the same?
Not asking to do it here, just making an observation.

}
}
}
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/WorktreeDialog/FormManageWorktree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private bool IsCurrentlyOpenedWorktree(WorkTree workTree)

private void buttonCreateNewWorktree_Click(object sender, EventArgs e)
{
using FormCreateWorktree formCreateWorktree = new(UICommands);
using FormCreateWorktree formCreateWorktree = new(UICommands, _worktrees[0].Path);
RussKie marked this conversation as resolved.
Show resolved Hide resolved
DialogResult dialogResult = formCreateWorktree.ShowDialog(this);
if (dialogResult != DialogResult.OK)
{
Expand Down