@@ -9,10 +9,12 @@ use std::path::PathBuf;
99use anyhow:: { anyhow, bail} ;
1010use colored:: Colorize as _;
1111
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 } ;
1414use 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+ } ;
1618
1719/// Backup for a file
1820struct FileBackup {
@@ -108,9 +110,9 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
108110 } ,
109111 } ;
110112
111- git :: add_remote_branch ( & info, commit. as_ref ( ) ) ?;
113+ git_high_level :: add_remote_branch ( & info, commit. as_ref ( ) ) ?;
112114
113- let previous_branch = git :: checkout_from_remote (
115+ let previous_branch = git_high_level :: checkout_from_remote (
114116 & info. branch . local_branch_name ,
115117 & info. remote . local_remote_alias ,
116118 ) ?;
@@ -136,7 +138,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
136138 {
137139 // TODO: refactor this to not use such deep nesting
138140 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 ( ) )
140142 . await
141143 . inspect_err ( |err| {
142144 log:: error!( "failed to fetch branch from remote:\n {err}" ) ;
@@ -145,9 +147,12 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
145147 continue ;
146148 } ;
147149
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+ ) {
151156 log:: error!( "failed to merge {pull_request}: {err}" ) ;
152157 continue ;
153158 }
@@ -172,13 +177,13 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
172177 let owner = & remote. owner ;
173178 let repo = & remote. repo ;
174179 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| {
176181 log:: error!( "failed to fetch branch {owner}/{repo}/{branch}: {err}" ) ;
177182 } ) else {
178183 continue ;
179184 } ;
180185
181- if let Err ( err) = git :: merge_into_main (
186+ if let Err ( err) = git_high_level :: merge (
182187 & info. branch . local_branch_name ,
183188 & info. branch . upstream_branch_name ,
184189 ) {
@@ -206,7 +211,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
206211 }
207212 }
208213
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 ( ) ) ) {
210215 git ( [ "checkout" , & previous_branch] ) ?;
211216
212217 git:: delete_remote_and_branch (
@@ -223,7 +228,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
223228 filename, contents, ..
224229 } in & backed_up_files
225230 {
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) ) ;
227232 let mut file =
228233 File :: create ( & path) . map_err ( |err| anyhow ! ( "failed to restore backup: {err}" ) ) ?;
229234
@@ -233,7 +238,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
233238 // apply patches if they exist
234239
235240 for patch in config. patches {
236- let file_name = GIT_ROOT
241+ let file_name = git :: ROOT
237242 . join ( CONFIG_ROOT . as_str ( ) )
238243 . join ( format ! ( "{patch}.patch" ) ) ;
239244
@@ -261,7 +266,7 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
261266 }
262267
263268 git ( [ "add" , CONFIG_ROOT . as_str ( ) ] ) ?;
264- git ( [ "commit" , "--message" , "patchy: Restore configuration files"] ) ?;
269+ git:: commit ( "restore configuration files") ?;
265270
266271 let temporary_branch = with_uuid ( "temp-branch" ) ;
267272
0 commit comments