<commit_before>package com.softwaremill.codebrag.repository

import org.eclipse.jgit.api.Git
import org.eclipse.jgit.transport.{URIish, CredentialItem, UsernamePasswordCredentialsProvider, CredentialsProvider}
import com.softwaremill.codebrag.repository.config.{RepoData, UserPassCredentials, PassphraseCredentials}

/**
 * Encapsulates all required operations on already initialized git repo
 * It works on current branch only and can pull changes and list commits
 * either all or only those to specified commit (starting from HEAD)
 * @param repoData repository config required to work on repo (location, credentials)
 */
class GitRepository(val repoData: RepoData) extends Repository with RepositoryAutoBuilder with GitRepoBranchesModel {

  private val credentialsProvider = {
    repoData.repoCredentials.map {
      case ssh: PassphraseCredentials => new SshPassphraseCredentialsProvider(ssh.phrase)
      case userpass: UserPassCredentials => new UsernamePasswordCredentialsProvider(userpass.user, userpass.pass)
    }
  }

  protected def pullChangesForRepo() {
    val git = new Git(repo)
    val fetchCommand = git.fetch().setRemoveDeletedRefs(true) // need co call fetch first as pull doesn't have an option to purge removed branches
    val pullCommand = git.pull()
    credentialsProvider.foreach { p =>
      fetchCommand.setCredentialsProvider(p)
      pullCommand.setCredentialsProvider(p)
    }
    fetchCommand.call()
    pullCommand.call()
  }

  private class SshPassphraseCredentialsProvider(passphrase: String) extends CredentialsProvider {
    def isInteractive = false
    def supports(items: CredentialItem*) = true
    def get(uri: URIish, items: CredentialItem*) = {
      if(passphrase.nonEmpty) {
        items.foreach { item => {
          item match {
            case i: CredentialItem.StringType => i.setValue(passphrase)
            case _ =>
          }
        }}
      }
      true
    }
  }

}<commit_msg>Use reset hard to avoid conflicts<commit_after>package com.softwaremill.codebrag.repository

import org.eclipse.jgit.api.Git
import org.eclipse.jgit.api.ResetCommand.ResetType
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.transport.{URIish, CredentialItem, UsernamePasswordCredentialsProvider, CredentialsProvider}
import com.softwaremill.codebrag.repository.config.{RepoData, UserPassCredentials, PassphraseCredentials}

/**
 * Encapsulates all required operations on already initialized git repo
 * It works on current branch only and can pull changes and list commits
 * either all or only those to specified commit (starting from HEAD)
 * @param repoData repository config required to work on repo (location, credentials)
 */
class GitRepository(val repoData: RepoData) extends Repository with RepositoryAutoBuilder with GitRepoBranchesModel {

  private val credentialsProvider = {
    repoData.repoCredentials.map {
      case ssh: PassphraseCredentials => new SshPassphraseCredentialsProvider(ssh.phrase)
      case userpass: UserPassCredentials => new UsernamePasswordCredentialsProvider(userpass.user, userpass.pass)
    }
  }

  protected def pullChangesForRepo() {
    val git = new Git(repo)
    val fetchCommand = git.fetch().setRemoveDeletedRefs(true) // need co call fetch first as pull doesn't have an option to purge removed branches
    val updateCommand = git.reset()
        .setMode(ResetType.HARD)
        .setRef(Constants.FETCH_HEAD)
    credentialsProvider.foreach { p =>
      fetchCommand.setCredentialsProvider(p)
    }
    fetchCommand.call()
    updateCommand.call()
  }

  private class SshPassphraseCredentialsProvider(passphrase: String) extends CredentialsProvider {
    def isInteractive = false
    def supports(items: CredentialItem*) = true
    def get(uri: URIish, items: CredentialItem*) = {
      if(passphrase.nonEmpty) {
        items.foreach { item => {
          item match {
            case i: CredentialItem.StringType => i.setValue(passphrase)
            case _ =>
          }
        }}
      }
      true
    }
  }

}
{'fraction_non_alphanumeric': 0.0779349714569372, 'fraction_numerical': 0.0, 'mean_word_length': 3.837935174069628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '834670', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1079, 'n_words': 300}