Skip to content

Commit 8159c57

Browse files
Auto-checkout working directory after git push
Non-bare repos now automatically update their working directory after a successful push, eliminating the need for post-receive hooks or manual git checkout -f.
1 parent 5d35720 commit 8159c57

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/handlers/git.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ export async function handleGit(request, reply) {
201201
if (code !== 0 && !headersSent) {
202202
reply.code(500).send({ error: 'Git operation failed' });
203203
}
204+
205+
// Auto-checkout working directory after successful push to non-bare repo
206+
if (code === 0 && isGitWriteOperation(urlPath) && gitInfo.isRegular) {
207+
const checkout = spawn('git', ['checkout', '-f'], {
208+
cwd: repoAbs,
209+
env: { ...process.env, GIT_DIR: gitInfo.gitDir }
210+
});
211+
checkout.on('error', (err) => {
212+
console.error('Auto-checkout failed:', err.message);
213+
});
214+
}
215+
204216
resolve();
205217
});
206218
});

0 commit comments

Comments
 (0)