From d8aaf716c435f225880b890c4c13732be9d9621c Mon Sep 17 00:00:00 2001 From: laphets Date: Wed, 17 Oct 2018 21:04:31 +0800 Subject: [PATCH 1/5] Fulfill local branch checking when checkout to an remote branch --- extensions/git/src/api/git.d.ts | 5 +++++ extensions/git/src/commands.ts | 16 ++++++++++++++-- extensions/git/src/git.ts | 17 ++++++++++++++++- extensions/git/src/repository.ts | 7 ++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index 988b6eca7a6..c2d41d1e0f2 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -26,6 +26,11 @@ export interface Ref { readonly remote?: string; } +export interface Trackingship { + readonly local: string; + readonly upstarem: string; +} + export interface UpstreamRef { readonly remote: string; readonly name: string; diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 9c838715840..4ad9adb0e3b 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -52,11 +52,20 @@ class CheckoutRemoteHeadItem extends CheckoutItem { } async run(repository: Repository): Promise { - if (!this.ref.name) { + const ref = this.ref.name; + if (!ref) { return; } - await repository.checkoutTracking(this.ref.name); + // Check whether there's a local branch which already has the target branch as an upstream + const trackings = await repository.getTracking(ref); + if (trackings.length > 0) { + //Just checkout the local branch + await repository.checkout(trackings[0].local); + } else { + // Default + await repository.checkoutTracking(ref); + } } } @@ -1373,6 +1382,9 @@ export class CommandCenter { const placeHolder = localize('select a ref to checkout', 'Select a ref to checkout'); const choice = await window.showQuickPick(picks, { placeHolder }); + // TODO: Judge whether it's local branch + console.log(choice); + if (!choice) { return false; } diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 0deb723c9d0..e7ee5231c5b 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -14,7 +14,7 @@ import * as filetype from 'file-type'; import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent } from './util'; import { CancellationToken } from 'vscode'; import { detectEncoding } from './encoding'; -import { Ref, RefType, Branch, Remote, GitErrorCodes } from './api/git'; +import { Ref, RefType, Branch, Remote, GitErrorCodes, Trackingship } from './api/git'; const readfile = denodeify(fs.readFile); @@ -1374,6 +1374,21 @@ export class Repository { } } + async GetTracking(upstreamBranch: string): Promise { + const result = await this.run(['for-each-ref', '--format', '%(if)%(upstream:short)%(then)%(refname:short)->%(upstream:short) %(else)* %(end)', 'refs/heads']); + return result.stdout.trim().split('\n') + .map(line => line.trim()) + .filter(line => line !== '*') + .map(line => { + const splited = line.split('->'); + return { + local: splited[0], + upstarem: splited[1] + } as Trackingship; + }) + .filter(trackingShip => trackingShip.upstarem === upstreamBranch); + } + async getRefs(): Promise { const result = await this.run(['for-each-ref', '--format', '%(refname) %(objectname)', '--sort', '-committerdate']); diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index 003a6ba2ea7..d8dcc69a9a8 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -13,7 +13,7 @@ import * as path from 'path'; import * as nls from 'vscode-nls'; import * as fs from 'fs'; import { StatusBarCommands } from './statusbar'; -import { Branch, Ref, Remote, RefType, GitErrorCodes } from './api/git'; +import { Branch, Ref, Remote, RefType, GitErrorCodes, Trackingship } from './api/git'; const timeout = (millis: number) => new Promise(c => setTimeout(c, millis)); @@ -311,6 +311,7 @@ export const enum Operation { GetObjectDetails = 'GetObjectDetails', SubmoduleUpdate = 'SubmoduleUpdate', RebaseContinue = 'RebaseContinue', + GetTracking = 'GetTracking' } function isReadOnly(operation: Operation): boolean { @@ -880,6 +881,10 @@ export class Repository implements Disposable { await this.run(Operation.CheckoutTracking, () => this.repository.checkout(treeish, [], { track: true })); } + async getTracking(treeish: string): Promise { + return await this.run(Operation.GetTracking, () => this.repository.GetTracking(treeish)); + } + async getCommit(ref: string): Promise { return await this.repository.getCommit(ref); } From d99dea11d1071f437602ebad4b7b04c23df003e0 Mon Sep 17 00:00:00 2001 From: laphets Date: Wed, 17 Oct 2018 23:45:24 +0800 Subject: [PATCH 2/5] Remove useless console --- extensions/git/src/commands.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 4ad9adb0e3b..42178ef825d 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1382,9 +1382,6 @@ export class CommandCenter { const placeHolder = localize('select a ref to checkout', 'Select a ref to checkout'); const choice = await window.showQuickPick(picks, { placeHolder }); - // TODO: Judge whether it's local branch - console.log(choice); - if (!choice) { return false; } From d24031bf45c3688cfe41dfdeba8168ab5991a6e8 Mon Sep 17 00:00:00 2001 From: laphets Date: Thu, 18 Oct 2018 10:25:12 +0800 Subject: [PATCH 3/5] Fix some typo Update extensions/git/src/api/git.d.ts Fix another typo Fix some typo --- extensions/git/src/api/git.d.ts | 6 +++--- extensions/git/src/git.ts | 10 +++++----- extensions/git/src/repository.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/extensions/git/src/api/git.d.ts b/extensions/git/src/api/git.d.ts index c2d41d1e0f2..a20df351ea5 100644 --- a/extensions/git/src/api/git.d.ts +++ b/extensions/git/src/api/git.d.ts @@ -26,9 +26,9 @@ export interface Ref { readonly remote?: string; } -export interface Trackingship { +export interface TrackingShip { readonly local: string; - readonly upstarem: string; + readonly upstream: string; } export interface UpstreamRef { @@ -175,4 +175,4 @@ export const enum GitErrorCodes { WrongCase = 'WrongCase', CantLockRef = 'CantLockRef', CantRebaseMultipleBranches = 'CantRebaseMultipleBranches', -} \ No newline at end of file +} diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index e7ee5231c5b..02ca9afafc1 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -14,7 +14,7 @@ import * as filetype from 'file-type'; import { assign, groupBy, denodeify, IDisposable, toDisposable, dispose, mkdirp, readBytes, detectUnicodeEncoding, Encoding, onceEvent } from './util'; import { CancellationToken } from 'vscode'; import { detectEncoding } from './encoding'; -import { Ref, RefType, Branch, Remote, GitErrorCodes, Trackingship } from './api/git'; +import { Ref, RefType, Branch, Remote, GitErrorCodes, TrackingShip } from './api/git'; const readfile = denodeify(fs.readFile); @@ -1374,7 +1374,7 @@ export class Repository { } } - async GetTracking(upstreamBranch: string): Promise { + async GetTracking(upstreamBranch: string): Promise { const result = await this.run(['for-each-ref', '--format', '%(if)%(upstream:short)%(then)%(refname:short)->%(upstream:short) %(else)* %(end)', 'refs/heads']); return result.stdout.trim().split('\n') .map(line => line.trim()) @@ -1383,10 +1383,10 @@ export class Repository { const splited = line.split('->'); return { local: splited[0], - upstarem: splited[1] - } as Trackingship; + upstream: splited[1] + } as TrackingShip; }) - .filter(trackingShip => trackingShip.upstarem === upstreamBranch); + .filter(trackingShip => trackingShip.upstream === upstreamBranch); } async getRefs(): Promise { diff --git a/extensions/git/src/repository.ts b/extensions/git/src/repository.ts index d8dcc69a9a8..cff2a80a899 100644 --- a/extensions/git/src/repository.ts +++ b/extensions/git/src/repository.ts @@ -13,7 +13,7 @@ import * as path from 'path'; import * as nls from 'vscode-nls'; import * as fs from 'fs'; import { StatusBarCommands } from './statusbar'; -import { Branch, Ref, Remote, RefType, GitErrorCodes, Trackingship } from './api/git'; +import { Branch, Ref, Remote, RefType, GitErrorCodes, TrackingShip } from './api/git'; const timeout = (millis: number) => new Promise(c => setTimeout(c, millis)); @@ -881,7 +881,7 @@ export class Repository implements Disposable { await this.run(Operation.CheckoutTracking, () => this.repository.checkout(treeish, [], { track: true })); } - async getTracking(treeish: string): Promise { + async getTracking(treeish: string): Promise { return await this.run(Operation.GetTracking, () => this.repository.GetTracking(treeish)); } From 2e0a8c42dfe618d291e04a948d294a35e9010f03 Mon Sep 17 00:00:00 2001 From: laphets Date: Sat, 20 Oct 2018 11:19:22 +0800 Subject: [PATCH 4/5] Revise some comments --- extensions/git/src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 42178ef825d..f92f6951b8e 100755 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -63,7 +63,7 @@ class CheckoutRemoteHeadItem extends CheckoutItem { //Just checkout the local branch await repository.checkout(trackings[0].local); } else { - // Default + // Default: checkout a new local branch tracking the upstream await repository.checkoutTracking(ref); } } From a9d2bd7370f053b2707645e247f88dc7407512be Mon Sep 17 00:00:00 2001 From: laphets Date: Fri, 9 Nov 2018 00:06:57 +0800 Subject: [PATCH 5/5] Resolve another conflict --- build/tfs/linux/frozen-check.js | 40 --------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 build/tfs/linux/frozen-check.js diff --git a/build/tfs/linux/frozen-check.js b/build/tfs/linux/frozen-check.js deleted file mode 100644 index 281632424b7..00000000000 --- a/build/tfs/linux/frozen-check.js +++ /dev/null @@ -1,40 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -'use strict'; -Object.defineProperty(exports, "__esModule", { value: true }); -const documentdb_1 = require("documentdb"); -function createDefaultConfig(quality) { - return { - id: quality, - frozen: false - }; -} -function getConfig(quality) { - const client = new documentdb_1.DocumentClient(process.env['AZURE_DOCUMENTDB_ENDPOINT'], { masterKey: process.env['AZURE_DOCUMENTDB_MASTERKEY'] }); - const collection = 'dbs/builds/colls/config'; - const query = { - query: `SELECT TOP 1 * FROM c WHERE c.id = @quality`, - parameters: [ - { name: '@quality', value: quality } - ] - }; - return new Promise((c, e) => { - client.queryDocuments(collection, query).toArray((err, results) => { - if (err && err.code !== 409) { - return e(err); - } - c(!results || results.length === 0 ? createDefaultConfig(quality) : results[0]); - }); - }); -} -getConfig(process.argv[2]) - .then(config => { - console.log(config.frozen); - process.exit(0); -}) - .catch(err => { - console.error(err); - process.exit(1); -});