Skip to content

Commit

Permalink
#292 Create a *.tar or *.zip archive of the repository at any branch …
Browse files Browse the repository at this point in the history
…or tag from the corresponding context menu.
  • Loading branch information
mhutchie committed Apr 19, 2020
1 parent c5d7f56 commit 10ab1ad
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 4 deletions.
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
"type": "boolean",
"title": "Create Pull Request..."
},
"createArchive": {
"type": "boolean",
"title": "Create Archive"
},
"copyName": {
"type": "boolean",
"title": "Copy Branch Name to Clipboard"
Expand Down Expand Up @@ -236,6 +240,10 @@
"type": "boolean",
"title": "Create Pull Request"
},
"createArchive": {
"type": "boolean",
"title": "Create Archive"
},
"copyName": {
"type": "boolean",
"title": "Copy Branch Name to Clipboard"
Expand Down Expand Up @@ -286,6 +294,10 @@
"type": "boolean",
"title": "Push Tag..."
},
"createArchive": {
"type": "boolean",
"title": "Create Archive"
},
"copyName": {
"type": "boolean",
"title": "Copy Tag Name to Clipboard"
Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ class Config {
get contextMenuActionsVisibility(): ContextMenuActionsVisibility {
let userConfig = this.config.get('contextMenuActionsVisibility', {});
let config = {
branch: { checkout: true, rename: true, delete: true, merge: true, rebase: true, push: true, createPullRequest: true, copyName: true },
branch: { checkout: true, rename: true, delete: true, merge: true, rebase: true, push: true, createPullRequest: true, createArchive: true, copyName: true },
commit: { addTag: true, createBranch: true, checkout: true, cherrypick: true, revert: true, drop: true, merge: true, rebase: true, reset: true, copyHash: true, copySubject: true },
remoteBranch: { checkout: true, delete: true, fetch: true, pull: true, createPullRequest: true, copyName: true },
remoteBranch: { checkout: true, delete: true, fetch: true, pull: true, createPullRequest: true, createArchive: true, copyName: true },
stash: { apply: true, createBranch: true, pop: true, drop: true, copyName: true, copyHash: true },
tag: { viewDetails: true, delete: true, push: true, copyName: true },
tag: { viewDetails: true, delete: true, push: true, createArchive: true, copyName: true },
uncommittedChanges: { stash: true, reset: true, clean: true, openSourceControlView: true }
};
mergeConfigObjects(config, userConfig);
Expand Down
15 changes: 15 additions & 0 deletions src/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,21 @@ export class DataSource implements vscode.Disposable {
}


/* Git Action Methods - Branches & Tags */

/**
* Create an archive of a repository at a specific reference, and save to disk.
* @param repo The path of the repository.
* @param ref The reference of the revision to archive.
* @param outputFilePath The file path that the archive should be saved to.
* @param type The type of archive.
* @returns The ErrorInfo from the executed command.
*/
public archive(repo: string, ref: string, outputFilePath: string, type: 'tar' | 'zip') {
return this.runGitCommand(['archive', '--format=' + type, '-o', outputFilePath, ref], repo);
}


/* Git Action Methods - Commits */

/**
Expand Down
8 changes: 7 additions & 1 deletion src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Logger } from './logger';
import { RepoFileWatcher } from './repoFileWatcher';
import { RepoManager } from './repoManager';
import { ErrorInfo, GitConfigLocation, GitGraphViewInitialState, GitPushBranchMode, GitRepoSet, LoadGitGraphViewTo, RefLabelAlignment, RequestMessage, ResponseMessage, TabIconColourTheme } from './types';
import { copyFilePathToClipboard, copyToClipboard, createPullRequest, getNonce, openExtensionSettings, openFile, showErrorMessage, UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED, viewDiff, viewFileAtRevision, viewScm } from './utils';
import { archive, copyFilePathToClipboard, copyToClipboard, createPullRequest, getNonce, openExtensionSettings, openFile, showErrorMessage, UNABLE_TO_FIND_GIT_MSG, UNCOMMITTED, viewDiff, viewFileAtRevision, viewScm } from './utils';

/**
* Manages the Git Graph View.
Expand Down Expand Up @@ -240,6 +240,12 @@ export class GitGraphView implements vscode.Disposable {
error: await copyToClipboard(msg.data)
});
break;
case 'createArchive':
this.sendMessage({
command: 'createArchive',
error: await archive(msg.repo, msg.ref, this.dataSource)
});
break;
case 'createBranch':
this.sendMessage({
command: 'createBranch',
Expand Down
13 changes: 13 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export interface ContextMenuActionsVisibility {
readonly rebase: boolean;
readonly push: boolean;
readonly createPullRequest: boolean;
readonly createArchive: boolean;
readonly copyName: boolean;
};
readonly commit: {
Expand All @@ -291,6 +292,7 @@ export interface ContextMenuActionsVisibility {
readonly fetch: boolean;
readonly pull: boolean;
readonly createPullRequest: boolean;
readonly createArchive: boolean;
readonly copyName: boolean;
};
readonly stash: {
Expand All @@ -305,6 +307,7 @@ export interface ContextMenuActionsVisibility {
readonly viewDetails: boolean;
readonly delete: boolean;
readonly push: boolean;
readonly createArchive: boolean;
readonly copyName: boolean;
};
readonly uncommittedChanges: {
Expand Down Expand Up @@ -595,6 +598,14 @@ export interface ResponseCopyToClipboard extends ResponseWithErrorInfo {
readonly type: string;
}

export interface RequestCreateArchive extends RepoRequest {
readonly command: 'createArchive';
readonly ref: string;
}
export interface ResponseCreateArchive extends ResponseWithErrorInfo {
readonly command: 'createArchive';
}

export interface RequestCreateBranch extends RepoRequest {
readonly command: 'createBranch';
readonly commitHash: string;
Expand Down Expand Up @@ -1023,6 +1034,7 @@ export type RequestMessage =
| RequestCompareCommits
| RequestCopyFilePath
| RequestCopyToClipboard
| RequestCreateArchive
| RequestCreateBranch
| RequestCreatePullRequest
| RequestDeleteBranch
Expand Down Expand Up @@ -1078,6 +1090,7 @@ export type ResponseMessage =
| ResponseCommitDetails
| ResponseCopyFilePath
| ResponseCopyToClipboard
| ResponseCreateArchive
| ResponseCreateBranch
| ResponseCreatePullRequest
| ResponseDeleteBranch
Expand Down
31 changes: 31 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { getConfig } from './config';
import { DataSource } from './dataSource';
import { DiffSide, encodeDiffDocUri } from './diffDocProvider';
import { ExtensionState } from './extensionState';
import { ErrorInfo, GitFileStatus, PullRequestConfig, PullRequestProvider } from './types';
Expand Down Expand Up @@ -188,6 +189,36 @@ export function getRepoName(path: string) {

/* Visual Studio Code Command Wrappers */

/**
* Create an archive of a repository at a specific reference, and save to disk.
* @param repo The path of the repository.
* @param ref The reference of the revision to archive.
* @param dataSource The DataSource instance that can be used to create the archive.
* @returns The ErrorInfo from the executed command.
*/
export function archive(repo: string, ref: string, dataSource: DataSource): Thenable<ErrorInfo> {
return vscode.window.showSaveDialog({
defaultUri: vscode.Uri.file(repo),
saveLabel: 'Create Archive',
filters: { 'TAR Archive': ['tar'], 'ZIP Archive': ['zip'] }
}).then(
(uri) => {
if (uri) {
const extension = uri.fsPath.substring(uri.fsPath.lastIndexOf('.') + 1).toLowerCase();
if (extension === 'tar' || extension === 'zip') {
return dataSource.archive(repo, ref, uri.fsPath, extension);
} else {
return 'Invalid file extension "*.' + extension + '". The archive file must have a *.tar or *.zip extension.';
}
} else {
return 'No file name was provided for the archive.';
}
},
() => 'Visual Studio Code was unable to display the save dialog.'
);
}


/**
* Copy the path of a file in a repository to the clipboard.
* @param repo The repository the file is contained in.
Expand Down
24 changes: 24 additions & 0 deletions web/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,13 @@ class GitGraphView {
}
}
], [
{
title: 'Create Archive',
visible: visibility.createArchive,
onClick: () => {
runAction({ command: 'createArchive', repo: this.currentRepo, ref: refName }, 'Creating Archive');
}
},
{
title: 'Copy Branch Name to Clipboard',
visible: visibility.copyName,
Expand Down Expand Up @@ -1219,6 +1226,13 @@ class GitGraphView {
}
}
], [
{
title: 'Create Archive',
visible: visibility.createArchive,
onClick: () => {
runAction({ command: 'createArchive', repo: this.currentRepo, ref: refName }, 'Creating Archive');
}
},
{
title: 'Copy Branch Name to Clipboard',
visible: visibility.copyName,
Expand Down Expand Up @@ -1340,6 +1354,13 @@ class GitGraphView {
}
}
], [
{
title: 'Create Archive',
visible: visibility.createArchive,
onClick: () => {
runAction({ command: 'createArchive', repo: this.currentRepo, ref: tagName }, 'Creating Archive');
}
},
{
title: 'Copy Tag Name to Clipboard',
visible: visibility.copyName,
Expand Down Expand Up @@ -2626,6 +2647,9 @@ window.addEventListener('load', () => {
case 'copyToClipboard':
finishOrDisplayError(msg.error, 'Unable to Copy ' + msg.type + ' to Clipboard');
break;
case 'createArchive':
finishOrDisplayError(msg.error, 'Unable to Create Archive', true);
break;
case 'createBranch':
refreshOrDisplayError(msg.error, 'Unable to Create Branch');
break;
Expand Down

0 comments on commit 10ab1ad

Please sign in to comment.