mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
fix<*>: fix crash while creating branch with empty repository
This commit is contained in:
parent
284e8077d6
commit
f4237efaa2
4 changed files with 43 additions and 36 deletions
|
@ -20,8 +20,10 @@ namespace SourceGit.Commands {
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Branch(string branch, string basedOn) {
|
public bool Branch(string branch, string basedOn, Action<string> onProgress) {
|
||||||
Args = $"checkout -b {branch} {basedOn}";
|
Args = $"checkout --progress -b {branch} {basedOn}";
|
||||||
|
TraitErrorAsOutput = true;
|
||||||
|
handler = onProgress;
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,10 @@ namespace SourceGit.Commands {
|
||||||
var current = branches.Find(x => x.IsCurrent);
|
var current = branches.Find(x => x.IsCurrent);
|
||||||
|
|
||||||
var masterBranch = branches.Find(x => x.Name == master);
|
var masterBranch = branches.Find(x => x.Name == master);
|
||||||
if (masterBranch == null) new Branch(Cwd, master).Create(current.Head);
|
if (masterBranch == null && current != null) new Branch(Cwd, develop).Create(current.Head);
|
||||||
|
|
||||||
var devBranch = branches.Find(x => x.Name == develop);
|
var devBranch = branches.Find(x => x.Name == develop);
|
||||||
if (devBranch == null) new Branch(Cwd, develop).Create(current.Head);
|
if (devBranch == null && current != null) new Branch(Cwd, develop).Create(current.Head);
|
||||||
|
|
||||||
var cmd = new Config(Cwd);
|
var cmd = new Config(Cwd);
|
||||||
cmd.Set("gitflow.branch.master", master);
|
cmd.Set("gitflow.branch.master", master);
|
||||||
|
|
|
@ -61,20 +61,21 @@ namespace SourceGit.Views.Popups {
|
||||||
return Task.Run(() => {
|
return Task.Run(() => {
|
||||||
Models.Watcher.SetEnabled(repo, false);
|
Models.Watcher.SetEnabled(repo, false);
|
||||||
if (checkout) {
|
if (checkout) {
|
||||||
if (AutoStash) {
|
var changes = new Commands.LocalChanges(repo).Result();
|
||||||
var changes = new Commands.LocalChanges(repo).Result();
|
if (changes.Count > 0) {
|
||||||
if (changes.Count > 0) {
|
if (AutoStash) {
|
||||||
if (!new Commands.Stash(repo).Push(changes, "NEWBRANCH_AUTO_STASH")) {
|
if (!new Commands.Stash(repo).Push(changes, "NEWBRANCH_AUTO_STASH")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
AutoStash = true;
|
new Commands.Discard(repo).Whole();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new Commands.Discard(repo).Whole();
|
AutoStash = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Commands.Checkout(repo).Branch(BranchName, basedOn);
|
UpdateProgress($"Create new branch '{BranchName}'");
|
||||||
|
new Commands.Checkout(repo).Branch(BranchName, basedOn, UpdateProgress);
|
||||||
if (AutoStash) new Commands.Stash(repo).Pop("stash@{0}");
|
if (AutoStash) new Commands.Stash(repo).Pop("stash@{0}");
|
||||||
} else {
|
} else {
|
||||||
new Commands.Branch(repo, BranchName).Create(basedOn);
|
new Commands.Branch(repo, BranchName).Create(basedOn);
|
||||||
|
|
|
@ -400,7 +400,8 @@ namespace SourceGit.Views.Widgets {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenNewBranch(object sender, RoutedEventArgs e) {
|
private void OpenNewBranch(object sender, RoutedEventArgs e) {
|
||||||
new Popups.CreateBranch(repo, repo.Branches.Find(x => x.IsCurrent)).Show();
|
var current = repo.Branches.Find(x => x.IsCurrent);
|
||||||
|
if (current != null) new Popups.CreateBranch(repo, current).Show();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,27 +685,36 @@ namespace SourceGit.Views.Widgets {
|
||||||
new Popups.CreateBranch(repo, branch).Show();
|
new Popups.CreateBranch(repo, branch).Show();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
menu.Items.Add(checkout);
|
||||||
|
menu.Items.Add(new Separator());
|
||||||
|
|
||||||
var pull = new MenuItem();
|
if (current != null) {
|
||||||
pull.Header = App.Text("BranchCM.PullInto", branch.Name, current.Name);
|
var pull = new MenuItem();
|
||||||
pull.Click += (o, e) => {
|
pull.Header = App.Text("BranchCM.PullInto", branch.Name, current.Name);
|
||||||
new Popups.Pull(repo, branch).Show();
|
pull.Click += (o, e) => {
|
||||||
e.Handled = true;
|
new Popups.Pull(repo, branch).Show();
|
||||||
};
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
|
||||||
var merge = new MenuItem();
|
var merge = new MenuItem();
|
||||||
merge.Header = App.Text("BranchCM.Merge", branch.Name, current.Name);
|
merge.Header = App.Text("BranchCM.Merge", branch.Name, current.Name);
|
||||||
merge.Click += (o, e) => {
|
merge.Click += (o, e) => {
|
||||||
new Popups.Merge(repo.Path, $"{branch.Remote}/{branch.Name}", current.Name).Show();
|
new Popups.Merge(repo.Path, $"{branch.Remote}/{branch.Name}", current.Name).Show();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
var rebase = new MenuItem();
|
var rebase = new MenuItem();
|
||||||
rebase.Header = App.Text("BranchCM.Rebase", current.Name, branch.Name);
|
rebase.Header = App.Text("BranchCM.Rebase", current.Name, branch.Name);
|
||||||
rebase.Click += (o, e) => {
|
rebase.Click += (o, e) => {
|
||||||
new Popups.Rebase(repo.Path, current.Name, branch).Show();
|
new Popups.Rebase(repo.Path, current.Name, branch).Show();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu.Items.Add(pull);
|
||||||
|
menu.Items.Add(merge);
|
||||||
|
menu.Items.Add(rebase);
|
||||||
|
menu.Items.Add(new Separator());
|
||||||
|
}
|
||||||
|
|
||||||
var delete = new MenuItem();
|
var delete = new MenuItem();
|
||||||
delete.Header = App.Text("BranchCM.Delete", branch.Name);
|
delete.Header = App.Text("BranchCM.Delete", branch.Name);
|
||||||
|
@ -733,13 +743,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
Clipboard.SetText(branch.Remote + "/" + branch.Name);
|
Clipboard.SetText(branch.Remote + "/" + branch.Name);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
menu.Items.Add(checkout);
|
|
||||||
menu.Items.Add(new Separator());
|
|
||||||
menu.Items.Add(pull);
|
|
||||||
menu.Items.Add(merge);
|
|
||||||
menu.Items.Add(rebase);
|
|
||||||
menu.Items.Add(new Separator());
|
|
||||||
menu.Items.Add(delete);
|
menu.Items.Add(delete);
|
||||||
menu.Items.Add(new Separator());
|
menu.Items.Add(new Separator());
|
||||||
menu.Items.Add(createBranch);
|
menu.Items.Add(createBranch);
|
||||||
|
|
Loading…
Reference in a new issue