{"record":{"id":"90e8412075a7a41b","repo":"theonedev/onedev","slug":"source-and-target-are-the-same","errorCode":null,"errorMessage":"Source and target are the same","messagePattern":"Source and target are the same","errorType":"validation","errorClass":"NotAcceptableException","httpStatus":400,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java","lineNumber":436,"sourceCode":"\t\t\t}\n\t\t\tprojectService.deleteBranch(request.getSourceProject(), request.getSourceBranch());\n\t\t}\n\t}\n\n\t@Transactional\n\t@Override\n\tpublic void open(PullRequest request) {\n\t\tPreconditions.checkArgument(request.isNew());\n\n\t\tvar target = Preconditions.checkNotNull(request.getTarget(),\n\t\t\t\t\"Pull request target must be set before calling open\");\n\t\tvar source = Preconditions.checkNotNull(request.getSource(),\n\t\t\t\t\"Pull request source must be set before calling open\");\n\t\tPreconditions.checkNotNull(request.getSubmitter(),\n\t\t\t\t\"Pull request submitter must be set before calling open\");\n\n\t\tif (target.equals(source))\n\t\t\tthrow new NotAcceptableException(\"Source and target are the same\");\n\n\t\tPullRequest existing = findOpen(target, source);\n\t\tif (existing != null)\n\t\t\tthrow new NotAcceptableException(\"Another pull request already opened for this change\");\n\n\t\texisting = findEffective(target, source);\n\t\tif (existing != null) {\n\t\t\tif (existing.isOpen())\n\t\t\t\tthrow new NotAcceptableException(\"Another pull request already opened for this change\");\n\t\t\telse\n\t\t\t\tthrow new NotAcceptableException(\"Another pull request already merged the change\");\n\t\t}\n\n\t\tif (request.getBaseCommitHash() == null) {\n\t\t\tObjectId baseCommitId = gitService.getMergeBase(\n\t\t\t\t\ttarget.getProject(), target.getObjectId(),\n\t\t\t\t\tsource.getProject(), source.getObjectId());\n\t\t\tif (baseCommitId == null)","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultPullRequestService.java#L418-L454","documentation":"open throws this NotAcceptableException when the pull request's source and target BranchInfo are equal — a PR from a branch to itself makes no sense, so OneDev rejects it up front in open(). The comparison is target.equals(source).","triggerScenarios":"Calling DefaultPullRequestService.open(request) (or the REST/UI create-PR flow) where request.getSource() equals request.getTarget() — same project, same branch name — e.g. pre-filling the form with the same branch on both sides.","commonSituations":"Automation or UI defaults selecting the current branch for both source and target; scripting PR creation from a variable that happens to equal the target branch; creating a PR from a repo's default branch to itself.","solutions":["Set the target branch to the branch you intend to merge INTO (usually the default/main branch), keeping source as the feature branch","Verify source and target differ (project + branch name) before calling open","Fix form/script defaults so target is not pre-filled with the source branch"],"exampleFix":"// before\nrequest.setSource(new BranchInfo(project.getId(), branch));\nrequest.setTarget(new BranchInfo(project.getId(), branch)); // same -> error\n// after\nrequest.setSource(new BranchInfo(project.getId(), featureBranch));\nrequest.setTarget(new BranchInfo(project.getId(), \"main\"));","handlingStrategy":"validation","validationCode":"if (request.getTarget().equals(request.getSource()))\n    throw new IllegalArgumentException(\"source and target must differ\");","typeGuard":"boolean distinctBranches(PullRequest r) {\n    return r.getSource() != null && r.getTarget() != null && !r.getSource().equals(r.getTarget());\n}","tryCatchPattern":"try {\n    prService.open(request);\n} catch (NotAcceptableException e) {\n    // source == target; fix branch selection\n}","preventionTips":["Default the target to the main/default branch in create-PR forms","Compare source and target (project + branch) before submission","Guard automation variables so target cannot equal source"],"tags":["pull-request","creation","invalid-argument"],"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"}