<commit_before>import { git } from './core'
import { Repository } from '../../models/repository'
import { IRemote } from '../../models/remote'

/** Get the remote names. */
export async function getRemotes(repository: Repository): Promise<ReadonlyArray<string>> {
  const result = await git([ 'remote' ], repository.path, 'getRemotes')
  const lines = result.stdout
  return lines.split('\n')
}

/** Get the name of the default remote. */
export async function getDefaultRemote(repository: Repository): Promise<IRemote | null> {
  const remotes = await getRemotes(repository)
  if (remotes.length === 0) {
    return null
  }

  const index = remotes.indexOf('origin')
  let name: string | null = null
  if (index > -1) {
    name = remotes[index]
  } else {
    name = remotes[0]
  }

  return name ? { name, url: '' } : null
}

/** Add a new remote with the given URL. */
export async function addRemote(path: string, name: string, url: string): Promise<void> {
  await git([ 'remote', 'add', name, url ], path, 'addRemote')
}<commit_msg>Modified method to return a remote instance<commit_after>import { git } from './core'
import { Repository } from '../../models/repository'
import { IRemote } from '../../models/remote'

/** Get the remote names. */
export async function getRemotes(repository: Repository): Promise<ReadonlyArray<IRemote>> {
  const result = await git([ 'remote', '-v' ], repository.path, 'getRemotes')
  const output = result.stdout
  const lines = output.split('\n')
  const remotes = lines
    .map(x  => x.split(/\s+/))
    .map(x => ({name: x[0], url: x[1]}))
    .filter((x, i) => i%2 !== 0)

  return remotes
}

/** Get the name of the default remote. */
export async function getDefaultRemote(repository: Repository): Promise<IRemote | null> {
  const remotes = await getRemotes(repository)
  if (remotes.length === 0) {
    return null
  }

  const remote = remotes.find(x => x.name === 'origin')

  if (remote) {
    return remote
  }

  return remotes[0]
}

/** Add a new remote with the given URL. */
export async function addRemote(path: string, name: string, url: string): Promise<void> {
  await git([ 'remote', 'add', name, url ], path, 'addRemote')
}
{'fraction_non_alphanumeric': 0.1585198720877113, 'fraction_numerical': 0.004111466423024212, 'mean_word_length': 3.6595744680851063, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, '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': '7188089', 'n_tokens_mistral': 680, 'n_tokens_neox': 676, 'n_words': 222}