@@ -171,60 +171,19 @@ async function main() {
171171 console . log ( '\n✅ Gutenberg directory already exists' ) ;
172172 }
173173
174- // Check current ref
175- console . log ( '\n🔍 Checking current ref...' ) ;
176- let currentRef ;
177- try {
178- currentRef = await execOutput ( 'git' , [ 'rev-parse' , 'HEAD' ] , { cwd : gutenbergDir } ) ;
179- console . log ( ` Current: ${ currentRef } ` ) ;
180- } catch ( error ) {
181- console . error ( '❌ Failed to get current ref:' , error . message ) ;
182- process . exit ( 1 ) ;
183- }
184-
185- // Fetch latest changes (shallow)
186- console . log ( '\n📡 Fetching latest changes...' ) ;
174+ // Fetch and checkout target ref
175+ console . log ( `\n📡 Fetching and checking out: ${ ref } ` ) ;
187176 try {
177+ // Fetch the specific ref (works for branches, tags, and commit hashes)
188178 await exec ( 'git' , [ 'fetch' , '--depth' , '1' , 'origin' , ref ] , { cwd : gutenbergDir } ) ;
189- console . log ( '✅ Fetched successfully' ) ;
190- } catch ( error ) {
191- console . error ( '❌ Fetch failed:' , error . message ) ;
192- process . exit ( 1 ) ;
193- }
194179
195- // Resolve target ref to commit hash
196- console . log ( `\n🎯 Resolving target ref: ${ ref } ` ) ;
197- let targetRef ;
198- try {
199- targetRef = await execOutput ( 'git' , [ 'rev-parse' , `origin/${ ref } ` ] , {
200- cwd : gutenbergDir ,
201- } ) ;
202- console . log ( ` Target: ${ targetRef } ` ) ;
203- } catch ( error ) {
204- // If it's not a branch, try as a tag or commit
205- try {
206- targetRef = await execOutput ( 'git' , [ 'rev-parse' , ref ] , {
207- cwd : gutenbergDir ,
208- } ) ;
209- console . log ( ` Target: ${ targetRef } ` ) ;
210- } catch ( innerError ) {
211- console . error ( '❌ Failed to resolve target ref:' , error . message ) ;
212- process . exit ( 1 ) ;
213- }
214- }
180+ // Checkout what was just fetched
181+ await exec ( 'git' , [ 'checkout' , 'FETCH_HEAD' ] , { cwd : gutenbergDir } ) ;
215182
216- // Check out target ref if different from current
217- if ( currentRef !== targetRef ) {
218- console . log ( '\n📦 Checking out target ref...' ) ;
219- try {
220- await exec ( 'git' , [ 'checkout' , targetRef ] , { cwd : gutenbergDir } ) ;
221- console . log ( '✅ Checked out successfully' ) ;
222- } catch ( error ) {
223- console . error ( '❌ Checkout failed:' , error . message ) ;
224- process . exit ( 1 ) ;
225- }
226- } else {
227- console . log ( '\n✅ Already at target ref' ) ;
183+ console . log ( '✅ Checked out successfully' ) ;
184+ } catch ( error ) {
185+ console . error ( '❌ Fetch/checkout failed:' , error . message ) ;
186+ process . exit ( 1 ) ;
228187 }
229188
230189 // Install dependencies
0 commit comments