import { git, envForAuthentication, expectedAuthenticationErrors, GitError } from './core'
import { Repository } from '../../models/repository'
import { User } from '../../models/user'

/** Fetch from the given remote. */
export async function fetch(repository: Repository, user: User | null, remote: string): Promise<void> {
  const options = {
    successExitCodes: new Set([ 0 ]),
    env: envForAuthentication(user),
    expectedErrors: expectedAuthenticationErrors(),
  }

  const args = [ 'fetch', '--prune', remote ]
  const result = await git(args, repository.path, 'fetch', options)

  if (result.gitErrorDescription) {
    return Promise.reject(new GitError(result, args))
  }

  return Promise.resolve()
}

/** Fetch a given refspec from the given remote. */
export async function fetchRefspec(repository: Repository, user: User | null, remote: string, refspec: string): Promise<void> {
  const options = {
    successExitCodes: new Set([ 0, 128 ]),
    env: envForAuthentication(user),
    expectedErrors: expectedAuthenticationErrors(),
  }

  const args = [ 'fetch', remote, refspec ]
  const result = await git(args, repository.path, 'fetchRefspec', options)

  if (result.gitErrorDescription) {
    return Promise.reject(new GitError(result, args))
  }

  return Promise.resolve()
}


import { git, envForAuthentication, expectedAuthenticationErrors } from './core'
import { Repository } from '../../models/repository'
import { User } from '../../models/user'

/** Fetch from the given remote. */
export async function fetch(repository: Repository, user: User | null, remote: string): Promise<void> {
  const options = {
    successExitCodes: new Set([ 0 ]),
    env: envForAuthentication(user),
    expectedErrors: expectedAuthenticationErrors(),
  }

  await git([ 'fetch', '--prune', remote ], repository.path, 'fetch', options)
}

/** Fetch a given refspec from the given remote. */
export async function fetchRefspec(repository: Repository, user: User | null, remote: string, refspec: string): Promise<void> {
  const options = {
    successExitCodes: new Set([ 0, 128 ]),
    env: envForAuthentication(user),
    expectedErrors: expectedAuthenticationErrors(),
  }

  await git([ 'fetch', remote, refspec ], repository.path, 'fetchRefspec', options)
}


--- 
+++ 
@@ -1,4 +1,4 @@
-import { git, envForAuthentication, expectedAuthenticationErrors } from './core'
+import { git, envForAuthentication, expectedAuthenticationErrors, GitError } from './core'
 import { Repository } from '../../models/repository'
 import { User } from '../../models/user'
 
@@ -10,7 +10,14 @@
     expectedErrors: expectedAuthenticationErrors(),
   }
 
-  await git([ 'fetch', '--prune', remote ], repository.path, 'fetch', options)
+  const args = [ 'fetch', '--prune', remote ]
+  const result = await git(args, repository.path, 'fetch', options)
+
+  if (result.gitErrorDescription) {
+    return Promise.reject(new GitError(result, args))
+  }
+
+  return Promise.resolve()
 }
 
 /** Fetch a given refspec from the given remote. */
@@ -21,6 +28,13 @@
     expectedErrors: expectedAuthenticationErrors(),
   }
 
-  await git([ 'fetch', remote, refspec ], repository.path, 'fetchRefspec', options)
+  const args = [ 'fetch', remote, refspec ]
+  const result = await git(args, repository.path, 'fetchRefspec', options)
+
+  if (result.gitErrorDescription) {
+    return Promise.reject(new GitError(result, args))
+  }
+
+  return Promise.resolve()
 }
 
Revert "cleanup check and rethrow"

This reverts commit 3df56c32782f966e438da0c596357208b4e9bf9a.
