mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07: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();
|
||||
}
|
||||
|
||||
public bool Branch(string branch, string basedOn) {
|
||||
Args = $"checkout -b {branch} {basedOn}";
|
||||
public bool Branch(string branch, string basedOn, Action<string> onProgress) {
|
||||
Args = $"checkout --progress -b {branch} {basedOn}";
|
||||
TraitErrorAsOutput = true;
|
||||
handler = onProgress;
|
||||
return Exec();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ namespace SourceGit.Commands {
|
|||
var current = branches.Find(x => x.IsCurrent);
|
||||
|
||||
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);
|
||||
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);
|
||||
cmd.Set("gitflow.branch.master", master);
|
||||
|
|
|
@ -61,20 +61,21 @@ namespace SourceGit.Views.Popups {
|
|||
return Task.Run(() => {
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
if (checkout) {
|
||||
if (AutoStash) {
|
||||
var changes = new Commands.LocalChanges(repo).Result();
|
||||
if (changes.Count > 0) {
|
||||
if (AutoStash) {
|
||||
if (!new Commands.Stash(repo).Push(changes, "NEWBRANCH_AUTO_STASH")) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
AutoStash = true;
|
||||
}
|
||||
} else {
|
||||
new Commands.Discard(repo).Whole();
|
||||
}
|
||||
} else {
|
||||
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}");
|
||||
} else {
|
||||
new Commands.Branch(repo, BranchName).Create(basedOn);
|
||||
|
|
|
@ -400,7 +400,8 @@ namespace SourceGit.Views.Widgets {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -684,7 +685,10 @@ namespace SourceGit.Views.Widgets {
|
|||
new Popups.CreateBranch(repo, branch).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(checkout);
|
||||
menu.Items.Add(new Separator());
|
||||
|
||||
if (current != null) {
|
||||
var pull = new MenuItem();
|
||||
pull.Header = App.Text("BranchCM.PullInto", branch.Name, current.Name);
|
||||
pull.Click += (o, e) => {
|
||||
|
@ -706,6 +710,12 @@ namespace SourceGit.Views.Widgets {
|
|||
e.Handled = true;
|
||||
};
|
||||
|
||||
menu.Items.Add(pull);
|
||||
menu.Items.Add(merge);
|
||||
menu.Items.Add(rebase);
|
||||
menu.Items.Add(new Separator());
|
||||
}
|
||||
|
||||
var delete = new MenuItem();
|
||||
delete.Header = App.Text("BranchCM.Delete", branch.Name);
|
||||
delete.Click += (o, e) => {
|
||||
|
@ -734,12 +744,6 @@ namespace SourceGit.Views.Widgets {
|
|||
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(new Separator());
|
||||
menu.Items.Add(createBranch);
|
||||
|
|
Loading…
Reference in a new issue