@@ -4,7 +4,7 @@ use gitbutler_project::ProjectId;
4
4
use gitbutler_repo:: RepositoryExt ;
5
5
use gitbutler_repo_actions:: RepoActionsExt ;
6
6
use serde:: Deserialize ;
7
- use serde_json:: { json , Value } ;
7
+ use serde_json:: { Value , json } ;
8
8
9
9
use crate :: RequestContext ;
10
10
@@ -63,7 +63,7 @@ struct GitGetGlobalConfigParams {
63
63
64
64
pub fn git_remote_branches ( ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
65
65
let params: GitRemoteBranchesParams = serde_json:: from_value ( params) ?;
66
-
66
+
67
67
let project = ctx. project_controller . get ( params. project_id ) ?;
68
68
let command_ctx = CommandContext :: open ( & project, ctx. app_settings . get ( ) ?. clone ( ) ) ?;
69
69
let branches = command_ctx. repo ( ) . remote_branches ( ) ?;
@@ -72,7 +72,7 @@ pub fn git_remote_branches(ctx: &RequestContext, params: Value) -> anyhow::Resul
72
72
73
73
pub fn git_test_push ( ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
74
74
let params: GitTestPushParams = serde_json:: from_value ( params) ?;
75
-
75
+
76
76
let project = ctx. project_controller . get ( params. project_id ) ?;
77
77
let command_ctx = CommandContext :: open ( & project, ctx. app_settings . get ( ) ?. clone ( ) ) ?;
78
78
command_ctx. git_test_push ( & params. remote_name , & params. branch_name , Some ( None ) ) ?;
@@ -81,16 +81,19 @@ pub fn git_test_push(ctx: &RequestContext, params: Value) -> anyhow::Result<Valu
81
81
82
82
pub fn git_test_fetch ( ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
83
83
let params: GitTestFetchParams = serde_json:: from_value ( params) ?;
84
-
84
+
85
85
let project = ctx. project_controller . get ( params. project_id ) ?;
86
86
let command_ctx = CommandContext :: open ( & project, ctx. app_settings . get ( ) ?. clone ( ) ) ?;
87
- command_ctx. fetch ( & params. remote_name , Some ( params. action . unwrap_or_else ( || "test" . to_string ( ) ) ) ) ?;
87
+ command_ctx. fetch (
88
+ & params. remote_name ,
89
+ Some ( params. action . unwrap_or_else ( || "test" . to_string ( ) ) ) ,
90
+ ) ?;
88
91
Ok ( json ! ( { } ) )
89
92
}
90
93
91
94
pub fn git_index_size ( ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
92
95
let params: GitIndexSizeParams = serde_json:: from_value ( params) ?;
93
-
96
+
94
97
let project = ctx. project_controller . get ( params. project_id ) ?;
95
98
let command_ctx = CommandContext :: open ( & project, ctx. app_settings . get ( ) ?. clone ( ) ) ?;
96
99
let size = command_ctx
@@ -103,15 +106,22 @@ pub fn git_index_size(ctx: &RequestContext, params: Value) -> anyhow::Result<Val
103
106
104
107
pub fn git_head ( ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
105
108
let params: GitHeadParams = serde_json:: from_value ( params) ?;
106
-
109
+
107
110
let project = ctx. project_controller . get ( params. project_id ) ?;
108
111
let command_ctx = CommandContext :: open ( & project, ctx. app_settings . get ( ) ?. clone ( ) ) ?;
109
- let head = command_ctx. repo ( ) . head ( ) . context ( "failed to get repository head" ) ?;
112
+ let head = command_ctx
113
+ . repo ( )
114
+ . head ( )
115
+ . context ( "failed to get repository head" ) ?;
110
116
Ok ( json ! ( head. name( ) . unwrap( ) . to_string( ) ) )
111
117
}
112
118
113
119
pub fn delete_all_data ( ctx : & RequestContext , _params : Value ) -> anyhow:: Result < Value > {
114
- for project in ctx. project_controller . list ( ) . context ( "failed to list projects" ) ? {
120
+ for project in ctx
121
+ . project_controller
122
+ . list ( )
123
+ . context ( "failed to list projects" ) ?
124
+ {
115
125
ctx. project_controller
116
126
. delete ( project. id )
117
127
. map_err ( |err| err. context ( "failed to delete project" ) ) ?;
@@ -121,23 +131,23 @@ pub fn delete_all_data(ctx: &RequestContext, _params: Value) -> anyhow::Result<V
121
131
122
132
pub fn git_set_global_config ( _ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
123
133
let params: GitSetGlobalConfigParams = serde_json:: from_value ( params) ?;
124
-
134
+
125
135
let mut config = git2:: Config :: open_default ( ) ?;
126
136
config. set_str ( & params. key , & params. value ) ?;
127
137
Ok ( json ! ( params. value) )
128
138
}
129
139
130
140
pub fn git_remove_global_config ( _ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
131
141
let params: GitRemoveGlobalConfigParams = serde_json:: from_value ( params) ?;
132
-
142
+
133
143
let mut config = git2:: Config :: open_default ( ) ?;
134
144
config. remove ( & params. key ) ?;
135
145
Ok ( json ! ( { } ) )
136
146
}
137
147
138
148
pub fn git_get_global_config ( _ctx : & RequestContext , params : Value ) -> anyhow:: Result < Value > {
139
149
let params: GitGetGlobalConfigParams = serde_json:: from_value ( params) ?;
140
-
150
+
141
151
let config = git2:: Config :: open_default ( ) ?;
142
152
let value = config. get_string ( & params. key ) ;
143
153
match value {
@@ -150,4 +160,4 @@ pub fn git_get_global_config(_ctx: &RequestContext, params: Value) -> anyhow::Re
150
160
}
151
161
}
152
162
}
153
- }
163
+ }
0 commit comments