Handler for the `git fetch` command.
(rawArgs: string[])
| 137 | |
| 138 | /** Handler for the `git fetch` command. */ |
| 139 | private _fetch(rawArgs: string[]) { |
| 140 | const cleanArgs = rawArgs.filter((arg) => arg !== '--'); |
| 141 | const {force, refspec, repoUrl} = yargs(cleanArgs) |
| 142 | .command('$0 <repoUrl> <refspec>', false) |
| 143 | .positional('repoUrl', {type: 'string', demandOption: true}) |
| 144 | .positional('refspec', {type: 'string', demandOption: true}) |
| 145 | .option('force', {boolean: true, alias: 'f'}) |
| 146 | .option('quiet', {boolean: true, alias: 'q'}) |
| 147 | .parseSync(); |
| 148 | |
| 149 | const ref = this._unwrapRefspec(refspec); |
| 150 | |
| 151 | // Keep track of the fetch head, so that it can be checked out |
| 152 | // later in a detached state. |
| 153 | this.fetchHeadRef = {name: ref.source, repoUrl: repoUrl}; |
| 154 | |
| 155 | // If a destination has been specified in the ref spec, add it to the |
| 156 | // list of available local branches. |
| 157 | if (ref.destination) { |
| 158 | if (this.branches[ref.destination] && !force) { |
| 159 | throw Error('Cannot override existing local branch when fetching.'); |
| 160 | } |
| 161 | this.branches[ref.destination] = { |
| 162 | branch: ref.destination, |
| 163 | ref: this.fetchHeadRef, |
| 164 | newCommits: [], |
| 165 | }; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** Handler for the `git checkout` command. */ |
| 170 | private _checkout(rawArgs: string[]) { |
no test coverage detected