1
- import tempy from 'tempy' ;
2
- import execa from 'execa' ;
3
- import fileUrl from 'file-url' ;
4
- import pReduce from 'p-reduce' ;
5
- import gitLogParser from 'git-log-parser' ;
6
- import getStream from 'get-stream' ;
1
+ const tempy = require ( 'tempy' ) ;
2
+ const execa = require ( 'execa' ) ;
3
+ const fileUrl = require ( 'file-url' ) ;
4
+ const pReduce = require ( 'p-reduce' ) ;
5
+ const gitLogParser = require ( 'git-log-parser' ) ;
6
+ const getStream = require ( 'get-stream' ) ;
7
7
8
8
/**
9
9
* Create a temporary git repository.
@@ -14,7 +14,7 @@ import getStream from 'get-stream';
14
14
* @param {String } [branch='master'] The branch to initialize.
15
15
* @return {String } The path of the clone if `withRemote` is `true`, the path of the repository otherwise.
16
16
*/
17
- export async function gitRepo ( withRemote , branch = 'master' ) {
17
+ async function gitRepo ( withRemote , branch = 'master' ) {
18
18
let cwd = tempy . directory ( ) ;
19
19
20
20
await execa ( 'git' , [ 'init' ] . concat ( withRemote ? [ '--bare' ] : [ ] ) , { cwd} ) ;
@@ -43,7 +43,7 @@ export async function gitRepo(withRemote, branch = 'master') {
43
43
* @param {String } repositoryUrl The URL of the bare repository.
44
44
* @param {String } [branch='master'] the branch to initialize.
45
45
*/
46
- export async function initBareRepo ( repositoryUrl , branch = 'master' ) {
46
+ async function initBareRepo ( repositoryUrl , branch = 'master' ) {
47
47
const cwd = tempy . directory ( ) ;
48
48
await execa ( 'git' , [ 'clone' , '--no-hardlinks' , repositoryUrl , cwd ] , { cwd} ) ;
49
49
await gitCheckout ( branch , true , { cwd} ) ;
@@ -59,7 +59,7 @@ export async function initBareRepo(repositoryUrl, branch = 'master') {
59
59
*
60
60
* @returns {Array<Commit> } The created commits, in reverse order (to match `git log` order).
61
61
*/
62
- export async function gitCommits ( messages , execaOpts ) {
62
+ async function gitCommits ( messages , execaOpts ) {
63
63
await pReduce (
64
64
messages ,
65
65
async ( _ , message ) =>
@@ -76,7 +76,7 @@ export async function gitCommits(messages, execaOpts) {
76
76
*
77
77
* @return {Array<Object> } The list of parsed commits.
78
78
*/
79
- export async function gitGetCommits ( from , execaOpts ) {
79
+ async function gitGetCommits ( from , execaOpts ) {
80
80
Object . assign ( gitLogParser . fields , { hash : 'H' , message : 'B' , gitTags : 'd' , committerDate : { key : 'ci' , type : Date } } ) ;
81
81
return (
82
82
await getStream . array (
@@ -96,7 +96,7 @@ export async function gitGetCommits(from, execaOpts) {
96
96
* @param {Boolean } create to create the branch, `false` to checkout an existing branch.
97
97
* @param {Object } [execaOpts] Options to pass to `execa`.
98
98
*/
99
- export async function gitCheckout ( branch , create , execaOpts ) {
99
+ async function gitCheckout ( branch , create , execaOpts ) {
100
100
await execa ( 'git' , create ? [ 'checkout' , '-b' , branch ] : [ 'checkout' , branch ] , execaOpts ) ;
101
101
}
102
102
@@ -107,7 +107,7 @@ export async function gitCheckout(branch, create, execaOpts) {
107
107
* @param {String } [sha] The commit on which to create the tag. If undefined the tag is created on the last commit.
108
108
* @param {Object } [execaOpts] Options to pass to `execa`.
109
109
*/
110
- export async function gitTagVersion ( tagName , sha , execaOpts ) {
110
+ async function gitTagVersion ( tagName , sha , execaOpts ) {
111
111
await execa ( 'git' , sha ? [ 'tag' , '-f' , tagName , sha ] : [ 'tag' , tagName ] , execaOpts ) ;
112
112
}
113
113
@@ -120,7 +120,7 @@ export async function gitTagVersion(tagName, sha, execaOpts) {
120
120
* @param {Number } [depth=1] The number of commit to clone.
121
121
* @return {String } The path of the cloned repository.
122
122
*/
123
- export async function gitShallowClone ( repositoryUrl , branch = 'master' , depth = 1 ) {
123
+ async function gitShallowClone ( repositoryUrl , branch = 'master' , depth = 1 ) {
124
124
const cwd = tempy . directory ( ) ;
125
125
126
126
await execa ( 'git' , [ 'clone' , '--no-hardlinks' , '--no-tags' , '-b' , branch , '--depth' , depth , repositoryUrl , cwd ] , {
@@ -136,7 +136,7 @@ export async function gitShallowClone(repositoryUrl, branch = 'master', depth =
136
136
* @param {Number } head A commit sha of the remote repo that will become the detached head of the new one.
137
137
* @return {String } The path of the new repository.
138
138
*/
139
- export async function gitDetachedHead ( repositoryUrl , head ) {
139
+ async function gitDetachedHead ( repositoryUrl , head ) {
140
140
const cwd = tempy . directory ( ) ;
141
141
142
142
await execa ( 'git' , [ 'init' ] , { cwd} ) ;
@@ -154,7 +154,7 @@ export async function gitDetachedHead(repositoryUrl, head) {
154
154
*
155
155
* @return {String } The HEAD sha of the remote repository.
156
156
*/
157
- export async function gitRemoteHead ( repositoryUrl , execaOpts ) {
157
+ async function gitRemoteHead ( repositoryUrl , execaOpts ) {
158
158
return ( await execa ( 'git' , [ 'ls-remote' , repositoryUrl , 'HEAD' ] , execaOpts ) ) . stdout
159
159
. split ( '\n' )
160
160
. filter ( head => Boolean ( head ) )
@@ -168,7 +168,7 @@ export async function gitRemoteHead(repositoryUrl, execaOpts) {
168
168
*
169
169
* @return {Array<String> } Array of staged files path.
170
170
*/
171
- export async function gitStaged ( execaOpts ) {
171
+ async function gitStaged ( execaOpts ) {
172
172
return ( await execa ( 'git' , [ 'status' , '--porcelain' ] , execaOpts ) ) . stdout
173
173
. split ( '\n' )
174
174
. filter ( status => status . startsWith ( 'A ' ) )
@@ -183,7 +183,7 @@ export async function gitStaged(execaOpts) {
183
183
*
184
184
* @return {Array<String> } The list of files path included in the commit.
185
185
*/
186
- export async function gitCommitedFiles ( ref , execaOpts ) {
186
+ async function gitCommitedFiles ( ref , execaOpts ) {
187
187
return ( await execa ( 'git' , [ 'diff-tree' , '-r' , '--name-only' , '--no-commit-id' , '-r' , ref ] , execaOpts ) ) . stdout
188
188
. split ( '\n' )
189
189
. filter ( file => Boolean ( file ) ) ;
@@ -195,7 +195,7 @@ export async function gitCommitedFiles(ref, execaOpts) {
195
195
* @param {Array<String> } files Array of files path to add to the index.
196
196
* @param {Object } [execaOpts] Options to pass to `execa`.
197
197
*/
198
- export async function gitAdd ( files , execaOpts ) {
198
+ async function gitAdd ( files , execaOpts ) {
199
199
await execa ( 'git' , [ 'add' , '--force' , '--ignore-errors' , ...files ] , { ...execaOpts } ) ;
200
200
}
201
201
@@ -206,6 +206,22 @@ export async function gitAdd(files, execaOpts) {
206
206
* @param {String } branch The branch to push.
207
207
* @param {Object } [execaOpts] Options to pass to `execa`.
208
208
*/
209
- export async function gitPush ( repositoryUrl , branch , execaOpts ) {
209
+ async function gitPush ( repositoryUrl , branch , execaOpts ) {
210
210
await execa ( 'git' , [ 'push' , '--tags' , repositoryUrl , `HEAD:${ branch } ` ] , execaOpts ) ;
211
211
}
212
+
213
+ module . exports = {
214
+ gitRepo,
215
+ initBareRepo,
216
+ gitCommits,
217
+ gitGetCommits,
218
+ gitCheckout,
219
+ gitTagVersion,
220
+ gitShallowClone,
221
+ gitDetachedHead,
222
+ gitRemoteHead,
223
+ gitStaged,
224
+ gitCommitedFiles,
225
+ gitAdd,
226
+ gitPush,
227
+ } ;
0 commit comments