{"record":{"id":"8ce233336ba2afef","repo":"theonedev/onedev","slug":"not-a-branch-revisionandpath-getrevision","errorCode":null,"errorMessage":"Not a branch: ${revisionAndPath.getRevision()}","messagePattern":"Not a branch: (.+?)","errorType":"http","errorClass":"NotAcceptableException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/rest/resource/RepositoryResource.java","lineNumber":389,"sourceCode":"\t@Api(order=110, description=\"Create, update, or delete specified file. Return hash of resulting commit\", \n\t\t\texample=\"46c001b04cba0ca41588841f1ca32f50b582ee9b\")\n\t@Path(\"/{projectId}/files/{branchAndFile:.*}\")\n\t@POST\n\tpublic FileEditResponse editFile(\n\t\t\t@PathParam(\"projectId\") Long projectId, \n\t\t\t@PathParam(\"branchAndFile\") @NotEmpty @Api(example=\"test-branch/path/to/file\") String branchAndFile, \n\t\t\t@NotNull FileEditRequest request) {\n\t\tProject project = projectService.load(projectId);\n\t\t\n\t\tList<String> revisionAndPathSegments = Splitter.on('/').splitToList(branchAndFile);\n\t\tRevisionAndPath revisionAndPath;\n\t\tString refName;\n\t\tObjectId oldCommitId;\n\t\tif (project.getDefaultBranch() != null) {\n\t\t\trevisionAndPath = RevisionAndPath.parse(project, revisionAndPathSegments);\n\t\t\tRefFacade ref = project.getBranchRef(revisionAndPath.getRevision());\n\t\t\tif (ref == null) \n\t\t\t\tthrow new NotAcceptableException(\"Not a branch: \" + revisionAndPath.getRevision());\n\t\t\trefName = ref.getName();\n\t\t\toldCommitId = ref.getObjectId();\n\t\t\tif (revisionAndPath.getPath() == null)\n\t\t\t\tthrow new NotAcceptableException(\"Branch and file should be specified\");\n\t\t} else {\n\t\t\tif (revisionAndPathSegments.size() < 2)\n\t\t\t\tthrow new NotAcceptableException(\"Branch and file should be specified\");\n\t\t\trevisionAndPath = new RevisionAndPath(\n\t\t\t\t\trevisionAndPathSegments.get(0), \n\t\t\t\t\tStringUtils.join(revisionAndPathSegments.subList(1, revisionAndPathSegments.size())));\n\t\t\trefName = GitUtils.branch2ref(revisionAndPath.getRevision());\n\t\t\toldCommitId = ObjectId.zeroId();\n\t\t}\n\n\t\tif (!SecurityUtils.canModifyFile(project, revisionAndPath.getRevision(), revisionAndPath.getPath())) \n\t\t\tthrow new UnauthorizedException();\n\n\t\tMap<String, BlobContent> newBlobs = new HashMap<>();","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/rest/resource/RepositoryResource.java#L371-L407","documentation":"RepositoryResource.editFile only allows edits against a branch when the project has a default branch configured. It parses 'revisionAndPath' and looks up project.getBranchRef(revision); if the revision is not a branch (e.g. a tag, a raw commit hash, or a made-up name), it throws a NotAcceptableException with message \"Not a branch: <revision>\" because edits must land on a branch ref.","triggerScenarios":"PUT/POST to the file-edit endpoint with revisionAndPath whose revision segment is a tag, commit SHA, or non-existent ref, on a project that has a default branch.","commonSituations":"Automation tools editing files on a tagged release instead of a branch; scripts passing a commit hash thinking any revision works; typos in branch names ('master' vs 'main').","solutions":["Pass a branch name as the revision segment (e.g. 'main/path/to/file').","If you need to edit a file at a tag/commit, create or use a branch pointing there first.","List the project's branches to confirm the exact branch name and spelling."],"exampleFix":"// before: editing against a tag\ncurl -X PUT .../projects/42/files/v1.0.0/README.md\n\n// after: editing against a branch\ncurl -X PUT .../projects/42/files/main/README.md","handlingStrategy":"validation","validationCode":"// resolve the revision to a branch before editing\nconst branch = await getBranch(projectId, revision);\nif (!branch) {\n  throw new Error(`'${revision}' is not a branch; edits require a branch name`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await editFile(projectId, revisionAndPath, changes);\n} catch (e) {\n  if (isNotAcceptable(e) && e.message.startsWith(\"Not a branch:\")) {\n    // create a working branch from the tag/commit, then retry\n  } else throw e;\n}","preventionTips":["Only pass branch names as the revision segment for edit operations.","Create a branch from tags/commits first if you must edit their content.","Validate branch names against the project's branch list (watch master/main differences)."],"tags":["rest-api","git","branches"],"backgroundTag":"invalid-argument-value","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}