1
+ import { BranchDropData } from '$lib/branches/dropHandler' ;
1
2
import { changesToDiffSpec } from '$lib/commits/utils' ;
2
3
import { ChangeDropData } from '$lib/dragging/draggables' ;
3
4
import StackMacros from '$lib/stacks/macros' ;
5
+ import { handleMoveBranchResult } from '$lib/stacks/stack' ;
4
6
import { ensureValue } from '$lib/utils/validation' ;
5
7
import { chipToasts } from '@gitbutler/ui' ;
6
8
import type { DropzoneHandler } from '$lib/dragging/handler' ;
@@ -23,13 +25,25 @@ export class OutsideLaneDzHandler implements DropzoneHandler {
23
25
this . macros = new StackMacros ( this . projectId , this . stackService , this . uiState ) ;
24
26
}
25
27
26
- accepts ( data : unknown ) {
28
+ private acceptsChangeDropData ( data : unknown ) : data is ChangeDropData {
27
29
if ( ! ( data instanceof ChangeDropData ) ) return false ;
28
30
if ( data . selectionId . type === 'commit' && data . stackId === undefined ) return false ;
29
31
return true ;
30
32
}
31
33
32
- async ondrop ( data : ChangeDropData ) {
34
+ private acceptsBranchDropData ( data : unknown ) : data is BranchDropData {
35
+ if ( ! ( data instanceof BranchDropData ) ) return false ;
36
+ if ( data . hasConflicts ) return false ;
37
+ if ( data . numberOfBranchesInStack <= 1 ) return false ; // Can't tear off the last branch of a stack
38
+ if ( data . numberOfCommits === 0 ) return false ; // TODO: Allow to rip empty branches
39
+ return true ;
40
+ }
41
+
42
+ accepts ( data : unknown ) {
43
+ return this . acceptsChangeDropData ( data ) || this . acceptsBranchDropData ( data ) ;
44
+ }
45
+
46
+ async ondropChangeData ( data : ChangeDropData ) {
33
47
switch ( data . selectionId . type ) {
34
48
case 'branch' : {
35
49
const newBranchName = await this . stackService . fetchNewBranchName ( this . projectId ) ;
@@ -112,4 +126,28 @@ export class OutsideLaneDzHandler implements DropzoneHandler {
112
126
}
113
127
}
114
128
}
129
+
130
+ async ondropBranchData ( data : BranchDropData ) {
131
+ await this . stackService
132
+ . tearOffBranch ( {
133
+ projectId : this . projectId ,
134
+ sourceStackId : data . stackId ,
135
+ subjectBranchName : data . branchName
136
+ } )
137
+ . then ( ( result ) => {
138
+ handleMoveBranchResult ( result ) ;
139
+ } ) ;
140
+ }
141
+
142
+ async ondrop ( data : unknown ) : Promise < void > {
143
+ if ( this . acceptsChangeDropData ( data ) ) {
144
+ await this . ondropChangeData ( data ) ;
145
+ return ;
146
+ }
147
+
148
+ if ( this . acceptsBranchDropData ( data ) ) {
149
+ await this . ondropBranchData ( data ) ;
150
+ return ;
151
+ }
152
+ }
115
153
}
0 commit comments