How to use the dugite.GitError.NotAGitRepository function in dugite

To help you get started, we’ve selected a few dugite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github desktop / desktop / app / src / lib / git / for-each-ref.ts View on Github external
'%(trailers:unfold,only)',
    `%${delimiter}`, // indicate end-of-line as %(body) may contain newlines
  ].join('%00')

  if (!prefixes || !prefixes.length) {
    prefixes = ['refs/heads', 'refs/remotes']
  }

  // TODO: use expectedErrors here to handle a specific error
  // see https://github.com/desktop/desktop/pull/5299#discussion_r206603442 for
  // discussion about what needs to change
  const result = await git(
    ['for-each-ref', `--format=${format}`, ...prefixes],
    repository.path,
    'getBranches',
    { expectedErrors: new Set([GitError.NotAGitRepository]) }
  )

  if (result.gitError === GitError.NotAGitRepository) {
    return []
  }

  const names = result.stdout
  const lines = names.split(delimiterString)

  // Remove the trailing newline
  lines.splice(-1, 1)

  if (lines.length === 0) {
    return []
  }
github desktop / desktop / app / src / lib / git / for-each-ref.ts View on Github external
if (!prefixes || !prefixes.length) {
    prefixes = ['refs/heads', 'refs/remotes']
  }

  // TODO: use expectedErrors here to handle a specific error
  // see https://github.com/desktop/desktop/pull/5299#discussion_r206603442 for
  // discussion about what needs to change
  const result = await git(
    ['for-each-ref', `--format=${format}`, ...prefixes],
    repository.path,
    'getBranches',
    { expectedErrors: new Set([GitError.NotAGitRepository]) }
  )

  if (result.gitError === GitError.NotAGitRepository) {
    return []
  }

  const names = result.stdout
  const lines = names.split(delimiterString)

  // Remove the trailing newline
  lines.splice(-1, 1)

  if (lines.length === 0) {
    return []
  }

  const trailerSeparators = await getTrailerSeparatorCharacters(repository)

  const branches = []
github desktop / desktop / app / src / lib / git / core.ts View on Github external
return 'A submodule points to a commit which does not exist.'
    case DugiteError.LocalPermissionDenied:
      return 'Permission denied.'
    case DugiteError.InvalidMerge:
      return 'This is not something we can merge.'
    case DugiteError.InvalidRebase:
      return 'This is not something we can rebase.'
    case DugiteError.NonFastForwardMergeIntoEmptyHead:
      return 'The merge you attempted is not a fast-forward, so it cannot be performed on an empty branch.'
    case DugiteError.PatchDoesNotApply:
      return 'The requested changes conflict with one or more files in the repository.'
    case DugiteError.BranchAlreadyExists:
      return 'A branch with that name already exists.'
    case DugiteError.BadRevision:
      return 'Bad revision.'
    case DugiteError.NotAGitRepository:
      return 'This is not a git repository.'
    case DugiteError.ProtectedBranchForcePush:
      return 'This branch is protected from force-push operations.'
    case DugiteError.ProtectedBranchRequiresReview:
      return 'This branch is protected and any changes requires an approved review. Open a pull request with changes targeting this branch instead.'
    case DugiteError.PushWithFileSizeExceedingLimit:
      return "The push operation includes a file which exceeds GitHub's file size restriction of 100MB. Please remove the file from history and try again."
    case DugiteError.HexBranchNameRejected:
      return 'The branch name cannot be a 40-character string of hexadecimal characters, as this is the format that Git uses for representing objects.'
    case DugiteError.ForcePushRejected:
      return 'The force push has been rejected for the current branch.'
    case DugiteError.InvalidRefLength:
      return 'A ref cannot be longer than 255 characters.'
    case DugiteError.CannotMergeUnrelatedHistories:
      return 'Unable to merge unrelated histories in this repository.'
    case DugiteError.PushWithPrivateEmail:
github desktop / desktop / app / src / lib / dispatcher / error-handlers.ts View on Github external
return error
  }

  const repository = e.metadata.repository
  if (!repository || !(repository instanceof Repository)) {
    return error
  }

  if (repository.missing) {
    return null
  }

  const errorWithCode = asErrorWithCode(e.underlyingError)
  const gitError = asGitError(e.underlyingError)
  const missing =
    (gitError && gitError.result.gitError === DugiteError.NotAGitRepository) ||
    (errorWithCode && errorWithCode.code === RepositoryDoesNotExistErrorCode)

  if (missing) {
    await dispatcher.updateRepositoryMissing(repository, true)
    return null
  }

  return error
}