<commit_before>package no.skatteetaten.aurora.boober.service

import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import no.skatteetaten.aurora.AuroraMetrics
import no.skatteetaten.aurora.boober.controller.security.User
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.ResetCommand
import org.eclipse.jgit.revwalk.RevCommit
import spock.lang.Ignore
import spock.lang.Specification

class GitServiceTest extends Specification {

  static REMOTE_REPO_FOLDER = new File("build/gitrepos_gitservice_bare").absoluteFile.absolutePath
  static CHECKOUT_PATH = new File("build/gitservice").absoluteFile.absolutePath
  static REPO_NAME = "test"

  def userDetailsProvider = Mock(UserDetailsProvider)
  def gitService = new GitService(userDetailsProvider, "$REMOTE_REPO_FOLDER/%s", CHECKOUT_PATH, "", "",
      new AuroraMetrics(new SimpleMeterRegistry()))

  def setup() {
    GitServiceHelperKt.recreateRepo(new File(REMOTE_REPO_FOLDER, "${REPO_NAME}.git"))
    FolderHelperKt.recreateFolder(new File(CHECKOUT_PATH))

    userDetailsProvider.getAuthenticatedUser() >> new User("aurora", "token", "Aurora Test User", [])
  }

  @Ignore("test fails on mac")
  def "Verify local unpushed commits are deleted when checking out repo"() {

    final String USER1_FOLDER = "test_user1"
    final String USER2_FOLDER = "test_user2"

    given: "A git repository with a few commits by user1"
      Git repoUser1 = gitService.checkoutRepository(REPO_NAME, USER1_FOLDER)
      def testFile = new File(CHECKOUT_PATH, "$USER1_FOLDER/test.txt")

      ["First", "Second", "Third"].each {
        testFile.write(it)
        gitService.commitAndPushChanges(repoUser1, "$it commit")
      }

    and: "repository has been checked out by user2"
      gitService.checkoutRepository(REPO_NAME, USER2_FOLDER)<commit_msg>ignore GitServiceTest only for macOs<commit_after>package no.skatteetaten.aurora.boober.service

import io.micrometer.core.instrument.simple.SimpleMeterRegistry
import no.skatteetaten.aurora.AuroraMetrics
import no.skatteetaten.aurora.boober.controller.security.User
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.ResetCommand
import org.eclipse.jgit.revwalk.RevCommit
import spock.lang.IgnoreIf
import spock.lang.Specification

class GitServiceTest extends Specification {

  static REMOTE_REPO_FOLDER = new File("build/gitrepos_gitservice_bare").absoluteFile.absolutePath
  static CHECKOUT_PATH = new File("build/gitservice").absoluteFile.absolutePath
  static REPO_NAME = "test"

  def userDetailsProvider = Mock(UserDetailsProvider)
  def gitService = new GitService(userDetailsProvider, "$REMOTE_REPO_FOLDER/%s", CHECKOUT_PATH, "", "",
      new AuroraMetrics(new SimpleMeterRegistry()))

  def setup() {
    GitServiceHelperKt.recreateRepo(new File(REMOTE_REPO_FOLDER, "${REPO_NAME}.git"))
    FolderHelperKt.recreateFolder(new File(CHECKOUT_PATH))

    userDetailsProvider.getAuthenticatedUser() >> new User("aurora", "token", "A<PASSWORD>", [])
  }

  @IgnoreIf({ os.macOs })
  def "Verify local unpushed commits are deleted when checking out repo"() {

    final String USER1_FOLDER = "test_user1"
    final String USER2_FOLDER = "test_user2"

    given: "A git repository with a few commits by user1"
      Git repoUser1 = gitService.checkoutRepository(REPO_NAME, USER1_FOLDER)
      def testFile = new File(CHECKOUT_PATH, "$USER1_FOLDER/test.txt")

      ["First", "Second", "Third"].each {
        testFile.write(it)
        gitService.commitAndPushChanges(repoUser1, "$it commit")
      }

    and: "repository has been checked out by user2"
      gitService.checkoutRepository(REPO_NAME, USER2_FOLDER)
{'fraction_non_alphanumeric': 0.10134578412524031, 'fraction_numerical': 0.006042296072507553, 'mean_word_length': 5.100502512562814, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1091393', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1159, 'n_words': 235}