<commit_before>// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.sshd.scproot.hooks;

import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.TimeZone;

public class CommitMsgHookTest extends HookTestCase {
  private final String SOB1 = "Signed-off-by: <NAME> <<EMAIL>>\n";
  private final String SOB2 = "Signed-off-by: <NAME> <<EMAIL>>\n";

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    final Date when = author.getWhen();
    final TimeZone tz = author.getTimeZone();

    author = new PersonIdent("<NAME>", "<EMAIL>");
    author = new PersonIdent(author, when, tz);

    committer = new PersonIdent("<NAME>", "<EMAIL>");
    committer = new PersonIdent(committer, when, tz);
  }

  public void testEmptyMessages() throws Exception {
    // Empty input must yield empty output so commit will abort.
    // Note we must consider different commit templates formats.
    //
    hookDoesNotModify("");
    hookDoesNotModify(" ");
    hookDoesNotModify("\n");
    hookDoesNotModify("\n\n");
    hookDoesNotModify("  \n  ");

    hookDoesNotModify("#");<commit_msg>Skip CommitMsgHookTest on Win32<commit_after>// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.gerrit.sshd.scproot.hooks;

import com.google.gerrit.server.util.HostPlatform;

import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.TimeZone;

public class CommitMsgHookTest extends HookTestCase {
  private final String SOB1 = "Signed-off-by: <NAME> <<EMAIL>>\n";
  private final String SOB2 = "Signed-off-by: <NAME> <<EMAIL>>\n";

  @Override
  public void runBare() throws Throwable {
    try {
      super.runBare();
    } catch (SkipTestOnThisPlatform e) {
      System.err.println(" - Skipping " + getName() + " on this system");
    }
  }

  private static class SkipTestOnThisPlatform extends RuntimeException {
  }

  @Override
  protected void setUp() throws Exception {
    if (HostPlatform.isWin32()) {
      throw new SkipTestOnThisPlatform();
    }

    super.setUp();
    final Date when = author.getWhen();
    final TimeZone tz = author.getTimeZone();

    author = new PersonIdent("<NAME>", "<EMAIL>");
    author = new PersonIdent(author, when, tz);

    committer = new PersonIdent("<NAME>", "<EMAIL>");
    committer = new PersonIdent(committer, when, tz);
  }

  public void testEmptyMessages() throws Exception {
    // Empty input must yield empty output so commit will abort.
    // Note we must consider different commit templates formats.
    //
    hookDoesNotModify("");
    hookDoesNotModify(" ");
    hookDoesNotModify("\n");
    hookDoesNotModify("\n\n");
    hookDoesNotModify("  \n  ");

    hookDoesNotModify("#");
{'fraction_non_alphanumeric': 0.11848542863220592, 'fraction_numerical': 0.005105296745373325, 'mean_word_length': 3.8826583592938735, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6991448', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1391, 'n_words': 430}