File tree 4 files changed +34
-10
lines changed
4 files changed +34
-10
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ export default class AutomaticsManager {
166
166
if ( this . plugin . settings . differentIntervalCommitAndPush ) {
167
167
await this . plugin . commit ( { fromAuto : true } ) ;
168
168
} else {
169
- await this . plugin . commitAndSync ( true ) ;
169
+ await this . plugin . commitAndSync ( { fromAutoBackup : true } ) ;
170
170
}
171
171
return true ;
172
172
} ,
Original file line number Diff line number Diff line change @@ -153,15 +153,17 @@ export function addCommmands(plugin: ObsidianGit) {
153
153
id : "push" ,
154
154
name : "Commit-and-sync" ,
155
155
callback : ( ) =>
156
- plugin . promiseQueue . addTask ( ( ) => plugin . commitAndSync ( false ) ) ,
156
+ plugin . promiseQueue . addTask ( ( ) =>
157
+ plugin . commitAndSync ( { fromAutoBackup : false } )
158
+ ) ,
157
159
} ) ;
158
160
159
161
plugin . addCommand ( {
160
162
id : "backup-and-close" ,
161
163
name : "Commit-and-sync and then close Obsidian" ,
162
164
callback : ( ) =>
163
165
plugin . promiseQueue . addTask ( async ( ) => {
164
- await plugin . commitAndSync ( false ) ;
166
+ await plugin . commitAndSync ( { fromAutoBackup : false } ) ;
165
167
window . close ( ) ;
166
168
} ) ,
167
169
} ) ;
@@ -171,7 +173,10 @@ export function addCommmands(plugin: ObsidianGit) {
171
173
name : "Commit-and-sync with specific message" ,
172
174
callback : ( ) =>
173
175
plugin . promiseQueue . addTask ( ( ) =>
174
- plugin . commitAndSync ( false , true )
176
+ plugin . commitAndSync ( {
177
+ fromAutoBackup : false ,
178
+ requestCustomMessage : true ,
179
+ } )
175
180
) ,
176
181
} ) ;
177
182
Original file line number Diff line number Diff line change @@ -751,11 +751,17 @@ export default class ObsidianGit extends Plugin {
751
751
this . setPluginState ( { gitAction : CurrentGitAction . idle } ) ;
752
752
}
753
753
754
- async commitAndSync (
755
- fromAutoBackup : boolean ,
754
+ async commitAndSync ( {
755
+ fromAutoBackup,
756
756
requestCustomMessage = false ,
757
- commitMessage ?: string
758
- ) : Promise < void > {
757
+ commitMessage,
758
+ onlyStaged = false ,
759
+ } : {
760
+ fromAutoBackup : boolean ;
761
+ requestCustomMessage ?: boolean ;
762
+ commitMessage ?: string ;
763
+ onlyStaged ?: boolean ;
764
+ } ) : Promise < void > {
759
765
if ( ! ( await this . isAllInitialized ( ) ) ) return ;
760
766
761
767
if (
@@ -769,6 +775,7 @@ export default class ObsidianGit extends Plugin {
769
775
fromAuto : fromAutoBackup ,
770
776
requestCustomMessage,
771
777
commitMessage,
778
+ onlyStaged,
772
779
} ) ;
773
780
if ( ! commitSuccessful ) {
774
781
return ;
Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
- import { Platform , setIcon } from " obsidian" ;
2
+ import { Platform , Scope , setIcon } from " obsidian" ;
3
3
import { SOURCE_CONTROL_VIEW_CONFIG } from " src/constants" ;
4
4
import type ObsidianGit from " src/main" ;
5
5
import type {
81
81
});
82
82
});
83
83
84
+ view .scope = new Scope (plugin .app .scope );
85
+ view .scope .register ([" Ctrl" ], " Enter" , (_ : KeyboardEvent ) =>
86
+ commitAndSync ()
87
+ );
88
+
84
89
async function commit() {
85
90
loading = true ;
86
91
if (status ) {
100
105
function commitAndSync() {
101
106
loading = true ;
102
107
if (status ) {
108
+ // If staged files exist only commit them, but if not, commit all.
109
+ // I hope this is the most intuitive way.
110
+ const onlyStaged = status .staged .length > 0 ;
103
111
plugin .promiseQueue .addTask (() =>
104
112
plugin
105
- .commitAndSync (false , false , commitMessage )
113
+ .commitAndSync ({
114
+ fromAutoBackup: false ,
115
+ commitMessage ,
116
+ onlyStaged ,
117
+ })
106
118
.then (() => {
107
119
commitMessage = plugin .settings .commitMessage ;
108
120
})
You can’t perform that action at this time.
0 commit comments