File tree Expand file tree Collapse file tree 5 files changed +51
-33
lines changed Expand file tree Collapse file tree 5 files changed +51
-33
lines changed Original file line number Diff line number Diff line change @@ -45,11 +45,19 @@ public override async Task<bool> Sure()
45
45
var succ = false ;
46
46
var needPopStash = false ;
47
47
48
- var confirmed = await _repo . ConfirmCheckoutBranchAsync ( ) ;
49
- if ( ! confirmed )
48
+ if ( _repo . CurrentBranch is { IsDetachedHead : true } )
50
49
{
51
- _repo . SetWatcherEnabled ( true ) ;
52
- return true ;
50
+ var refs = await new Commands . QueryRefsContainsCommit ( _repo . FullPath , _repo . CurrentBranch . Head ) . GetResultAsync ( ) ;
51
+ if ( refs . Count == 0 )
52
+ {
53
+ var msg = App . Text ( "Checkout.WarnLostCommits" ) ;
54
+ var shouldContinue = await App . AskConfirmAsync ( msg , null ) ;
55
+ if ( ! shouldContinue )
56
+ {
57
+ _repo . SetWatcherEnabled ( true ) ;
58
+ return true ;
59
+ }
60
+ }
53
61
}
54
62
55
63
if ( DiscardLocalChanges )
Original file line number Diff line number Diff line change @@ -50,11 +50,19 @@ public override async Task<bool> Sure()
50
50
var succ = false ;
51
51
var needPopStash = false ;
52
52
53
- var confirmed = await _repo . ConfirmCheckoutBranchAsync ( ) ;
54
- if ( ! confirmed )
53
+ if ( _repo . CurrentBranch is { IsDetachedHead : true } )
55
54
{
56
- _repo . SetWatcherEnabled ( true ) ;
57
- return true ;
55
+ var refs = await new Commands . QueryRefsContainsCommit ( _repo . FullPath , _repo . CurrentBranch . Head ) . GetResultAsync ( ) ;
56
+ if ( refs . Count == 0 )
57
+ {
58
+ var msg = App . Text ( "Checkout.WarnLostCommits" ) ;
59
+ var shouldContinue = await App . AskConfirmAsync ( msg , null ) ;
60
+ if ( ! shouldContinue )
61
+ {
62
+ _repo . SetWatcherEnabled ( true ) ;
63
+ return true ;
64
+ }
65
+ }
58
66
}
59
67
60
68
if ( DiscardLocalChanges )
Original file line number Diff line number Diff line change @@ -45,11 +45,19 @@ public override async Task<bool> Sure()
45
45
bool succ ;
46
46
var needPop = false ;
47
47
48
- var confirmed = await _repo . ConfirmCheckoutBranchAsync ( ) ;
49
- if ( ! confirmed )
48
+ if ( _repo . CurrentBranch is { IsDetachedHead : true } )
50
49
{
51
- _repo . SetWatcherEnabled ( true ) ;
52
- return true ;
50
+ var refs = await new Commands . QueryRefsContainsCommit ( _repo . FullPath , _repo . CurrentBranch . Head ) . GetResultAsync ( ) ;
51
+ if ( refs . Count == 0 )
52
+ {
53
+ var msg = App . Text ( "Checkout.WarnLostCommits" ) ;
54
+ var shouldContinue = await App . AskConfirmAsync ( msg , null ) ;
55
+ if ( ! shouldContinue )
56
+ {
57
+ _repo . SetWatcherEnabled ( true ) ;
58
+ return true ;
59
+ }
60
+ }
53
61
}
54
62
55
63
if ( DiscardLocalChanges )
Original file line number Diff line number Diff line change 1
- using System . ComponentModel . DataAnnotations ;
1
+ using System ;
2
+ using System . ComponentModel . DataAnnotations ;
2
3
using System . Threading . Tasks ;
3
4
4
5
namespace SourceGit . ViewModels
@@ -67,7 +68,7 @@ public bool RecurseSubmodules
67
68
public CreateBranch ( Repository repo , Models . Branch branch )
68
69
{
69
70
_repo = repo ;
70
- _baseOnRevision = branch . IsDetachedHead ? branch . Head : branch . FullName ;
71
+ _baseOnRevision = branch . Head ;
71
72
72
73
if ( ! branch . IsLocal && repo . Branches . Find ( x => x . IsLocal && x . Name == branch . Name ) == null )
73
74
Name = branch . Name ;
@@ -127,11 +128,19 @@ public override async Task<bool> Sure()
127
128
128
129
if ( CheckoutAfterCreated )
129
130
{
130
- var confirmed = await _repo . ConfirmCheckoutBranchAsync ( ) ;
131
- if ( ! confirmed )
131
+ if ( _repo . CurrentBranch is { IsDetachedHead : true } && ! _repo . CurrentBranch . Head . Equals ( _baseOnRevision , StringComparison . Ordinal ) )
132
132
{
133
- _repo . SetWatcherEnabled ( true ) ;
134
- return true ;
133
+ var refs = await new Commands . QueryRefsContainsCommit ( _repo . FullPath , _repo . CurrentBranch . Head ) . GetResultAsync ( ) ;
134
+ if ( refs . Count == 0 )
135
+ {
136
+ var msg = App . Text ( "Checkout.WarnLostCommits" ) ;
137
+ var shouldContinue = await App . AskConfirmAsync ( msg , null ) ;
138
+ if ( ! shouldContinue )
139
+ {
140
+ _repo . SetWatcherEnabled ( true ) ;
141
+ return true ;
142
+ }
143
+ }
135
144
}
136
145
}
137
146
Original file line number Diff line number Diff line change @@ -1337,21 +1337,6 @@ public void CreateNewBranch()
1337
1337
ShowPopup ( new CreateBranch ( this , _currentBranch ) ) ;
1338
1338
}
1339
1339
1340
- public async Task < bool > ConfirmCheckoutBranchAsync ( )
1341
- {
1342
- if ( _currentBranch is not { IsDetachedHead : true } )
1343
- return true ;
1344
-
1345
- var refs = await new Commands . QueryRefsContainsCommit ( _fullpath , _currentBranch . Head ) . GetResultAsync ( ) ;
1346
- if ( refs . Count == 0 )
1347
- {
1348
- var msg = App . Text ( "Checkout.WarnLostCommits" ) ;
1349
- return await App . AskConfirmAsync ( msg , null ) ;
1350
- }
1351
-
1352
- return true ;
1353
- }
1354
-
1355
1340
public void CheckoutBranch ( Models . Branch branch )
1356
1341
{
1357
1342
if ( branch . IsLocal )
You can’t perform that action at this time.
0 commit comments