{"record":{"id":"27ab8faf4609c331","repo":"eyaltoledano/claude-task-master","slug":"not-in-a-git-repository-cannot-auto-switch-tags","errorCode":null,"errorMessage":"Not in a git repository, cannot auto-switch tags","messagePattern":"Not in a git repository, cannot auto-switch tags","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"scripts/modules/task-manager/tag-management.js","lineNumber":1485,"sourceCode":"\t\tgetCurrentBranch,\n\t\tisGitRepository,\n\t\tsanitizeBranchNameForTag,\n\t\tisValidBranchForTag\n\t} = await import('../utils/git-utils.js');\n\n\t// Create a consistent logFn object regardless of context\n\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',","sourceCodeStart":1467,"sourceCodeEnd":1503,"githubUrl":"https://github.com/eyaltoledano/claude-task-master/blob/c0c98d367c55296bfe69e65680625b6db437af02/scripts/modules/task-manager/tag-management.js#L1467-L1503","documentation":"autoSwitchTagForBranch integrates tag switching with git branches. Before doing anything it checks isGitRepository(projectRoot); if the working directory is not inside a git repository it logs this warning and returns { switched: false, reason: 'not_git_repo' }. Auto-switching is meaningless without branches, so the operation is safely skipped.","triggerScenarios":"Invoking autoSwitchTagForBranch (directly or via task flows that call it, e.g. after task operations with useGitWorkflow enabled) while projectRoot is outside any .git directory, or when git init was never run.","commonSituations":"Running task-master in a freshly downloaded folder without git init; CI workspaces that copy files without the .git directory; Docker images that omit git metadata; passing a subdirectory or parent path that is not a repo root.","solutions":["Run 'git init' in the project root (and make an initial commit) if branch-based tagging is desired.","Run the command from within the actual repository root, not a non-repo copy of the files.","If you don't need auto-switching, ignore the warning or disable the git workflow option.","In CI, ensure the checkout step (e.g. actions/checkout) runs so .git exists before invoking task-master."],"exampleFix":"// before (shell)\nnpx task-master list  # run in extracted zip, no git\n// after\ngit init && git add -A && git commit -m init\nnpx task-master list","handlingStrategy":"fallback","validationCode":"const { execSync } = require('child_process');\nfunction inGitRepo(root) {\n  try { execSync('git rev-parse --is-inside-work-tree', { cwd: root, stdio: 'ignore' }); return true; }\n  catch { return false; }\n}\nif (!inGitRepo(projectRoot)) console.warn('Skipping tag auto-switch: not a git repo');","typeGuard":"function isRepoRoot(root) {\n  return require('fs').existsSync(require('path').join(root, '.git'));\n}","tryCatchPattern":"try {\n  const r = await autoSwitchTagForBranch(projectRoot, opts);\n  if (r.reason === 'not_git_repo') {\n    // proceed without tag switching\n  }\n} catch (e) { /* handle */ }","preventionTips":["Always git init before running task-master workflows that depend on branches.","In CI, use a proper checkout step so .git exists.","Don't copy projects around without their .git directory if branch-tag sync matters.","Treat reason:'not_git_repo' as an expected no-op, not an error."],"tags":["git","tagging","environment"],"backgroundTag":"not-a-git-repository","analyzedSha":"c0c98d367c55296bfe69e65680625b6db437af02","analyzedAt":"2026-08-29T02:56:26.071Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}