-
Notifications
You must be signed in to change notification settings - Fork 3
fix(gitRoutes): block edits on default branch #116
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
6a0b3c1
ce51596
45f27db
9a075a4
80ab077
4c6d8ae
f04e652
3ad8078
66cef54
b24de51
54a1264
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import { | |
| generateRecFileToMapWasm, | ||
| validateTestFromMapWasm | ||
| } from './wasmNodeWrapper.js'; | ||
| import { autoCommitAndPush } from './helpers.js'; | ||
| import { autoCommitAndPush, isOnDefaultBranch } from './helpers.js'; | ||
|
|
||
| // Helper functions that were in server.js | ||
| export function getUserRepoPath(req, WORKDIR, ROOT_DIR, getAuthConfig) { | ||
|
|
@@ -492,6 +492,19 @@ export function setupRoutes(app, isAuthenticated, dependencies) { | |
| return res.status(400).json({ error: 'File path is required' }); | ||
| } | ||
|
|
||
| // Check if on default branch - block file modifications | ||
| const userRepoPath = getUserRepoPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const branchCheck = await isOnDefaultBranch(userRepoPath); | ||
|
|
||
| if (branchCheck.isDefault) { | ||
| return res.status(403).json({ | ||
| error: `Cannot save files on default branch (${branchCheck.defaultBranch}). Please create a new branch before editing.`, | ||
| currentBranch: branchCheck.currentBranch, | ||
| defaultBranch: branchCheck.defaultBranch, | ||
| isDefaultBranch: true | ||
| }); | ||
| } | ||
|
Comment on lines
+502
to
+513
|
||
|
|
||
| // Use the user's test directory as the base | ||
| const testDir = getUserTestPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const absolutePath = path.join(testDir, filePath); | ||
|
|
@@ -607,6 +620,19 @@ export function setupRoutes(app, isAuthenticated, dependencies) { | |
| return res.status(400).json({ error: 'Source and target paths are required' }); | ||
| } | ||
|
|
||
| // Check if on default branch - block file modifications | ||
| const userRepoPath = getUserRepoPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const branchCheck = await isOnDefaultBranch(userRepoPath); | ||
|
|
||
| if (branchCheck.isDefault) { | ||
| return res.status(403).json({ | ||
| error: `Cannot move files on default branch (${branchCheck.defaultBranch}). Please create a new branch before editing.`, | ||
| currentBranch: branchCheck.currentBranch, | ||
| defaultBranch: branchCheck.defaultBranch, | ||
| isDefaultBranch: true | ||
| }); | ||
| } | ||
|
|
||
| // Use the user's test directory as the base | ||
| const testDir = getUserTestPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const absoluteSourcePath = path.join(testDir, sourcePath); | ||
|
|
@@ -640,6 +666,19 @@ export function setupRoutes(app, isAuthenticated, dependencies) { | |
| return res.status(400).json({ error: 'File path is required' }); | ||
| } | ||
|
|
||
| // Check if on default branch - block file modifications | ||
| const userRepoPath = getUserRepoPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const branchCheck = await isOnDefaultBranch(userRepoPath); | ||
|
|
||
| if (branchCheck.isDefault) { | ||
| return res.status(403).json({ | ||
| error: `Cannot delete files on default branch (${branchCheck.defaultBranch}). Please create a new branch before editing.`, | ||
| currentBranch: branchCheck.currentBranch, | ||
| defaultBranch: branchCheck.defaultBranch, | ||
| isDefaultBranch: true | ||
| }); | ||
| } | ||
|
|
||
| // Use the user's test directory as the base | ||
| const testDir = getUserTestPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const absolutePath = path.join(testDir, filePath); | ||
|
|
@@ -694,6 +733,19 @@ export function setupRoutes(app, isAuthenticated, dependencies) { | |
| return res.status(400).json({ error: 'Directory path is required' }); | ||
| } | ||
|
|
||
| // Check if on default branch - block directory creation | ||
| const userRepoPath = getUserRepoPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const branchCheck = await isOnDefaultBranch(userRepoPath); | ||
|
|
||
| if (branchCheck.isDefault) { | ||
| return res.status(403).json({ | ||
| error: `Cannot create directories on default branch (${branchCheck.defaultBranch}). Please create a new branch before editing.`, | ||
| currentBranch: branchCheck.currentBranch, | ||
| defaultBranch: branchCheck.defaultBranch, | ||
| isDefaultBranch: true | ||
| }); | ||
| } | ||
|
|
||
| // Use the user's test directory as the base | ||
| const testDir = getUserTestPath(req, WORKDIR, ROOT_DIR, getAuthConfig); | ||
| const absolutePath = path.join(testDir, dirPath); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
git.revparse()call returns a string with a trailing newline character. This needs to be trimmed before comparison withdefaultBranchto avoid false negatives when checkingcurrentBranch === defaultBranch.