{"record":{"id":"785945be0a768928","repo":"mislav/hub","slug":"unable-to-select-a-comment-character-that-is-not-u","errorCode":null,"errorMessage":"unable to select a comment character that is not used in the current message","messagePattern":"unable to select a comment character that is not used in the current message","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"git/git.go","lineNumber":210,"sourceCode":"}\n\nfunc CommentChar(text string) (string, error) {\n\tchar, err := Config(\"core.commentchar\")\n\tif err != nil {\n\t\treturn \"#\", nil\n\t} else if char == \"auto\" {\n\t\tlines := strings.Split(text, \"\\n\")\n\t\tcommentCharCandidates := strings.Split(\"#;@!$%^&|:\", \"\")\n\tcandidateLoop:\n\t\tfor _, candidate := range commentCharCandidates {\n\t\t\tfor _, line := range lines {\n\t\t\t\tif strings.HasPrefix(line, candidate) {\n\t\t\t\t\tcontinue candidateLoop\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn candidate, nil\n\t\t}\n\t\treturn \"\", fmt.Errorf(\"unable to select a comment character that is not used in the current message\")\n\t} else {\n\t\treturn char, nil\n\t}\n}\n\nfunc Show(sha string) (string, error) {\n\tcmd := cmd.New(\"git\")\n\tcmd.Stderr = nil\n\tcmd.WithArg(\"-c\").WithArg(\"log.showSignature=false\")\n\tcmd.WithArg(\"show\").WithArg(\"-s\").WithArg(\"--format=%s%n%+b\").WithArg(sha)\n\n\toutput, err := cmd.Output()\n\treturn strings.TrimSpace(output), err\n}\n\nfunc Log(sha1, sha2 string) (string, error) {\n\texecCmd := cmd.New(\"git\")\n\texecCmd.WithArg(\"-c\").WithArg(\"log.showSignature=false\").WithArg(\"log\").WithArg(\"--no-color\")","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/git/git.go#L192-L228","documentation":"CommentChar() determines git's core.commentChar, and when it's set to \"auto\", the library scans the commit message for a character not used at line starts, throwing this error if every candidate collides. It means git (or the library) cannot pick a comment character that won't be stripped from the message.","triggerScenarios":"Calling git.CommentChar() (via TestCommentChar, NewEditor) with core.commentChar=auto while the message/prompt text begins lines with all candidate characters (e.g. message full of lines starting with '#', ';', etc.).","commonSituations":"Commit messages containing many lines starting with common comment chars; prompt templates that already use '#' or ';' prefixes; repos configured with core.commentChar=auto on git >= 2.20 behavior changes.","solutions":["Set an explicit core.commentChar (e.g. git config core.commentChar \"#\")","Rephrase commit message lines so they don't all start with comment characters","Check `git config core.commentChar` to understand current behavior","Shorten the message/prompt so fewer leading characters collide"],"exampleFix":"// before\nchar, err := git.CommentChar()\n// after\nif err := run(\"git\", \"config\", \"core.commentChar\", \"#\"); err != nil {\n    return err\n}\nchar, err := git.CommentChar()","handlingStrategy":"fallback","validationCode":"cfg, err := exec.Command(\"git\", \"config\", \"core.commentChar\").Output()\nif err == nil && strings.TrimSpace(string(cfg)) == \"auto\" {\n    // message uses many leading comment chars; set explicit char\n    exec.Command(\"git\", \"config\", \"core.commentChar\", \"#\")\n}","typeGuard":null,"tryCatchPattern":"char, err := git.CommentChar()\nif err != nil {\n    char = \"#\" // safe default; ensure message lines don't start with '#'\n}","preventionTips":["Set an explicit core.commentChar instead of auto","Keep commit message lines from all starting with '#'/';'","Pre-check candidate comment chars against the message body","Test comment-char selection on git >= 2.20 where auto behavior changed"],"tags":["git","config","comment-char","commit-message"],"backgroundTag":"comment-char-exhausted","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}