1 | # download-git-repo
|
2 |
|
3 | Download and extract a git repository (GitHub, GitLab, Bitbucket) from node.
|
4 |
|
5 | ## Installation
|
6 |
|
7 | $ npm install download-git-repo
|
8 |
|
9 | ## API
|
10 |
|
11 | ### download(repository, destination, options, callback)
|
12 |
|
13 | Download a git `repository` to a `destination` folder with `options`, and `callback`.
|
14 |
|
15 | #### repository
|
16 | The short hand repository string to download the repository from:
|
17 |
|
18 | - GitHub - `github:owner/name` or simply `owner/name`
|
19 | - GitLab - `gitlab:owner/name`
|
20 | - Bitbucket - `bitbucket:owner/name`
|
21 |
|
22 | The `repository` parameter defaults to the `master` branch, but you can specify a branch or tag as a URL fragment like `owner/name#my-branch`.
|
23 | In addition to specifying the type of where to download, you can also specify a custom origin like `gitlab:custom.com:owner/name`.
|
24 | Custom origin will default to `https` or `git@` for http and clone downloads respectively, unless protocol is specified.
|
25 | Feel free to submit an issue or pull request for additional origin options.
|
26 |
|
27 | #### destination
|
28 | The file path to download the repository to.
|
29 |
|
30 | #### options
|
31 | An optional options object parameter with download options. Options include:
|
32 |
|
33 | - `clone` - boolean default `false` - If true use `git clone` instead of an http download. While this can be a bit slower, it does allow private repositories to be used if the appropriate SSH keys are setup.
|
34 |
|
35 | #### callback
|
36 | The callback function as `function (err)`.
|
37 |
|
38 | ## Examples
|
39 | Using http download from Github repository at master.
|
40 | ```javascript
|
41 | download('flipxfx/download-git-repo-fixture', 'test/tmp', function (err) {
|
42 | console.log(err ? 'Error' : 'Success')
|
43 | })
|
44 | ```
|
45 |
|
46 | Using git clone from Bitbucket repository at my-branch.
|
47 | ```javascript
|
48 | download('bitbucket:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
|
49 | console.log(err ? 'Error' : 'Success')
|
50 | })
|
51 | ```
|
52 |
|
53 | Using http download from GitLab repository with custom origin.
|
54 | ```javascript
|
55 | download('gitlab:mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', function (err) {
|
56 | console.log(err ? 'Error' : 'Success')
|
57 | })
|
58 | ```
|
59 |
|
60 | Using git clone from GitLab repository with custom origin and protocol.
|
61 | Note that the repository type (`github`, `gitlab` etc.) is not required if cloning from a custom origin.
|
62 | ```javascript
|
63 | download('https://mygitlab.com:flipxfx/download-git-repo-fixture#my-branch', 'test/tmp', { clone: true }, function (err) {
|
64 | console.log(err ? 'Error' : 'Success')
|
65 | })
|
66 | ```
|
67 |
|
68 | ## Thanks
|
69 |
|
70 | To [ianstormtaylor/download-github-repo](https://github.com/ianstormtaylor/download-github-repo) for the head start.
|
71 |
|
72 | ## License
|
73 |
|
74 | MIT
|
75 |
|