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();
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
new Commands.Discard(repo).Whole();
|
||||
}
|
||||
} 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}");
|
||||
} 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,27 +685,36 @@ namespace SourceGit.Views.Widgets {
|
|||
new Popups.CreateBranch(repo, branch).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
menu.Items.Add(checkout);
|
||||
menu.Items.Add(new Separator());
|
||||
|
||||
var pull = new MenuItem();
|
||||
pull.Header = App.Text("BranchCM.PullInto", branch.Name, current.Name);
|
||||
pull.Click += (o, e) => {
|
||||
new Popups.Pull(repo, branch).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
if (current != null) {
|
||||
var pull = new MenuItem();
|
||||
pull.Header = App.Text("BranchCM.PullInto", branch.Name, current.Name);
|
||||
pull.Click += (o, e) => {
|
||||
new Popups.Pull(repo, branch).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
var merge = new MenuItem();
|
||||
merge.Header = App.Text("BranchCM.Merge", branch.Name, current.Name);
|
||||
merge.Click += (o, e) => {
|
||||
new Popups.Merge(repo.Path, $"{branch.Remote}/{branch.Name}", current.Name).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
var merge = new MenuItem();
|
||||
merge.Header = App.Text("BranchCM.Merge", branch.Name, current.Name);
|
||||
merge.Click += (o, e) => {
|
||||
new Popups.Merge(repo.Path, $"{branch.Remote}/{branch.Name}", current.Name).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
|
||||
var rebase = new MenuItem();
|
||||
rebase.Header = App.Text("BranchCM.Rebase", current.Name, branch.Name);
|
||||
rebase.Click += (o, e) => {
|
||||
new Popups.Rebase(repo.Path, current.Name, branch).Show();
|
||||
e.Handled = true;
|
||||
};
|
||||
var rebase = new MenuItem();
|
||||
rebase.Header = App.Text("BranchCM.Rebase", current.Name, branch.Name);
|
||||
rebase.Click += (o, e) => {
|
||||
new Popups.Rebase(repo.Path, current.Name, branch).Show();
|
||||
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);
|
||||
|
@ -733,13 +743,7 @@ namespace SourceGit.Views.Widgets {
|
|||
Clipboard.SetText(branch.Remote + "/" + branch.Name);
|
||||
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