Merge "feat: Detect and error on comment lines in commit message formatting"
diff --git a/polygerrit-ui/app/utils/commit-message-formatter-util.ts b/polygerrit-ui/app/utils/commit-message-formatter-util.ts
index bbd94ed..44b0f1d 100644
--- a/polygerrit-ui/app/utils/commit-message-formatter-util.ts
+++ b/polygerrit-ui/app/utils/commit-message-formatter-util.ts
@@ -24,6 +24,7 @@
   EXTRA_BLANK_LINE,
   INVALID_INDENTATION,
   TRAILING_SPACES,
+  COMMENT_LINE,
   LEADING_SPACES,
 }
 
@@ -201,9 +202,20 @@
     });
   }
 
-  // Check for extra blank lines using the raw messageString
   const lines = messageString.split('\n');
   for (let i = 0; i < lines.length; i++) {
+    if (lines[i].trim().startsWith('#')) {
+      errors.push({
+        type: ErrorType.COMMENT_LINE,
+        line: i + 1, // Line numbers are 1-based
+        message:
+          "'#' at line start is a comment marker in Git. Line will be ignored",
+      });
+    }
+  }
+
+  // Check for extra blank lines using the raw messageString
+  for (let i = 0; i < lines.length; i++) {
     if (i > 0 && lines[i].trim() === '' && lines[i - 1].trim() === '') {
       const isBetweenSubjectAndBody = i === 1 && message.body.length > 0;
       const isBetweenBodyAndFooter =
diff --git a/polygerrit-ui/app/utils/commit-message-formatter-util_test.ts b/polygerrit-ui/app/utils/commit-message-formatter-util_test.ts
index 1a76cd1..8b1a18e 100644
--- a/polygerrit-ui/app/utils/commit-message-formatter-util_test.ts
+++ b/polygerrit-ui/app/utils/commit-message-formatter-util_test.ts
@@ -330,5 +330,23 @@
         'Line should not start with spaces'
       );
     });
+
+    test('comment lines', () => {
+      const message =
+        'Fix the thing\n\n# This is a comment line.\nThis is body.\n# Another comment line in body.\n\nChange-Id: abcdefg\n# Comment line in footer\n';
+      const errors = detectFormattingErrorsInString(message);
+      assertError(
+        errors,
+        ErrorType.COMMENT_LINE,
+        3,
+        "'#' at line start is a comment marker in Git. Line will be ignored"
+      );
+      assertError(
+        errors,
+        ErrorType.COMMENT_LINE,
+        5,
+        "'#' at line start is a comment marker in Git. Line will be ignored"
+      );
+    });
   });
 });