File tree 3 files changed +56
-1
lines changed
3 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { openHistoryInGitHub, openLineInGitHub } from "./openInGitHub";
5
5
import { ChangedFilesModal } from "./ui/modals/changedFilesModal" ;
6
6
import { GeneralModal } from "./ui/modals/generalModal" ;
7
7
import { IgnoreModal } from "./ui/modals/ignoreModal" ;
8
+ import { SimpleGit } from "./gitManager/simpleGit" ;
8
9
9
10
export function addCommmands ( plugin : ObsidianGit ) {
10
11
const app = plugin . app ;
@@ -392,6 +393,22 @@ export function addCommmands(plugin: ObsidianGit) {
392
393
} ,
393
394
} ) ;
394
395
396
+ plugin . addCommand ( {
397
+ id : "raw-command" ,
398
+ name : "Raw command" ,
399
+ checkCallback : ( checking ) => {
400
+ const gitManager = plugin . gitManager ;
401
+ if ( checking ) {
402
+ // only available on desktop
403
+ return gitManager instanceof SimpleGit ;
404
+ } else {
405
+ plugin . tools
406
+ . runRawCommand ( )
407
+ . catch ( ( e ) => plugin . displayError ( e ) ) ;
408
+ }
409
+ } ,
410
+ } ) ;
411
+
395
412
plugin . addCommand ( {
396
413
id : "toggle-line-author-info" ,
397
414
name : "Toggle line author information" ,
Original file line number Diff line number Diff line change @@ -911,6 +911,12 @@ export class SimpleGit extends GitManager {
911
911
return await this . git . diff ( [ `${ commit1 } ..${ commit2 } ` , "--" , file ] ) ;
912
912
}
913
913
914
+ async rawCommand ( command : string ) : Promise < string > {
915
+ const parts = command . split ( " " ) ; // Very simple parsing, may need string-argv
916
+ const res = await this . git . raw ( parts [ 0 ] , ...parts . slice ( 1 ) ) ;
917
+ return res ;
918
+ }
919
+
914
920
async getSubmoduleOfFile (
915
921
repositoryRelativeFile : string
916
922
) : Promise < { submodule : string ; relativeFilepath : string } | undefined > {
Original file line number Diff line number Diff line change 1
- import { Platform , TFile } from "obsidian" ;
1
+ import { Notice , Platform , TFile } from "obsidian" ;
2
2
import {
3
3
CONFLICT_OUTPUT_FILE ,
4
4
DIFF_VIEW_CONFIG ,
5
5
SPLIT_DIFF_VIEW_CONFIG ,
6
6
} from "./constants" ;
7
7
import type ObsidianGit from "./main" ;
8
8
import { getNewLeaf , splitRemoteBranch } from "./utils" ;
9
+ import { SimpleGit } from "./gitManager/simpleGit" ;
10
+ import { GeneralModal } from "./ui/modals/generalModal" ;
9
11
10
12
export default class Tools {
11
13
constructor ( private readonly plugin : ObsidianGit ) { }
@@ -107,4 +109,34 @@ export default class Tools {
107
109
} ) ;
108
110
}
109
111
}
112
+
113
+ async runRawCommand ( ) {
114
+ const gitManager = this . plugin . gitManager ;
115
+ if ( ! ( gitManager instanceof SimpleGit ) ) {
116
+ return ;
117
+ }
118
+ const modal = new GeneralModal ( this . plugin , {
119
+ placeholder : "push origin master" ,
120
+ allowEmpty : false ,
121
+ } ) ;
122
+ const command = await modal . openAndGetResult ( ) ;
123
+ if ( command === undefined ) return ;
124
+
125
+ this . plugin . promiseQueue . addTask ( async ( ) => {
126
+ const notice = new Notice ( `Running '${ command } '...` , 999_999 ) ;
127
+
128
+ try {
129
+ const res = await gitManager . rawCommand ( command ) ;
130
+ if ( res ) {
131
+ notice . setMessage ( res ) ;
132
+ window . setTimeout ( ( ) => notice . hide ( ) , 5000 ) ;
133
+ } else {
134
+ notice . hide ( ) ;
135
+ }
136
+ } catch ( e ) {
137
+ notice . hide ( ) ;
138
+ throw e ;
139
+ }
140
+ } ) ;
141
+ }
110
142
}
You can’t perform that action at this time.
0 commit comments