@@ -9,6 +9,7 @@ enum PluginState {
99 add ,
1010 commit ,
1111 push ,
12+ conflicted ,
1213}
1314interface ObsidianGitSettings {
1415 commitMessage : string ;
@@ -37,7 +38,7 @@ export default class ObsidianGit extends Plugin {
3738 git : SimpleGit ;
3839 settings : ObsidianGitSettings ;
3940 statusBar : StatusBar ;
40- state : PluginState = PluginState . idle ;
41+ state : PluginState ;
4142 intervalIDBackup : number ;
4243 intervalIDPull : number ;
4344 lastUpdate : number ;
@@ -81,18 +82,16 @@ export default class ObsidianGit extends Plugin {
8182 new ChangedFilesModal ( this , status . files ) . open ( ) ;
8283 }
8384 } ) ;
84-
85- this . init ( ) ;
86-
8785 // init statusBar
8886 let statusBarEl = this . addStatusBarItem ( ) ;
8987 this . statusBar = new StatusBar ( statusBarEl , this ) ;
90- this . setState ( PluginState . idle ) ;
9188 this . registerInterval (
9289 window . setInterval ( ( ) => this . statusBar . display ( ) , 1000 )
9390 ) ;
9491
92+ this . init ( ) ;
9593 }
94+
9695 async onunload ( ) {
9796 console . log ( 'unloading ' + this . manifest . name + " plugin" ) ;
9897 }
@@ -120,6 +119,7 @@ export default class ObsidianGit extends Plugin {
120119 this . displayError ( "Valid git repository not found." ) ;
121120 } else {
122121 this . gitReady = true ;
122+ this . setState ( PluginState . idle ) ;
123123
124124 if ( this . settings . autoPullOnBoot ) {
125125 this . pullChangesFromRemote ( ) ;
@@ -225,6 +225,8 @@ export default class ObsidianGit extends Plugin {
225225
226226 if ( status . conflicted . length > 0 ) {
227227 this . displayError ( `Cannot push. You have ${ status . conflicted . length } conflict files` ) ;
228+ this . handleConflict ( status . conflicted ) ;
229+ return ;
228230 } else {
229231 const remoteChangedFiles = ( await this . git . diffSummary ( [ currentBranch , trackingBranch ] ) ) . changed ;
230232
@@ -337,6 +339,7 @@ export default class ObsidianGit extends Plugin {
337339 }
338340
339341 async handleConflict ( conflicted : string [ ] ) : Promise < void > {
342+ this . setState ( PluginState . conflicted ) ;
340343 const lines = [
341344 "# Conflict files" ,
342345 "Please resolve them and commit per command (This file will be deleted before the commit)." ,
@@ -375,10 +378,11 @@ export default class ObsidianGit extends Plugin {
375378 new Notice ( message ) ;
376379 }
377380
378- console . log ( `git obsidian: ${ message } ` ) ;
381+ console . log ( `git obsidian message : ${ message } ` ) ;
379382 }
380383 displayError ( message : string , timeout : number = 0 ) : void {
381384 new Notice ( message ) ;
385+ console . log ( `git obsidian error: ${ message } ` ) ;
382386 this . statusBar . displayMessage ( message . toLowerCase ( ) , timeout ) ;
383387 }
384388
@@ -657,7 +661,7 @@ class StatusBar {
657661 this . statusBarEl . setText ( this . currentMessage . message ) ;
658662 this . lastMessageTimestamp = Date . now ( ) ;
659663 } else if ( this . currentMessage ) {
660- let messageAge = Date . now ( ) - this . lastMessageTimestamp ;
664+ const messageAge = Date . now ( ) - this . lastMessageTimestamp ;
661665 if ( messageAge >= this . currentMessage . timeout ) {
662666 this . currentMessage = null ;
663667 this . lastMessageTimestamp = null ;
@@ -687,6 +691,12 @@ class StatusBar {
687691 case PluginState . pull :
688692 this . statusBarEl . setText ( "git: pulling changes.." ) ;
689693 break ;
694+ case PluginState . conflicted :
695+ this . statusBarEl . setText ( "git: you have conflict files.." ) ;
696+ break ;
697+ default :
698+ this . statusBarEl . setText ( "git: failed on initialization!" ) ;
699+ break ;
690700 }
691701 }
692702
0 commit comments