@@ -5,6 +5,7 @@ use anyhow::Context;
55use chrono:: Utc ;
66use diesel:: prelude:: * ;
77use std:: fs:: { self , OpenOptions } ;
8+ use std:: process:: Command ;
89use swirl:: PerformError ;
910
1011#[ swirl:: background_job]
@@ -98,37 +99,18 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
9899
99100 // Shell out to git because libgit2 does not currently support push leases
100101
101- let temp_key_path = repo. credentials . write_temporary_ssh_key ( ) ?;
102-
103- let checkout_path = repo. checkout_path . path ( ) ;
104- let output = std:: process:: Command :: new ( "git" )
105- . current_dir ( checkout_path)
106- . env (
107- "GIT_SSH_COMMAND" ,
108- format ! (
109- "ssh -o StrictHostKeyChecking=accept-new -i {}" ,
110- temp_key_path. display( )
111- ) ,
112- )
113- . args ( & [
114- "push" ,
115- // Both updates should succeed or fail together
116- "--atomic" ,
117- "origin" ,
118- // Overwrite master, but only if it server matches the expected value
119- & format ! ( "--force-with-lease=refs/heads/master:{}" , original_head) ,
120- // The new squashed commit is pushed to master
121- "HEAD:refs/heads/master" ,
122- // The previous value of HEAD is pushed to a snapshot branch
123- & format ! ( "{}:refs/heads/snapshot-{}" , original_head, now) ,
124- ] )
125- . output ( ) ?;
126-
127- if !output. status . success ( ) {
128- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
129- let message = format ! ( "Running git command failed with: {}" , stderr) ;
130- return Err ( message. into ( ) ) ;
131- }
102+ repo. run_command ( Command :: new ( "git" ) . args ( & [
103+ "push" ,
104+ // Both updates should succeed or fail together
105+ "--atomic" ,
106+ "origin" ,
107+ // Overwrite master, but only if it server matches the expected value
108+ & format ! ( "--force-with-lease=refs/heads/master:{}" , original_head) ,
109+ // The new squashed commit is pushed to master
110+ "HEAD:refs/heads/master" ,
111+ // The previous value of HEAD is pushed to a snapshot branch
112+ & format ! ( "{}:refs/heads/snapshot-{}" , original_head, now) ,
113+ ] ) ) ?;
132114
133115 println ! ( "The index has been successfully squashed." ) ;
134116
0 commit comments