<commit_before>import { git } from './core'
import { Repository } from '../../models/repository'
import { assertNever } from '../fatal-error'
import { WorkingDirectoryFileChange } from '../../models/status'

/** The reset modes which are supported. */
export const enum GitResetMode {
  Hard = 0,
  Soft,
  Mixed,
}

function resetModeToFlag(mode: GitResetMode): string {
  switch (mode) {
    case GitResetMode.Hard: return '--hard'
    case GitResetMode.Mixed: return '--mixed'
    case GitResetMode.Soft: return '--soft'
    default: return assertNever(mode, `Unknown reset mode: ${mode}`)
  }
}

/** Reset with the mode to the ref. */
export async function reset(repository: Repository, mode: GitResetMode, ref: string): Promise<true> {
  const modeFlag = resetModeToFlag(mode)
  await git([ 'reset', modeFlag, ref, '--' ], repository.path, 'reset')
  return true
}

/** Unstage the given files. */
export async function unstage(repository: Repository, files: ReadonlyArray<WorkingDirectoryFileChange>): Promise<true> {
  const paths = files.map(f => f.path)
  await git([ 'reset', '--', ...paths ], repository.path, 'unstage')
  return true
}<commit_msg>Don't pass an empty list of files<commit_after>import { git } from './core'
import { Repository } from '../../models/repository'
import { assertNever } from '../fatal-error'
import { WorkingDirectoryFileChange } from '../../models/status'

/** The reset modes which are supported. */
export const enum GitResetMode {
  Hard = 0,
  Soft,
  Mixed,
}

function resetModeToFlag(mode: GitResetMode): string {
  switch (mode) {
    case GitResetMode.Hard: return '--hard'
    case GitResetMode.Mixed: return '--mixed'
    case GitResetMode.Soft: return '--soft'
    default: return assertNever(mode, `Unknown reset mode: ${mode}`)
  }
}

/** Reset with the mode to the ref. */
export async function reset(repository: Repository, mode: GitResetMode, ref: string): Promise<true> {
  const modeFlag = resetModeToFlag(mode)
  await git([ 'reset', modeFlag, ref, '--' ], repository.path, 'reset')
  return true
}

/** Unstage the given files. */
export async function unstage(repository: Repository, files: ReadonlyArray<WorkingDirectoryFileChange>): Promise<true> {
  // If we don't pass any paths, it changes the semantics of the `git reset`. So
  // don't do that.
  if (!files.length) {
    return true
  }

  const paths = files.map(f => f.path)
  await git([ 'reset', '--', ...paths ], repository.path, 'unstage')
  return true
}
{'fraction_non_alphanumeric': 0.14659685863874344, 'fraction_numerical': 0.0008054772452678212, 'mean_word_length': 3.8421052631578947, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2231408', 'n_tokens_mistral': 754, 'n_tokens_neox': 746, 'n_words': 244}