@@ -9,6 +9,7 @@ enum PluginState {
9
9
add ,
10
10
commit ,
11
11
push ,
12
+ conflicted ,
12
13
}
13
14
interface ObsidianGitSettings {
14
15
commitMessage : string ;
@@ -37,7 +38,7 @@ export default class ObsidianGit extends Plugin {
37
38
git : SimpleGit ;
38
39
settings : ObsidianGitSettings ;
39
40
statusBar : StatusBar ;
40
- state : PluginState = PluginState . idle ;
41
+ state : PluginState ;
41
42
intervalIDBackup : number ;
42
43
intervalIDPull : number ;
43
44
lastUpdate : number ;
@@ -81,18 +82,16 @@ export default class ObsidianGit extends Plugin {
81
82
new ChangedFilesModal ( this , status . files ) . open ( ) ;
82
83
}
83
84
} ) ;
84
-
85
- this . init ( ) ;
86
-
87
85
// init statusBar
88
86
let statusBarEl = this . addStatusBarItem ( ) ;
89
87
this . statusBar = new StatusBar ( statusBarEl , this ) ;
90
- this . setState ( PluginState . idle ) ;
91
88
this . registerInterval (
92
89
window . setInterval ( ( ) => this . statusBar . display ( ) , 1000 )
93
90
) ;
94
91
92
+ this . init ( ) ;
95
93
}
94
+
96
95
async onunload ( ) {
97
96
console . log ( 'unloading ' + this . manifest . name + " plugin" ) ;
98
97
}
@@ -120,6 +119,7 @@ export default class ObsidianGit extends Plugin {
120
119
this . displayError ( "Valid git repository not found." ) ;
121
120
} else {
122
121
this . gitReady = true ;
122
+ this . setState ( PluginState . idle ) ;
123
123
124
124
if ( this . settings . autoPullOnBoot ) {
125
125
this . pullChangesFromRemote ( ) ;
@@ -225,6 +225,8 @@ export default class ObsidianGit extends Plugin {
225
225
226
226
if ( status . conflicted . length > 0 ) {
227
227
this . displayError ( `Cannot push. You have ${ status . conflicted . length } conflict files` ) ;
228
+ this . handleConflict ( status . conflicted ) ;
229
+ return ;
228
230
} else {
229
231
const remoteChangedFiles = ( await this . git . diffSummary ( [ currentBranch , trackingBranch ] ) ) . changed ;
230
232
@@ -337,6 +339,7 @@ export default class ObsidianGit extends Plugin {
337
339
}
338
340
339
341
async handleConflict ( conflicted : string [ ] ) : Promise < void > {
342
+ this . setState ( PluginState . conflicted ) ;
340
343
const lines = [
341
344
"# Conflict files" ,
342
345
"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 {
375
378
new Notice ( message ) ;
376
379
}
377
380
378
- console . log ( `git obsidian: ${ message } ` ) ;
381
+ console . log ( `git obsidian message : ${ message } ` ) ;
379
382
}
380
383
displayError ( message : string , timeout : number = 0 ) : void {
381
384
new Notice ( message ) ;
385
+ console . log ( `git obsidian error: ${ message } ` ) ;
382
386
this . statusBar . displayMessage ( message . toLowerCase ( ) , timeout ) ;
383
387
}
384
388
@@ -657,7 +661,7 @@ class StatusBar {
657
661
this . statusBarEl . setText ( this . currentMessage . message ) ;
658
662
this . lastMessageTimestamp = Date . now ( ) ;
659
663
} else if ( this . currentMessage ) {
660
- let messageAge = Date . now ( ) - this . lastMessageTimestamp ;
664
+ const messageAge = Date . now ( ) - this . lastMessageTimestamp ;
661
665
if ( messageAge >= this . currentMessage . timeout ) {
662
666
this . currentMessage = null ;
663
667
this . lastMessageTimestamp = null ;
@@ -687,6 +691,12 @@ class StatusBar {
687
691
case PluginState . pull :
688
692
this . statusBarEl . setText ( "git: pulling changes.." ) ;
689
693
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 ;
690
700
}
691
701
}
692
702
0 commit comments