Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clean cloned repository before checkout #551

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 5 additions & 128 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.0.0",
"description": "A bot that backport commits to other branches",
"main": "index.ts",
"type": "module",
"scripts": {
"serve": "tsx src/index.ts",
"test": "vitest run",
Expand Down Expand Up @@ -34,7 +35,6 @@
"@octokit/webhooks": "^13.3.0",
"p-queue": "^8.0.1",
"simple-git": "^3.25.0",
"ts-node": "^10.9.2",
"tsx": "^4.17.0"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { join, resolve } from 'node:path'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)


// Runtime variables
export const SERVE_PORT = process.env.SERVE_PORT || 3000
Expand Down
4 changes: 4 additions & 0 deletions src/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const cloneAndCacheRepo = async (task: Task, backportBranch: string): Pro
await git.raw(['fetch', '--all'])
await git.raw(['pull', '--prune'])

// reset and clean the repo
await git.raw(['reset', '--hard', `origin/${branch}`])
await git.raw(['clean', '--force', '-dfx'])
Comment on lines +73 to +75
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the important part. We make sure there is no pending changes before checking out the target branch
I checked the cached repo, it's on master, pulled on latest HEAD and with a clean state 🤨 ...

I don't get how the git fetch and pull --prune could put the repo in a conflicting state


// Checkout the branch we want to backport from
await git.checkout(branch)
await git.checkoutBranch(
Expand Down
11 changes: 4 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
"include": ["src/**/*.ts"],
"exclude": ["node_modules"],
"compilerOptions": {
"allowJs": true
},
"ts-node": {
// It is faster to skip typechecking.
// Remove if you want ts-node to do typechecking.
"transpileOnly": true,
"files": true,
"allowJs": true,
"moduleResolution": "node16",
"module": "node16",
"target": "es2022"
},
}
Loading