{"record":{"id":"872711caf728f03b","repo":"eyaltoledano/claude-task-master","slug":"could-not-determine-current-git-branch","errorCode":null,"errorMessage":"Could not determine current git branch","messagePattern":"Could not determine current git branch","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"scripts/modules/task-manager/tag-management.js","lineNumber":1492,"sourceCode":"\tconst logFn = mcpLog || {\n\t\tinfo: (...args) => log('info', ...args),\n\t\twarn: (...args) => log('warn', ...args),\n\t\terror: (...args) => log('error', ...args),\n\t\tdebug: (...args) => log('debug', ...args),\n\t\tsuccess: (...args) => log('success', ...args)\n\t};\n\n\ttry {\n\t\t// Check if we're in a git repository\n\t\tif (!(await isGitRepository(projectRoot))) {\n\t\t\tlogFn.warn('Not in a git repository, cannot auto-switch tags');\n\t\t\treturn { switched: false, reason: 'not_git_repo' };\n\t\t}\n\n\t\t// Get current git branch\n\t\tconst currentBranch = await getCurrentBranch(projectRoot);\n\t\tif (!currentBranch) {\n\t\t\tlogFn.warn('Could not determine current git branch');\n\t\t\treturn { switched: false, reason: 'no_current_branch' };\n\t\t}\n\n\t\tlogFn.info(`Current git branch: ${currentBranch}`);\n\n\t\t// Check if branch is valid for tag creation\n\t\tif (!isValidBranchForTag(currentBranch)) {\n\t\t\tlogFn.info(`Branch \"${currentBranch}\" is not suitable for tag creation`);\n\t\t\treturn {\n\t\t\t\tswitched: false,\n\t\t\t\treason: 'invalid_branch_for_tag',\n\t\t\t\tbranchName: currentBranch\n\t\t\t};\n\t\t}\n\n\t\t// Check if there's already a mapping for this branch\n\t\tlet tagName = await getTagForBranch(projectRoot, currentBranch);\n","sourceCodeStart":1474,"sourceCodeEnd":1510,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/tag-management.js#L1474-L1510","documentation":"After confirming the directory is a git repository, autoSwitchTagForBranch calls getCurrentBranch(projectRoot). If that returns a falsy value (e.g. detached HEAD with no branch name resolution, or git command failure), it warns 'Could not determine current git branch' and returns { switched: false, reason: 'no_current_branch' }.","triggerScenarios":"Calling autoSwitchTagForBranch in a repo where the current branch cannot be resolved: detached HEAD state, empty repo with no initial commit, corrupted .git/HEAD, or git executable unavailable to the spawned command.","commonSituations":"CI checkouts pinned to a commit SHA (detached HEAD); brand-new repos with zero commits; environments where git is not installed or not on PATH; worktrees with unusual HEAD configuration.","solutions":["Create and switch to a named branch: 'git switch -c main' (or checkout an existing branch) so HEAD resolves.","Make an initial commit if the repo is empty — branches don't exist before the first commit.","Ensure git is installed and on PATH in the execution environment.","In CI, configure the checkout action to fetch the branch (e.g. set ref to branch name instead of SHA) to avoid detached HEAD.","Inspect .git/HEAD for corruption and repair or re-clone if needed."],"exampleFix":"// before (CI step pinned to SHA => detached HEAD)\n- uses: actions/checkout@v4\n  with: { ref: ${{ github.sha }} }\n// after\n- uses: actions/checkout@v4\n  with: { ref: ${{ github.ref_name }} }","handlingStrategy":"validation","validationCode":"const { execSync } = require('child_process');\nfunction currentBranch(root) {\n  try {\n    return execSync('git rev-parse --abbrev-ref HEAD', { cwd: root })\n      .toString().trim();\n  } catch { return null; }\n}\nif (!currentBranch(projectRoot)) throw new Error('No current branch; create one with git switch -c main');","typeGuard":"function hasNamedBranch(root) {\n  const b = currentBranch(root);\n  return typeof b === 'string' && b.length > 0 && b !== 'HEAD';\n}","tryCatchPattern":"const r = await autoSwitchTagForBranch(projectRoot, opts);\nif (r.reason === 'no_current_branch') {\n  // e.g. detached HEAD in CI — pin to a branch or skip switching\n}","preventionTips":["Avoid detached HEAD states; checkout branches by name in CI.","Make an initial commit before relying on branch-based features.","Ensure git is installed and on PATH.","Verify with 'git branch --show-current' before running."],"tags":["git","branching","environment"],"backgroundTag":"git-branch-unresolved","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}