How to use dugite - 10 common examples

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 / rev-list.ts View on Github external
export async function getAheadBehind(
  repository: Repository,
  range: string
): Promise {
  // `--left-right` annotates the list of commits in the range with which side
  // they're coming from. When used with `--count`, it tells us how many
  // commits we have from the two different sides of the range.
  const args = ['rev-list', '--left-right', '--count', range, '--']
  const result = await git(args, repository.path, 'getAheadBehind', {
    expectedErrors: new Set([GitError.BadRevision]),
  })

  // This means one of the refs (most likely the upstream branch) no longer
  // exists. In that case we can't be ahead/behind at all.
  if (result.gitError === GitError.BadRevision) {
    return null
  }

  const stdout = result.stdout
  const pieces = stdout.split('\t')
  if (pieces.length !== 2) {
    return null
  }

  const ahead = parseInt(pieces[0], 10)
  if (isNaN(ahead)) {
github desktop / desktop / app / src / lib / git / rev-list.ts View on Github external
export async function getAheadBehind(
  repository: Repository,
  range: string
): Promise {
  // `--left-right` annotates the list of commits in the range with which side
  // they're coming from. When used with `--count`, it tells us how many
  // commits we have from the two different sides of the range.
  const args = ['rev-list', '--left-right', '--count', range, '--']
  const result = await git(args, repository.path, 'getAheadBehind', {
    expectedErrors: new Set([GitError.BadRevision]),
  })

  // This means one of the refs (most likely the upstream branch) no longer
  // exists. In that case we can't be ahead/behind at all.
  if (result.gitError === GitError.BadRevision) {
    return null
  }

  const stdout = result.stdout
  const pieces = stdout.split('\t')
  if (pieces.length !== 2) {
    return null
  }

  const ahead = parseInt(pieces[0], 10)
  if (isNaN(ahead)) {
    return null
  }

  const behind = parseInt(pieces[1], 10)
  if (isNaN(behind)) {
github desktop / desktop / app / src / lib / git / core.ts View on Github external
const commandName = `${name}: git ${args.join(' ')}`

  const result = await GitPerf.measure(commandName, () =>
    GitProcess.exec(args, path, options)
  )

  const exitCode = result.exitCode

  let gitError: DugiteError | null = null
  const acceptableExitCode = opts.successExitCodes
    ? opts.successExitCodes.has(exitCode)
    : false
  if (!acceptableExitCode) {
    gitError = GitProcess.parseError(result.stderr)
    if (!gitError) {
      gitError = GitProcess.parseError(result.stdout)
    }
  }

  const gitErrorDescription = gitError ? getDescriptionForError(gitError) : null
  const gitResult = { ...result, gitError, gitErrorDescription }

  let acceptableError = true
  if (gitError && opts.expectedErrors) {
    acceptableError = opts.expectedErrors.has(gitError)
  }

  if ((gitError && acceptableError) || acceptableExitCode) {
    return gitResult
  }

  // The caller should either handle this error, or expect that exit code.
github desktop / desktop / app / src / lib / dispatcher / error-handlers.ts View on Github external
const e = asErrorWithMetadata(error)
  if (!e) {
    return error
  }

  const gitError = asGitError(e.underlyingError)
  if (!gitError) {
    return error
  }

  const dugiteError = gitError.result.gitError
  if (!dugiteError) {
    return error
  }

  if (dugiteError !== DugiteError.PushNotFastForward) {
    return error
  }

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

  if (!(repository instanceof Repository)) {
    return error
  }

  // Since they need to pull, go ahead and do a fetch for them.
  dispatcher.fetch(repository, FetchType.UserInitiatedTask)

  return error
github electron / electron / script / release / prepare-release.js View on Github external
async function pushRelease (branch) {
  const pushDetails = await GitProcess.exec(['push', 'origin', `HEAD:${branch}`, '--follow-tags'], ELECTRON_DIR)
  if (pushDetails.exitCode === 0) {
    console.log(`${pass} Successfully pushed the release.  Wait for ` +
      `release builds to finish before running "npm run release".`)
  } else {
    console.log(`${fail} Error pushing the release: ${pushDetails.stderr}`)
    process.exit(1)
  }
}
github electron / electron / script / merge-release.js View on Github external
async function mergeReleaseIntoBranch (branchName) {
  console.log(`Merging release branch into ${branchName}.`)
  let mergeArgs = ['merge', 'release', '--squash']
  let mergeDetails = await GitProcess.exec(mergeArgs, gitDir)
  if (mergeDetails.exitCode === 0) {
    return true
  } else {
    const error = GitProcess.parseError(mergeDetails.stderr)
    if (error === GitError.MergeConflicts) {
      console.log(`${fail} Could not merge release branch into ${branchName} ` +
        `due to merge conflicts.`)
      return false
    } else {
      console.log(`${fail} Could not merge release branch into ${branchName} ` +
        `due to an error: ${mergeDetails.stderr}.`)
      process.exit(1)
    }
  }
}
github electron / electron / script / lint.js View on Github external
async function findChangedFiles (top) {
  const result = await GitProcess.exec(['diff', '--name-only', '--cached'], top)
  if (result.exitCode !== 0) {
    console.log('Failed to find changed files', GitProcess.parseError(result.stderr))
    process.exit(1)
  }
  const relativePaths = result.stdout.split(/\r\n|\r|\n/g)
  const absolutePaths = relativePaths.map(x => path.join(top, x))
  return new Set(absolutePaths)
}
github electron / electron / script / merge-release.js View on Github external
async function mergeReleaseIntoBranch (branchName) {
  console.log(`Merging release branch into ${branchName}.`)
  let mergeArgs = ['merge', 'release', '--squash']
  let mergeDetails = await GitProcess.exec(mergeArgs, gitDir)
  if (mergeDetails.exitCode === 0) {
    return true
  } else {
    const error = GitProcess.parseError(mergeDetails.stderr)
    if (error === GitError.MergeConflicts) {
      console.log(`${fail} Could not merge release branch into ${branchName} ` +
        `due to merge conflicts.`)
      return false
    } else {
      console.log(`${fail} Could not merge release branch into ${branchName} ` +
        `due to an error: ${mergeDetails.stderr}.`)
      process.exit(1)
    }
  }
}