forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.ts
More file actions
62 lines (55 loc) · 2.38 KB
/
Copy pathgit.ts
File metadata and controls
62 lines (55 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { execFile } from 'child_process';
import { promisify } from 'util';
import { Repository } from '../typings/git';
import Logger from './logger';
const exec = promisify(execFile);
/**
* Push a local branch to a remote.
*
* @param remote name of remote to push to
* @param {string?} localBranch name of local branch to push (default: current branch)
* @param {string?} remoteBranch name of remote branch (default: name of local branch)
*/
export async function push(
repo: Repository,
remote: string,
localBranch: string = repo.state.HEAD.name,
remoteBranch: string = localBranch): Promise<void> {
const {path: git} = (<any>repo)._repository.repository.git as any;
const args = ['push', '--porcelain', remote, `${localBranch}:${remoteBranch}`];
Logger.appendLine(`run> git ${args.join(' ')}`);
const {stdout, stderr} = await exec(git, args, {
cwd: repo.rootUri.fsPath,
});
Logger.appendLine(stdout);
Logger.appendLine(stderr);
}
// async pull(rebase?: boolean, remote?: string, branch?: string): Promise<void> {
// const args = ['pull', '--tags'];
// if (rebase) {
// args.push('-r');
// }
// if (remote && branch) {
// args.push(remote);
// args.push(branch);
// }
// try {
// await this.run(args);
// } catch (err) {
// if (/^CONFLICT \([^)]+\): \b/m.test(err.stdout || '')) {
// err.gitErrorCode = GitErrorCodes.Conflict;
// } else if (/Please tell me who you are\./.test(err.stderr || '')) {
// err.gitErrorCode = GitErrorCodes.NoUserNameConfigured;
// } else if (/Could not read from remote repository/.test(err.stderr || '')) {
// err.gitErrorCode = GitErrorCodes.RemoteConnectionError;
// } else if (/Pull is not possible because you have unmerged files|Cannot pull with rebase: You have unstaged changes|Your local changes to the following files would be overwritten|Please, commit your changes before you can merge/i.test(err.stderr)) {
// err.stderr = err.stderr.replace(/Cannot pull with rebase: You have unstaged changes/i, 'Cannot pull with rebase, you have unstaged changes');
// err.gitErrorCode = GitErrorCodes.DirtyWorkTree;
// } else if (/cannot lock ref|unable to update local ref/i.test(err.stderr || '')) {
// err.gitErrorCode = GitErrorCodes.CantLockRef;
// } else if (/cannot rebase onto multiple branches/i.test(err.stderr || '')) {
// err.gitErrorCode = GitErrorCodes.CantRebaseMultipleBranches;
// }
// throw err;
// }
// }