@@ -19,11 +19,9 @@ import Switchboard from './switchboard';
1919import yardstick from './yardstick' ;
2020import GitTimingsView from './views/git-timings-view' ;
2121import ContextMenuInterceptor from './context-menu-interceptor' ;
22- import { getActionPipelineManager } from './action-pipeline' ;
2322import AsyncQueue from './async-queue' ;
2423import WorkerManager from './worker-manager' ;
25- import { GitError } from './git-shell-out-strategy' ;
26-
24+ import registerPipelineMiddleware from './register-pipeline-middleware' ;
2725
2826const defaultState = {
2927} ;
@@ -84,137 +82,7 @@ export default class GithubPackage {
8482
8583 this . filePatchItems = [ ] ;
8684
87- this . pipelineManager = getActionPipelineManager ( ) ;
88- const pushPipeline = this . pipelineManager . getPipeline ( this . pipelineManager . actionKeys . PUSH ) ;
89- pushPipeline . addMiddleware ( 'confirm-force-push' , ( next , repository , branchName , options ) => {
90- if ( options . force ) {
91- const choice = this . props . confirm ( {
92- message : 'Are you sure you want to force push?' ,
93- detailedMessage : 'This operation could result in losing data on the remote.' ,
94- buttons : [ 'Force Push' , 'Cancel Push' ] ,
95- } ) ;
96- if ( choice !== 0 ) { return null ; } else { return next ( ) ; }
97- } else {
98- return next ( ) ;
99- }
100- } ) ;
101- pushPipeline . addMiddleware ( 'set-push-in-progress' , async ( next , repository , branchName , options ) => {
102- repository . setOperationProgressState ( 'push' , true ) ;
103- await next ( ) ;
104- repository . setOperationProgressState ( 'push' , false ) ;
105- } ) ;
106- pushPipeline . addMiddleware ( 'failed-to-push-error' , async ( next , repository , branchName , options ) => {
107- try {
108- const result = await next ( ) ;
109- return result ;
110- } catch ( error ) {
111- if ( ! ( error instanceof GitError ) ) { throw error ; }
112- if ( / r e j e c t e d [ \s \S ] * f a i l e d t o p u s h / . test ( error . stdErr ) ) {
113- this . notificationManager . addError ( 'Push rejected' , {
114- description : 'The tip of your current branch is behind its remote counterpart.' +
115- ' Try pulling before pushing again. Or, to force push, hold `cmd` or `ctrl` while clicking.' ,
116- dismissable : true ,
117- } ) ;
118- } else {
119- console . error ( error ) ;
120- this . notificationManager . addError ( 'Unable to push' , {
121- description : `<pre>${ error . stdErr } </pre>` ,
122- dismissable : true ,
123- } ) ;
124- }
125- return error ;
126- }
127- } ) ;
128-
129- const pullPipeline = this . pipelineManager . getPipeline ( this . pipelineManager . actionKeys . PULL ) ;
130- pullPipeline . addMiddleware ( 'set-pull-in-progress' , async ( next , repository , branchName ) => {
131- repository . setOperationProgressState ( 'pull' , true ) ;
132- await next ( ) ;
133- repository . setOperationProgressState ( 'pull' , false ) ;
134- } ) ;
135- pullPipeline . addMiddleware ( 'failed-to-pull-error' , async ( next , repository , branchName ) => {
136- try {
137- const result = await next ( ) ;
138- return result ;
139- } catch ( error ) {
140- if ( ! ( error instanceof GitError ) ) { throw error ; }
141- if ( / e r r o r : Y o u r l o c a l c h a n g e s t o t h e f o l l o w i n g f i l e s w o u l d b e o v e r w r i t t e n b y m e r g e / . test ( error . stdErr ) ) {
142- const lines = error . stdErr . split ( '\n' ) ;
143- const files = lines . slice ( 3 , lines . length - 3 ) . map ( l => `\`${ l . trim ( ) } \`` ) . join ( '<br>' ) ;
144- this . notificationManager . addError ( 'Pull aborted' , {
145- description : 'Local changes to the following would be overwritten by merge:<br>' + files +
146- '<br>Please commit your changes or stash them before you merge.' ,
147- dismissable : true ,
148- } ) ;
149- } else if ( / A u t o m a t i c m e r g e f a i l e d ; f i x c o n f l i c t s a n d t h e n c o m m i t t h e r e s u l t ./ . test ( error . stdOut ) ) {
150- this . controller . gitTabTracker . ensureVisible ( ) ;
151- this . notificationManager . addInfo ( 'Merge conflicts' , {
152- description : `Your local changes conflicted with changes made on the remote branch. Resolve the conflicts
153- with the Git panel and commit to continue.` ,
154- dismissable : true ,
155- } ) ;
156- } else {
157- console . error ( error ) ;
158- this . notificationManager . addError ( 'Unable to pull' , {
159- description : `<pre>${ error . stdErr } </pre>` ,
160- dismissable : true ,
161- } ) ;
162- }
163- return error ;
164- }
165- } ) ;
166-
167- const fetchPipeline = this . pipelineManager . getPipeline ( this . pipelineManager . actionKeys . FETCH ) ;
168- fetchPipeline . addMiddleware ( 'set-fetch-in-progress' , async ( next , repository ) => {
169- repository . setOperationProgressState ( 'fetch' , true ) ;
170- await next ( ) ;
171- repository . setOperationProgressState ( 'fetch' , false ) ;
172- } ) ;
173- fetchPipeline . addMiddleware ( 'failed-to-fetch-error' , async ( next , repository ) => {
174- try {
175- const result = await next ( ) ;
176- return result ;
177- } catch ( error ) {
178- if ( ! ( error instanceof GitError ) ) { throw error ; }
179- console . error ( error ) ;
180- this . notificationManager . addError ( 'Unable to fetch' , {
181- description : `<pre>${ error . stdErr } </pre>` ,
182- dismissable : true ,
183- } ) ;
184- return error ;
185- }
186- } ) ;
187-
188- const checkoutPipeline = this . pipelineManager . getPipeline ( this . pipelineManager . actionKeys . CHECKOUT ) ;
189- checkoutPipeline . addMiddleware ( 'set-checkout-in-progress' , async ( next , repository , branchName ) => {
190- repository . setOperationProgressState ( 'checkout' , branchName ) ;
191- await next ( ) ;
192- repository . setOperationProgressState ( 'checkout' , false ) ;
193- } ) ;
194- checkoutPipeline . addMiddleware ( 'failed-to-checkout-error' , async ( next , repository , branchName , options ) => {
195- try {
196- const result = await next ( ) ;
197- return result ;
198- } catch ( error ) {
199- if ( ! ( error instanceof GitError ) ) { throw error ; }
200- const message = options . createNew ? 'Cannot create branch' : 'Checkout aborted' ;
201- let description = `<pre>${ error . stdErr } </pre>` ;
202- if ( error . stdErr . match ( / l o c a l c h a n g e s .* w o u l d b e o v e r w r i t t e n / ) ) {
203- const files = error . stdErr . split ( / \r ? \n / ) . filter ( l => l . startsWith ( '\t' ) )
204- . map ( l => `\`${ l . trim ( ) } \`` ) . join ( '<br>' ) ;
205- description = 'Local changes to the following would be overwritten:<br>' + files +
206- '<br>Please commit your changes or stash them.' ;
207- } else if ( error . stdErr . match ( / b r a n c h .* a l r e a d y e x i s t s / ) ) {
208- description = `\`${ branchName } \` already exists. Choose another branch name.` ;
209- } else if ( error . stdErr . match ( / e r r o r : y o u n e e d t o r e s o l v e y o u r c u r r e n t i n d e x f i r s t / ) ) {
210- description = 'You must first resolve merge conflicts.' ;
211- } else {
212- console . error ( error ) ;
213- }
214- this . notificationManager . addError ( message , { description, dismissable : true } ) ;
215- return error ;
216- }
217- } ) ;
85+ registerPipelineMiddleware ( this . controller , { confirm, notificationManager} ) ;
21886 }
21987
22088 setupYardstick ( ) {
0 commit comments