Skip to content

Commit 8bcf177

Browse files
author
Eric Amodio
committed
Fixes issues with create/copy/rename/delete
1 parent 6a6876b commit 8bcf177

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

extensions/github-browser/src/changeStore.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77
import { commands, Event, EventEmitter, FileStat, FileType, Memento, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode';
8-
import { getRootUri, getRelativePath } from './extension';
8+
import { getRootUri, getRelativePath, isChild } from './extension';
99
import { sha1 } from './sha1';
1010

1111
const textDecoder = new TextDecoder();
@@ -191,21 +191,29 @@ export class ChangeStore implements IChangeStore, IWritableChangeStore {
191191
return entries;
192192
}
193193

194+
const folderPath = getRelativePath(rootUri, uri);
195+
194196
const operations = this.getChanges(rootUri);
195197
for (const operation of operations) {
196198
switch (operation.type) {
197199
case 'changed':
198200
continue;
201+
199202
case 'created': {
200-
const file = getRelativePath(rootUri, operation.uri);
201-
entries.push([file, FileType.File]);
203+
const filePath = getRelativePath(rootUri, operation.uri);
204+
if (isChild(folderPath, filePath)) {
205+
entries.push([filePath, FileType.File]);
206+
}
202207
break;
203208
}
209+
204210
case 'deleted': {
205-
const file = getRelativePath(rootUri, operation.uri);
206-
const index = entries.findIndex(([path]) => path === file);
207-
if (index !== -1) {
208-
entries.splice(index, 1);
211+
const filePath = getRelativePath(rootUri, operation.uri);
212+
if (isChild(folderPath, filePath)) {
213+
const index = entries.findIndex(([path]) => path === filePath);
214+
if (index !== -1) {
215+
entries.splice(index, 1);
216+
}
209217
}
210218
break;
211219
}

extensions/github-browser/src/extension.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,21 @@ export function activate(context: ExtensionContext) {
4848
}
4949

5050
export function getRelativePath(rootUri: Uri, uri: Uri) {
51-
return uri.fsPath.substr(rootUri.fsPath.length + 1);
51+
return uri.path.substr(rootUri.path.length + 1);
5252
}
5353

5454
export function getRootUri(uri: Uri) {
5555
return workspace.getWorkspaceFolder(uri)?.uri;
5656
}
5757

58+
export function isChild(folderPath: string, filePath: string) {
59+
return isDescendent(folderPath, filePath) && filePath.substr(folderPath.length + (folderPath.endsWith('/') ? 0 : 1)).split('/').length === 1;
60+
}
61+
62+
export function isDescendent(folderPath: string, filePath: string) {
63+
return folderPath.length === 0 || filePath.startsWith(folderPath.endsWith('/') ? folderPath : `${folderPath}/`);
64+
}
65+
5866
// function openWorkspace(uri: Uri, name: string, location: 'currentWindow' | 'newWindow' | 'addToCurrentWorkspace') {
5967
// if (location === 'addToCurrentWorkspace') {
6068
// const count = (workspace.workspaceFolders && workspace.workspaceFolders.length) || 0;

extensions/github-browser/src/github/api.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,21 @@ export class GitHubApi implements Disposable {
152152
updatedTree.push({ path: operation.path, mode: '100644', type: 'blob', content: operation.content });
153153
break;
154154

155-
case 'changed':
156-
const item = updatedTree.find(item => item.path === operation.path);
157-
if (item !== undefined) {
158-
updatedTree.push({ ...item, content: operation.content });
155+
case 'changed': {
156+
const index = updatedTree.findIndex(item => item.path === operation.path);
157+
if (index !== -1) {
158+
const { path, mode, type } = updatedTree[index];
159+
updatedTree.splice(index, 1, { path: path, mode: mode, type: type, content: operation.content });
159160
}
160161
break;
161-
162-
case 'deleted':
162+
}
163+
case 'deleted': {
163164
const index = updatedTree.findIndex(item => item.path === operation.path);
164165
if (index !== -1) {
165166
updatedTree.splice(index, 1);
166167
}
167168
break;
169+
}
168170
}
169171
}
170172
} else {
@@ -179,7 +181,8 @@ export class GitHubApi implements Disposable {
179181
case 'changed':
180182
const item = treeResp.data.tree.find(item => item.path === operation.path) as GitCreateTreeParamsTree;
181183
if (item !== undefined) {
182-
updatedTree.push({ ...item, content: operation.content });
184+
const { path, mode, type } = item;
185+
updatedTree.push({ path: path, mode: mode, type: type, content: operation.content });
183186
}
184187
break;
185188
}

0 commit comments

Comments
 (0)