mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 13:20:30 +08:00
enhance: do not warn when creating branch with current detached HEAD
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -45,11 +45,19 @@ namespace SourceGit.ViewModels
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
|
||||
var confirmed = await _repo.ConfirmCheckoutBranchAsync();
|
||||
if (!confirmed)
|
||||
if (_repo.CurrentBranch is { IsDetachedHead: true })
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
|
||||
if (refs.Count == 0)
|
||||
{
|
||||
var msg = App.Text("Checkout.WarnLostCommits");
|
||||
var shouldContinue = await App.AskConfirmAsync(msg, null);
|
||||
if (!shouldContinue)
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DiscardLocalChanges)
|
||||
|
||||
@@ -50,11 +50,19 @@ namespace SourceGit.ViewModels
|
||||
var succ = false;
|
||||
var needPopStash = false;
|
||||
|
||||
var confirmed = await _repo.ConfirmCheckoutBranchAsync();
|
||||
if (!confirmed)
|
||||
if (_repo.CurrentBranch is { IsDetachedHead: true })
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
|
||||
if (refs.Count == 0)
|
||||
{
|
||||
var msg = App.Text("Checkout.WarnLostCommits");
|
||||
var shouldContinue = await App.AskConfirmAsync(msg, null);
|
||||
if (!shouldContinue)
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DiscardLocalChanges)
|
||||
|
||||
@@ -45,11 +45,19 @@ namespace SourceGit.ViewModels
|
||||
bool succ;
|
||||
var needPop = false;
|
||||
|
||||
var confirmed = await _repo.ConfirmCheckoutBranchAsync();
|
||||
if (!confirmed)
|
||||
if (_repo.CurrentBranch is { IsDetachedHead: true })
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
|
||||
if (refs.Count == 0)
|
||||
{
|
||||
var msg = App.Text("Checkout.WarnLostCommits");
|
||||
var shouldContinue = await App.AskConfirmAsync(msg, null);
|
||||
if (!shouldContinue)
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DiscardLocalChanges)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
@@ -67,7 +68,7 @@ namespace SourceGit.ViewModels
|
||||
public CreateBranch(Repository repo, Models.Branch branch)
|
||||
{
|
||||
_repo = repo;
|
||||
_baseOnRevision = branch.IsDetachedHead ? branch.Head : branch.FullName;
|
||||
_baseOnRevision = branch.Head;
|
||||
|
||||
if (!branch.IsLocal && repo.Branches.Find(x => x.IsLocal && x.Name == branch.Name) == null)
|
||||
Name = branch.Name;
|
||||
@@ -127,11 +128,19 @@ namespace SourceGit.ViewModels
|
||||
|
||||
if (CheckoutAfterCreated)
|
||||
{
|
||||
var confirmed = await _repo.ConfirmCheckoutBranchAsync();
|
||||
if (!confirmed)
|
||||
if (_repo.CurrentBranch is { IsDetachedHead: true } && !_repo.CurrentBranch.Head.Equals(_baseOnRevision, StringComparison.Ordinal))
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
|
||||
if (refs.Count == 0)
|
||||
{
|
||||
var msg = App.Text("Checkout.WarnLostCommits");
|
||||
var shouldContinue = await App.AskConfirmAsync(msg, null);
|
||||
if (!shouldContinue)
|
||||
{
|
||||
_repo.SetWatcherEnabled(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1337,21 +1337,6 @@ namespace SourceGit.ViewModels
|
||||
ShowPopup(new CreateBranch(this, _currentBranch));
|
||||
}
|
||||
|
||||
public async Task<bool> ConfirmCheckoutBranchAsync()
|
||||
{
|
||||
if (_currentBranch is not { IsDetachedHead: true })
|
||||
return true;
|
||||
|
||||
var refs = await new Commands.QueryRefsContainsCommit(_fullpath, _currentBranch.Head).GetResultAsync();
|
||||
if (refs.Count == 0)
|
||||
{
|
||||
var msg = App.Text("Checkout.WarnLostCommits");
|
||||
return await App.AskConfirmAsync(msg, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CheckoutBranch(Models.Branch branch)
|
||||
{
|
||||
if (branch.IsLocal)
|
||||
|
||||
Reference in New Issue
Block a user