{"record":{"id":"6673a26c3c60d237","repo":"eyaltoledano/claude-task-master","slug":"no-current-branch","errorCode":"NO_CURRENT_BRANCH","errorMessage":"Could not determine current git branch.","messagePattern":"Could not determine current git branch\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mcp-server/src/core/direct-functions/add-tag.js","lineNumber":94,"sourceCode":"\t\t\t\tdisableSilentMode();\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: 'NOT_GIT_REPO',\n\t\t\t\t\t\tmessage: 'Not in a git repository. Cannot use fromBranch option.'\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Get current git branch\n\t\t\tconst currentBranch = await gitUtils.getCurrentBranch(projectRoot);\n\t\t\tif (!currentBranch) {\n\t\t\t\tlog.error('Could not determine current git branch');\n\t\t\t\tdisableSilentMode();\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tcode: 'NO_CURRENT_BRANCH',\n\t\t\t\t\t\tmessage: 'Could not determine current git branch.'\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Prepare options for branch-based tag creation\n\t\t\tconst branchOptions = {\n\t\t\t\tcopyFromCurrent,\n\t\t\t\tcopyFromTag,\n\t\t\t\tdescription:\n\t\t\t\t\tdescription || `Tag created from git branch \"${currentBranch}\"`\n\t\t\t};\n\n\t\t\t// Call the createTagFromBranch function\n\t\t\tconst result = await createTagFromBranch(\n\t\t\t\ttasksJsonPath,\n\t\t\t\tcurrentBranch,\n\t\t\t\tbranchOptions,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/mcp-server/src/core/direct-functions/add-tag.js#L76-L112","documentation":"With the fromBranch option, addTagDirect reads the current branch via git (e.g. rev-parse --abbrev-ref HEAD). If git returns an empty value (detached HEAD with no resolvable name, or a command failure) the function returns NO_CURRENT_BRANCH because it cannot derive the new tag name from the branch.","triggerScenarios":"add_tag with fromBranch: true in a detached HEAD state, a bare repository, or when the git branch command fails/returns empty output.","commonSituations":"CI checkout of a specific commit SHA (detached HEAD); rebase in progress; repository with no commits yet; corrupted git state.","solutions":["Checkout a real branch first: 'git checkout -b feature-branch'","Create the tag explicitly with a name instead of using fromBranch","Verify 'git rev-parse --abbrev-ref HEAD' returns a branch name in the project root"],"exampleFix":"// before\nadd_tag({ tasksJsonPath: path, fromBranch: true }); // detached HEAD\n// after\ngit checkout -b my-feature; add_tag({ tasksJsonPath: path, fromBranch: true });","handlingStrategy":"fallback","validationCode":"const { execSync } = require('child_process');\nfunction currentBranch(root) {\n  try { return execSync('git rev-parse --abbrev-ref HEAD', { cwd: root }).toString().trim() || null; }\n  catch { return null; }\n}\nif (args.fromBranch && !currentBranch(projectRoot)) { /* detached HEAD: pick explicit tag name */ }","typeGuard":"function branchAvailable(args, root) {\n  const b = args?.fromBranch ? currentBranch(root) : 'n/a';\n  return !args?.fromBranch || (typeof b === 'string' && b.length > 0 && b !== 'HEAD');\n}","tryCatchPattern":"const res = await addTagDirect(args);\nif (!res.success && res.error?.code === 'NO_CURRENT_BRANCH') {\n  // fall back to explicit name: addTagDirect({ ...args, fromBranch: false, name: 'my-tag' })\n}","preventionTips":["Avoid branch-based tag creation in CI checkouts of raw SHAs","Ensure the repo has at least one commit and a checked-out branch","Detect detached HEAD client-side before using fromBranch"],"tags":["git","mcp","branch"],"backgroundTag":"git-detached-head","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}