{"record":{"id":"042f5d10061ee718","repo":"pcottle/learnGitBranching","slug":"git-error-options-042f5d","errorCode":null,"errorMessage":"git-error-options","messagePattern":"git-error-options","errorType":"validation","errorClass":"GitError","httpStatus":null,"severity":"error","filePath":"src/js/git/index.js","lineNumber":2680,"sourceCode":"  return mergeCommit;\n};\n\nGitEngine.prototype.checkout = function(idOrTarget) {\n  var target = this.resolveID(idOrTarget);\n  if (target.get('id') === 'HEAD') {\n    // git checkout HEAD is a\n    // meaningless command but i used to do this back in the day\n    return;\n  }\n\n  var type = target.get('type');\n  // check if this is an origin branch, and if so go to the commit referenced\n  if (type === 'branch' && target.getIsRemote()) {\n    target = this.getCommitFromRef(target.get('id'));\n  }\n\n  if (type !== 'branch' && type !== 'tag' && type !== 'commit') {\n    throw new GitError({\n      msg: intl.str('git-error-options')\n    });\n  }\n  if (type === 'tag') {\n    target = target.get('target');\n  }\n\n  this.HEAD.set('target', target);\n};\n\nGitEngine.prototype.forceBranch = function(branchName, where) {\n  branchName = this.crappyUnescape(branchName);\n  // if branchname doesn't exist...\n  if (!this.doesRefExist(branchName)) {\n    this.branch(branchName, where);\n  }\n\n  var branch = this.resolveID(branchName);","sourceCodeStart":2662,"sourceCodeEnd":2698,"githubUrl":"https://github.com/pcottle/learnGitBranching/blob/5b09d0ff9678cad164f5a7488a279a44f90d7256/src/js/git/index.js#L2662-L2698","documentation":"Ref-validation guard in checkout/switch: after resolving the target and normalizing remote branches to their referenced commit, the target's type must be one of 'branch', 'tag', or 'commit'. Anything else (detached HEAD placeholder, blob/tree-like refs, or an internal ref object) is not checkoutable.","triggerScenarios":"Calling checkout with options.target resolving to a ref whose type attribute is not branch/tag/commit — e.g. checking out HEAD while it is detached in a state the engine considers invalid, or passing an arbitrary object/id that resolves to an unsupported ref type.","commonSituations":"Passing raw file names or malformed ids to checkout; engine-level code passing an unresolved wrapper object; levels that detach HEAD then attempt further operations with a stale handle.","solutions":["Pass a concrete branch name, tag name, or commit id to checkout","Re-attach HEAD to a branch before further ref-based operations","Inspect resolveID(target).attributes.type first and reject non-branch/tag/commit values"],"exampleFix":"// before\nthis.checkout('some-file.txt');\n// after\nthis.checkout('main');","handlingStrategy":"type-guard","validationCode":"var t = engine.resolveID(target);\nvar type = t && t.attributes ? t.attributes.type : undefined;\nif (type !== 'branch' && type !== 'tag' && type !== 'commit') throw new Error('bad target');","typeGuard":"function isCheckoutable(engine, id) {\n  var r = engine.resolveID(id);\n  var t = r && r.attributes && r.attributes.type;\n  return t === 'branch' || t === 'tag' || t === 'commit';\n}","tryCatchPattern":null,"preventionTips":["Pass branch/tag/commit ids only","Re-attach detached HEAD before further ref ops"],"tags":["git","checkout","ref-validation","type-check"],"backgroundTag":"git-invalid-checkout-target","analyzedSha":"5b09d0ff9678cad164f5a7488a279a44f90d7256","analyzedAt":"2026-08-27T13:53:49.057Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}