-
-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fetch) Add updated/deleted branches to fetch response.
Parses more of the git fetch response, notably updates + deletes. This returns the to/from commit of each branch. When `--prune` is passed, git will also return deleted branches.
- Loading branch information
1 parent
61d4ee0
commit dffe6f4
Showing
3 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// ./simple-git/test/integration/fetch.spec.ts | ||
|
||
import { | ||
createTestContext, | ||
newSimpleGit, | ||
setUpInit, | ||
SimpleGitTestContext | ||
} from '../__fixtures__'; | ||
|
||
describe('fetch', () => { | ||
let context: SimpleGitTestContext; | ||
let upstream: string; | ||
let local: string; | ||
|
||
beforeEach(async () => (context = await createTestContext())); | ||
beforeEach(async () => { | ||
upstream = await context.dir('upstream'); | ||
local = context.path('local'); | ||
await context.file(['upstream', 'file']); | ||
|
||
await givenRemote(upstream); | ||
await givenLocal(upstream, local); | ||
}); | ||
|
||
it('fetches updates', async () => { | ||
const git = newSimpleGit(local); | ||
const bravoPriorHead = await git.revparse('origin/bravo'); | ||
await givenRemoteChanges(upstream); | ||
|
||
const result = await git.fetch(['--prune']); | ||
|
||
const bravoCurrentHead = await git.revparse('origin/bravo'); | ||
|
||
expect(result).toEqual({ | ||
branches: [ | ||
{ | ||
name: 'delta', | ||
tracking: 'origin/delta' | ||
} | ||
], | ||
deleted: [{ tracking: 'origin/charlie' }], | ||
raw: '', | ||
remote: upstream, | ||
tags: [ | ||
{ | ||
name: 'alpha', | ||
tracking: 'alpha' | ||
} | ||
], | ||
updated: [ | ||
{ | ||
from: bravoPriorHead.substring(0, 7), | ||
name: 'bravo', | ||
to: bravoCurrentHead.substring(0, 7), | ||
tracking: 'origin/bravo' | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
/** | ||
* Sets up the repo to be used as a local - by cloning the remote | ||
*/ | ||
async function givenLocal(upstream: string, local: string) { | ||
await newSimpleGit(context.root).clone(upstream, local); | ||
await setUpInit({ git: newSimpleGit(local) }); | ||
} | ||
|
||
/** | ||
* Sets up the repo to be used as a remote | ||
*/ | ||
async function givenRemote(upstream: string) { | ||
const git = newSimpleGit(upstream); | ||
await setUpInit({ git }); | ||
await git.add('.'); | ||
await git.commit('first'); | ||
await git.raw('checkout', '-b', 'bravo'); | ||
await git.raw('checkout', '-b', 'charlie'); | ||
} | ||
/** | ||
* Configure the remote with changes to be retrieved when using fetch on the local | ||
*/ | ||
async function givenRemoteChanges(upstream: string) { | ||
const git = newSimpleGit(upstream); | ||
await git.raw('tag', 'alpha'); | ||
await git.raw('checkout', 'bravo'); | ||
await context.file(['upstream', 'another-file']); | ||
await git.add('.'); | ||
await git.commit('second'); | ||
await git.raw('checkout', '-b', 'delta'); | ||
await git.raw('branch', '-d', 'charlie'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters