fix<*>: fix crash while creating branch with empty repository

This commit is contained in:
leo 2021-05-27 09:14:34 +08:00
parent 284e8077d6
commit f4237efaa2
4 changed files with 43 additions and 36 deletions

View file

@ -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);