From b32dd7f53d1c0ecdc3f1ef2746746692055ed2c9 Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Mon, 7 Mar 2022 08:15:24 -0500 Subject: [PATCH 01/10] added another input --- src/widgets/CredentialsBox.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index e20d4b337..cc08f65d9 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -25,6 +25,7 @@ export class GitCredentialsForm const label = document.createElement('label'); this._user = document.createElement('input'); this._password = document.createElement('input'); + this.cacheCredentials = document.createElement('input'); this._password.type = 'password'; const text = document.createElement('span'); @@ -35,13 +36,16 @@ export class GitCredentialsForm text.textContent = textContent; warning.textContent = warningContent; this._user.placeholder = this._trans.__('username'); + this.cacheCredentials.placeholder = this._trans.__('Cache credentials?'); this._password.placeholder = this._trans.__( 'password / personal access token' + ); label.appendChild(text); label.appendChild(this._user); label.appendChild(this._password); + label.appendChild(this._cacheCredentials); node.appendChild(label); node.appendChild(warning); return node; From c6e1e8a418e465ae5d6bbb8600ba4c6989a9cec4 Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:14:11 -0500 Subject: [PATCH 02/10] made changes to button --- src/commandsAndMenu.tsx | 5 ++++- src/widgets/CredentialsBox.tsx | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index 8c588be17..e2a0e7ac3 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -1407,7 +1407,10 @@ export async function showGitOperationDialog( trans, trans.__('Enter credentials for remote repository'), retry ? trans.__('Incorrect username or password.') : '' - ) + ), + buttons: [ + Dialog.cacheCredentials({label: trans.__('Cache Credentials?')}) + ] }); if (credentials.button.accept) { diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index cc08f65d9..2a3cdad2c 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -59,8 +59,10 @@ export class GitCredentialsForm username: this._user.value, password: this._password.value }; + return this._cacheCredentials; } protected _trans: TranslationBundle; private _user: HTMLInputElement; private _password: HTMLInputElement; + private _cacheCredentials: HTMLInputElement; } From b1def89daee0e7b26496dadb4b7bdd463e04c149 Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Fri, 11 Mar 2022 10:40:32 -0500 Subject: [PATCH 03/10] changed message --- src/commandsAndMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index 8c588be17..9b98a4c5e 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -1405,7 +1405,7 @@ export async function showGitOperationDialog( title: trans.__('Git credentials required'), body: new GitCredentialsForm( trans, - trans.__('Enter credentials for remote repository'), + trans.__('Hello my name is Zeshan'), retry ? trans.__('Incorrect username or password.') : '' ) }); From 28a876bc11915ffd9c2c13a83d9e2eb4b3753e68 Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:12:12 -0500 Subject: [PATCH 04/10] added button --- src/widgets/CredentialsBox.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index 2a3cdad2c..b145a03dc 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -25,7 +25,7 @@ export class GitCredentialsForm const label = document.createElement('label'); this._user = document.createElement('input'); this._password = document.createElement('input'); - this.cacheCredentials = document.createElement('input'); + //this.cacheCredentials = document.createElement('input'); this._password.type = 'password'; const text = document.createElement('span'); @@ -36,7 +36,7 @@ export class GitCredentialsForm text.textContent = textContent; warning.textContent = warningContent; this._user.placeholder = this._trans.__('username'); - this.cacheCredentials.placeholder = this._trans.__('Cache credentials?'); + //this.cacheCredentials.placeholder = this._trans.__('Cache credentials?'); this._password.placeholder = this._trans.__( 'password / personal access token' @@ -45,7 +45,7 @@ export class GitCredentialsForm label.appendChild(text); label.appendChild(this._user); label.appendChild(this._password); - label.appendChild(this._cacheCredentials); + //label.appendChild(this._cacheCredentials); node.appendChild(label); node.appendChild(warning); return node; @@ -59,10 +59,10 @@ export class GitCredentialsForm username: this._user.value, password: this._password.value }; - return this._cacheCredentials; + //return this._cacheCredentials; } protected _trans: TranslationBundle; private _user: HTMLInputElement; private _password: HTMLInputElement; - private _cacheCredentials: HTMLInputElement; + //private _cacheCredentials: HTMLInputElement; } From da4b0e13e665819237f0f2566a3f5f2bce105f80 Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:46:55 -0500 Subject: [PATCH 05/10] changed button --- src/commandsAndMenu.tsx | 10 +++++----- src/widgets/CredentialsBox.tsx | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index 633d3c59c..854972cbb 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -1405,12 +1405,12 @@ export async function showGitOperationDialog( title: trans.__('Git credentials required'), body: new GitCredentialsForm( trans, - trans.__('Hello my name is Zeshan'), + trans.__('March 11th 11:45AM'), retry ? trans.__('Incorrect username or password.') : '' - ), - buttons: [ - Dialog.cacheCredentials({label: trans.__('Cache Credentials?')}) - ] + )//, + //buttons: [ + // Dialog.cacheCredentials({label: trans.__('Cache Credentials?')}) + //] }); if (credentials.button.accept) { diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index b145a03dc..2a3cdad2c 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -25,7 +25,7 @@ export class GitCredentialsForm const label = document.createElement('label'); this._user = document.createElement('input'); this._password = document.createElement('input'); - //this.cacheCredentials = document.createElement('input'); + this.cacheCredentials = document.createElement('input'); this._password.type = 'password'; const text = document.createElement('span'); @@ -36,7 +36,7 @@ export class GitCredentialsForm text.textContent = textContent; warning.textContent = warningContent; this._user.placeholder = this._trans.__('username'); - //this.cacheCredentials.placeholder = this._trans.__('Cache credentials?'); + this.cacheCredentials.placeholder = this._trans.__('Cache credentials?'); this._password.placeholder = this._trans.__( 'password / personal access token' @@ -45,7 +45,7 @@ export class GitCredentialsForm label.appendChild(text); label.appendChild(this._user); label.appendChild(this._password); - //label.appendChild(this._cacheCredentials); + label.appendChild(this._cacheCredentials); node.appendChild(label); node.appendChild(warning); return node; @@ -59,10 +59,10 @@ export class GitCredentialsForm username: this._user.value, password: this._password.value }; - //return this._cacheCredentials; + return this._cacheCredentials; } protected _trans: TranslationBundle; private _user: HTMLInputElement; private _password: HTMLInputElement; - //private _cacheCredentials: HTMLInputElement; + private _cacheCredentials: HTMLInputElement; } From 4b74db79682c04d494e2a538b2a1d654dc21d2a1 Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:57:32 -0500 Subject: [PATCH 06/10] added _ --- src/widgets/CredentialsBox.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index 2a3cdad2c..2bedc9c1f 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -25,7 +25,7 @@ export class GitCredentialsForm const label = document.createElement('label'); this._user = document.createElement('input'); this._password = document.createElement('input'); - this.cacheCredentials = document.createElement('input'); + this._cacheCredentials = document.createElement('input'); this._password.type = 'password'; const text = document.createElement('span'); From 772be46f0eabfc1904c1f68e97e88b00469791f3 Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Fri, 11 Mar 2022 12:03:09 -0500 Subject: [PATCH 07/10] added _ --- src/widgets/CredentialsBox.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index 2bedc9c1f..f2c2b8c3f 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -36,7 +36,7 @@ export class GitCredentialsForm text.textContent = textContent; warning.textContent = warningContent; this._user.placeholder = this._trans.__('username'); - this.cacheCredentials.placeholder = this._trans.__('Cache credentials?'); + this._cacheCredentials.placeholder = this._trans.__('Cache credentials?'); this._password.placeholder = this._trans.__( 'password / personal access token' From a7a1b5f9e47ef19648812e1782812671f39146db Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Fri, 11 Mar 2022 12:20:58 -0500 Subject: [PATCH 08/10] removed return --- src/widgets/CredentialsBox.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index f2c2b8c3f..b395ea5fa 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -59,7 +59,7 @@ export class GitCredentialsForm username: this._user.value, password: this._password.value }; - return this._cacheCredentials; + // return this._cacheCredentials; } protected _trans: TranslationBundle; private _user: HTMLInputElement; From 4bc928f012f2f8e041a5629a8c3b07f04c10165d Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Tue, 15 Mar 2022 21:14:02 -0400 Subject: [PATCH 09/10] added button --- src/commandsAndMenu.tsx | 6 ++++-- src/model.ts | 23 +++++++++++++++++++---- src/widgets/CredentialsBox.tsx | 14 ++++++++++---- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index 854972cbb..0642949a3 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -1368,7 +1368,8 @@ export async function showGitOperationDialog( trans: TranslationBundle, args?: T, authentication?: Git.IAuth, - retry = false + retry = false, + cache = false ): Promise { try { let result: Git.IResultWithMessage; @@ -1405,7 +1406,7 @@ export async function showGitOperationDialog( title: trans.__('Git credentials required'), body: new GitCredentialsForm( trans, - trans.__('March 11th 11:45AM'), + trans.__('Enter credentials for remote repository'), retry ? trans.__('Incorrect username or password.') : '' )//, //buttons: [ @@ -1421,6 +1422,7 @@ export async function showGitOperationDialog( trans, args, credentials.value, + true, true ); } diff --git a/src/model.ts b/src/model.ts index 80543b844..0eba82227 100644 --- a/src/model.ts +++ b/src/model.ts @@ -577,7 +577,7 @@ export class GitExtension implements IGitExtension { async clone( path: string, url: string, - auth?: Git.IAuth + auth?: Git.IAuth, cacheCredentials = true ): Promise { return await this._taskHandler.execute( 'git:clone', @@ -822,7 +822,7 @@ export class GitExtension implements IGitExtension { * @throws {Git.GitResponseError} If the server response is not ok * @throws {ServerConnection.NetworkError} If the request cannot be made */ - async pull(auth?: Git.IAuth): Promise { + async pull(auth?: Git.IAuth, cacheCredentials = true): Promise { const path = await this._getPathRepository(); const data = this._taskHandler.execute( 'git:pull', @@ -855,7 +855,7 @@ export class GitExtension implements IGitExtension { * @throws {Git.GitResponseError} If the server response is not ok * @throws {ServerConnection.NetworkError} If the request cannot be made */ - async push(auth?: Git.IAuth, force = false): Promise { + async push(auth?: Git.IAuth, cacheCredentials = true, force = false): Promise { const path = await this._getPathRepository(); const data = this._taskHandler.execute( 'git:push', @@ -1494,7 +1494,22 @@ export class GitExtension implements IGitExtension { private _fetchRemotes = async (): Promise => { try { const path = await this._getPathRepository(); - await requestAPI(URLExt.join(path, 'remote', 'fetch'), 'POST'); + + const credentials = await showDialog({ + title: trans.__('Git credentials required'), + body: new GitCredentialsForm( + trans, + trans.__('Enter credentials for remote repository'), + retry ? trans.__('Incorrect username or password.') : '' + )//, + //buttons: [ + // Dialog.cacheCredentials({label: trans.__('Cache Credentials?')}) + //] + }); + + await requestAPI(URLExt.join(path, 'remote', 'fetch'), 'POST', { + auth?: Git.IAuth, cacheCredentials = true + }); } catch (error) { console.error('Failed to fetch remotes', error); } diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index b395ea5fa..02d112054 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -23,11 +23,14 @@ export class GitCredentialsForm private createBody(textContent: string, warningContent: string): HTMLElement { const node = document.createElement('div'); const label = document.createElement('label'); + const checkBoxLabel = document.createElement('label'); + const checkBox = document.createElement('input'); this._user = document.createElement('input'); this._password = document.createElement('input'); - this._cacheCredentials = document.createElement('input'); + //this._cacheCredentials = document.createElement('input'); this._password.type = 'password'; + const text = document.createElement('span'); const warning = document.createElement('div'); @@ -36,7 +39,8 @@ export class GitCredentialsForm text.textContent = textContent; warning.textContent = warningContent; this._user.placeholder = this._trans.__('username'); - this._cacheCredentials.placeholder = this._trans.__('Cache credentials?'); + checkBox.type = 'checkbox'; + //this._cacheCredentials.placeholder = this._trans.__('Cache credentials?'); this._password.placeholder = this._trans.__( 'password / personal access token' @@ -45,7 +49,9 @@ export class GitCredentialsForm label.appendChild(text); label.appendChild(this._user); label.appendChild(this._password); - label.appendChild(this._cacheCredentials); + checkBoxLabel.appendChild(checkbox); + node.appendChild(checkBoxLabel); + //label.appendChild(this._cacheCredentials); node.appendChild(label); node.appendChild(warning); return node; @@ -64,5 +70,5 @@ export class GitCredentialsForm protected _trans: TranslationBundle; private _user: HTMLInputElement; private _password: HTMLInputElement; - private _cacheCredentials: HTMLInputElement; + //private _cacheCredentials: HTMLInputElement; } From 75a06cab2173ecfc358e2bb7a0ce8d04d6e54f9a Mon Sep 17 00:00:00 2001 From: Zeshan Fayyaz <43391249+ZeshanFayyaz@users.noreply.github.com> Date: Thu, 17 Mar 2022 00:23:16 -0400 Subject: [PATCH 10/10] Cache Credentials for Clone and Methodology for Push / Pull --- src/commandsAndMenu.tsx | 17 ++++++++++++----- src/model.ts | 15 +++++++++------ src/tokens.ts | 7 +++++++ src/widgets/CredentialsBox.tsx | 13 ++++++++----- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/commandsAndMenu.tsx b/src/commandsAndMenu.tsx index 0642949a3..63362154e 100644 --- a/src/commandsAndMenu.tsx +++ b/src/commandsAndMenu.tsx @@ -1367,27 +1367,35 @@ export async function showGitOperationDialog( operation: Operation, trans: TranslationBundle, args?: T, - authentication?: Git.IAuth, + authentication?: Git.IAuthWithCacheCredentials, retry = false, cache = false ): Promise { try { + const auth = authentication ? { + username: authentication.username, + password: authentication.password + } as Git.IAuth : undefined; let result: Git.IResultWithMessage; // the Git action switch (operation) { case Operation.Clone: // eslint-disable-next-line no-case-declarations const { path, url } = args as any as IGitCloneArgs; - result = await model.clone(path, url, authentication); + result = await model.clone(path, + url, + auth, + authentication ? authentication.cacheCredentials : false + ); break; case Operation.Pull: result = await model.pull(authentication); break; case Operation.Push: - result = await model.push(authentication); + result = await model.push(authentication, false, authentication.cacheCredentials); break; case Operation.ForcePush: - result = await model.push(authentication, true); + result = await model.push(authentication, true, authentication.cacheCredentials); break; default: result = { code: -1, message: 'Unknown git command' }; @@ -1422,7 +1430,6 @@ export async function showGitOperationDialog( trans, args, credentials.value, - true, true ); } diff --git a/src/model.ts b/src/model.ts index 0eba82227..38afa6e47 100644 --- a/src/model.ts +++ b/src/model.ts @@ -577,7 +577,8 @@ export class GitExtension implements IGitExtension { async clone( path: string, url: string, - auth?: Git.IAuth, cacheCredentials = true + auth?: Git.IAuth, + cacheCredentials = false ): Promise { return await this._taskHandler.execute( 'git:clone', @@ -587,7 +588,8 @@ export class GitExtension implements IGitExtension { 'POST', { clone_url: url, - auth: auth as any + auth: auth as any, + cache_credentials: cacheCredentials } ); } @@ -822,7 +824,7 @@ export class GitExtension implements IGitExtension { * @throws {Git.GitResponseError} If the server response is not ok * @throws {ServerConnection.NetworkError} If the request cannot be made */ - async pull(auth?: Git.IAuth, cacheCredentials = true): Promise { + async pull(auth?: Git.IAuth, cache_credentials: true): Promise { const path = await this._getPathRepository(); const data = this._taskHandler.execute( 'git:pull', @@ -855,7 +857,7 @@ export class GitExtension implements IGitExtension { * @throws {Git.GitResponseError} If the server response is not ok * @throws {ServerConnection.NetworkError} If the request cannot be made */ - async push(auth?: Git.IAuth, cacheCredentials = true, force = false): Promise { + async push(auth?: Git.IAuth, cache_credentials: true, force = false, cacheCredentials = false): Promise { const path = await this._getPathRepository(); const data = this._taskHandler.execute( 'git:push', @@ -865,7 +867,8 @@ export class GitExtension implements IGitExtension { 'POST', { auth: auth as any, - force: force + force: force, + cache_credentials: cacheCredentials } ); } @@ -1508,7 +1511,7 @@ export class GitExtension implements IGitExtension { }); await requestAPI(URLExt.join(path, 'remote', 'fetch'), 'POST', { - auth?: Git.IAuth, cacheCredentials = true + auth?: Git.IAuth, cache_credentials: true }); } catch (error) { console.error('Failed to fetch remotes', error); diff --git a/src/tokens.ts b/src/tokens.ts index f682749ac..80a124cc3 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -926,6 +926,13 @@ export namespace Git { password: string; } + /** + * Interface for the Git Auth request with credentials caching option + */ + export interface IAuthWithCacheCredentials extends IAuth { + cacheCredentials: boolean; + } + /** * Structure for the request to the Git Clone API. */ diff --git a/src/widgets/CredentialsBox.tsx b/src/widgets/CredentialsBox.tsx index 02d112054..021e60431 100755 --- a/src/widgets/CredentialsBox.tsx +++ b/src/widgets/CredentialsBox.tsx @@ -24,7 +24,7 @@ export class GitCredentialsForm const node = document.createElement('div'); const label = document.createElement('label'); const checkBoxLabel = document.createElement('label'); - const checkBox = document.createElement('input'); + this._checkboxCacheCredentials = document.createElement('input'); this._user = document.createElement('input'); this._password = document.createElement('input'); //this._cacheCredentials = document.createElement('input'); @@ -39,7 +39,8 @@ export class GitCredentialsForm text.textContent = textContent; warning.textContent = warningContent; this._user.placeholder = this._trans.__('username'); - checkBox.type = 'checkbox'; + this._checkboxCacheCredentials.type = 'checkbox'; + this._checkboxCacheCredentials.textContent = this._trans.__("Save my login temporarily"); //this._cacheCredentials.placeholder = this._trans.__('Cache credentials?'); this._password.placeholder = this._trans.__( 'password / personal access token' @@ -49,7 +50,7 @@ export class GitCredentialsForm label.appendChild(text); label.appendChild(this._user); label.appendChild(this._password); - checkBoxLabel.appendChild(checkbox); + checkBoxLabel.appendChild(this._checkboxCacheCredentials); node.appendChild(checkBoxLabel); //label.appendChild(this._cacheCredentials); node.appendChild(label); @@ -60,15 +61,17 @@ export class GitCredentialsForm /** * Returns the input value. */ - getValue(): Git.IAuth { + getValue(): Git.IAuthWithCacheCredentials { return { username: this._user.value, - password: this._password.value + password: this._password.value, + cacheCredentials: this._checkboxCacheCredentials.checked }; // return this._cacheCredentials; } protected _trans: TranslationBundle; private _user: HTMLInputElement; private _password: HTMLInputElement; + private _checkboxCacheCredentials: HTMLInputElement; //private _cacheCredentials: HTMLInputElement; }