@@ -9,10 +9,12 @@ use std::path::PathBuf;
9
9
use anyhow:: { anyhow, bail} ;
10
10
use colored:: Colorize as _;
11
11
12
- use crate :: git :: { self , GIT_ROOT , git} ;
13
- use crate :: github_api:: { Branch , Remote , RemoteBranch } ;
12
+ use crate :: git_high_level :: { self , git} ;
13
+ use crate :: github_api:: { self , Branch , Remote , RemoteBranch } ;
14
14
use crate :: utils:: { display_link, with_uuid} ;
15
- use crate :: { CONFIG_FILE , CONFIG_FILE_PATH , CONFIG_PATH , CONFIG_ROOT , commands, confirm_prompt} ;
15
+ use crate :: {
16
+ CONFIG_FILE , CONFIG_FILE_PATH , CONFIG_PATH , CONFIG_ROOT , commands, confirm_prompt, git,
17
+ } ;
16
18
17
19
/// Backup for a file
18
20
struct FileBackup {
@@ -108,9 +110,9 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
108
110
} ,
109
111
} ;
110
112
111
- git :: add_remote_branch ( & info, commit. as_ref ( ) ) ?;
113
+ git_high_level :: add_remote_branch ( & info, commit. as_ref ( ) ) ?;
112
114
113
- let previous_branch = git :: checkout_from_remote (
115
+ let previous_branch = git_high_level :: checkout_from_remote (
114
116
& info. branch . local_branch_name ,
115
117
& info. remote . local_remote_alias ,
116
118
) ?;
@@ -136,7 +138,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
136
138
{
137
139
// TODO: refactor this to not use such deep nesting
138
140
let Ok ( ( response, info) ) =
139
- git :: fetch_pull_request ( & config. repo , * pull_request, None , commit. as_ref ( ) )
141
+ github_api :: fetch_pull_request ( & config. repo , * pull_request, None , commit. as_ref ( ) )
140
142
. await
141
143
. inspect_err ( |err| {
142
144
log:: error!( "failed to fetch branch from remote:\n {err}" ) ;
@@ -145,9 +147,12 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
145
147
continue ;
146
148
} ;
147
149
148
- if let Err ( err) =
149
- git:: merge_pull_request ( & info, * pull_request, & response. title , & response. html_url )
150
- {
150
+ if let Err ( err) = git_high_level:: merge_pull_request (
151
+ & info,
152
+ * pull_request,
153
+ & response. title ,
154
+ & response. html_url ,
155
+ ) {
151
156
log:: error!( "failed to merge {pull_request}: {err}" ) ;
152
157
continue ;
153
158
}
@@ -172,13 +177,13 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
172
177
let owner = & remote. owner ;
173
178
let repo = & remote. repo ;
174
179
let branch = & remote. branch ;
175
- let Ok ( ( _, info) ) = git :: fetch_branch ( remote) . await . inspect_err ( |err| {
180
+ let Ok ( ( _, info) ) = github_api :: fetch_branch ( remote) . await . inspect_err ( |err| {
176
181
log:: error!( "failed to fetch branch {owner}/{repo}/{branch}: {err}" ) ;
177
182
} ) else {
178
183
continue ;
179
184
} ;
180
185
181
- if let Err ( err) = git :: merge_into_main (
186
+ if let Err ( err) = git_high_level :: merge (
182
187
& info. branch . local_branch_name ,
183
188
& info. branch . upstream_branch_name ,
184
189
) {
@@ -206,7 +211,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
206
211
}
207
212
}
208
213
209
- if let Err ( err) = fs:: create_dir_all ( GIT_ROOT . join ( CONFIG_ROOT . as_str ( ) ) ) {
214
+ if let Err ( err) = fs:: create_dir_all ( git :: ROOT . join ( CONFIG_ROOT . as_str ( ) ) ) {
210
215
git ( [ "checkout" , & previous_branch] ) ?;
211
216
212
217
git:: delete_remote_and_branch (
@@ -223,7 +228,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
223
228
filename, contents, ..
224
229
} in & backed_up_files
225
230
{
226
- let path = GIT_ROOT . join ( PathBuf :: from ( CONFIG_ROOT . as_str ( ) ) . join ( filename) ) ;
231
+ let path = git :: ROOT . join ( PathBuf :: from ( CONFIG_ROOT . as_str ( ) ) . join ( filename) ) ;
227
232
let mut file =
228
233
File :: create ( & path) . map_err ( |err| anyhow ! ( "failed to restore backup: {err}" ) ) ?;
229
234
@@ -233,7 +238,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
233
238
// apply patches if they exist
234
239
235
240
for patch in config. patches {
236
- let file_name = GIT_ROOT
241
+ let file_name = git :: ROOT
237
242
. join ( CONFIG_ROOT . as_str ( ) )
238
243
. join ( format ! ( "{patch}.patch" ) ) ;
239
244
@@ -261,7 +266,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
261
266
}
262
267
263
268
git ( [ "add" , CONFIG_ROOT . as_str ( ) ] ) ?;
264
- git ( [ "commit" , "--message" , "patchy: Restore configuration files"] ) ?;
269
+ git:: commit ( "restore configuration files") ?;
265
270
266
271
let temporary_branch = with_uuid ( "temp-branch" ) ;
267
272
0 commit comments