mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds git ignoring commands
This commit is contained in:
parent
7968df1eb4
commit
3257d9162f
@ -1,5 +1,8 @@
|
||||
# Change Log
|
||||
|
||||
### 0.1.0
|
||||
- Git ignoring
|
||||
|
||||
### 0.0.12
|
||||
- Fixup commits (@zachdaniel Zach Daniel)
|
||||
- Allow freeform input in more menus
|
||||
|
18
package.json
18
package.json
@ -118,6 +118,10 @@
|
||||
"command": "magit.tagging",
|
||||
"title": "Magit Tagging"
|
||||
},
|
||||
{
|
||||
"command": "magit.ignoring",
|
||||
"title": "Magit Ignore"
|
||||
},
|
||||
{
|
||||
"command": "magit.worktree",
|
||||
"title": "Magit Worktree"
|
||||
@ -197,6 +201,10 @@
|
||||
"command": "magit.tagging",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.ignoring",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.worktree",
|
||||
"when": "editorLangId == magit"
|
||||
@ -383,6 +391,16 @@
|
||||
"key": "t",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.ignoring",
|
||||
"key": "i",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.ignoring",
|
||||
"key": "shift+i",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.worktree",
|
||||
"key": "shift+5",
|
||||
|
59
src/commands/ignoringCommands.ts
Normal file
59
src/commands/ignoringCommands.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { MenuUtil, MenuState } from '../menu/menu';
|
||||
import { QuickMenuUtil, QuickItem } from '../menu/quickMenu';
|
||||
import FilePathUtils from '../utils/filePathUtils';
|
||||
import * as fs from 'fs';
|
||||
import { window } from 'vscode';
|
||||
|
||||
const ignoringMenu = {
|
||||
title: 'Ignoring',
|
||||
commands: [
|
||||
{ label: 'l', description: 'Ignore locally', action: ({ repository }: MenuState) => ignore(repository) },
|
||||
{ label: 'g', description: 'Ignore globally (add to .gitignore)', action: ({ repository }: MenuState) => ignore(repository, true) }
|
||||
]
|
||||
};
|
||||
|
||||
export async function ignoring(repository: MagitRepository) {
|
||||
return MenuUtil.showMenu(ignoringMenu, { repository });
|
||||
}
|
||||
|
||||
async function ignore(repository: MagitRepository, globally = false) {
|
||||
|
||||
const ignoreSuggestions: QuickItem<string>[] = [];
|
||||
|
||||
repository.magitState?.untrackedFiles.forEach(change => {
|
||||
const fileName = FilePathUtils.fileName(change.originalUri);
|
||||
const fileExtension = FilePathUtils.fileExtension(fileName);
|
||||
|
||||
const globPattern1 = `/*.${fileExtension}`;
|
||||
const globPattern2 = `*.${fileExtension}`;
|
||||
|
||||
ignoreSuggestions.push({ label: fileName, meta: fileName });
|
||||
ignoreSuggestions.push({ label: globPattern1, meta: globPattern1 });
|
||||
ignoreSuggestions.push({ label: globPattern2, meta: globPattern2 });
|
||||
}) ?? [];
|
||||
|
||||
const ignorePattern = await QuickMenuUtil.showMenuWithFreeform(ignoreSuggestions, `File or pattern to ignore ${globally ? 'globally' : 'locally'}`);
|
||||
|
||||
if (ignorePattern) {
|
||||
|
||||
let gitIgnoreFilePath: string;
|
||||
|
||||
if (globally) {
|
||||
gitIgnoreFilePath = repository.rootUri.fsPath + '/.gitignore';
|
||||
} else {
|
||||
gitIgnoreFilePath = repository.rootUri.fsPath + '/.git/info/exclude';
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.appendFile(gitIgnoreFilePath, ignorePattern, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
window.setStatusBarMessage(`Wrote file ${gitIgnoreFilePath}`, 10000);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ import { resetting, resetMixed, resetHard } from './commands/resettingCommands';
|
||||
import { tagging } from './commands/taggingCommands';
|
||||
import { worktree } from './commands/worktreeCommands';
|
||||
import { diffing } from './commands/diffingCommands';
|
||||
import { ignoring } from './commands/ignoringCommands';
|
||||
|
||||
export const magitRepositories: Map<string, MagitRepository> = new Map<string, MagitRepository>();
|
||||
export const views: Map<string, DocumentView> = new Map<string, DocumentView>();
|
||||
@ -90,6 +91,7 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.show-refs', Command.primeRepo(showRefs)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.diffing', Command.primeRepo(diffing)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.tagging', Command.primeRepo(tagging)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.ignoring', Command.primeRepo(ignoring)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.worktree', Command.primeRepo(worktree)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.process-log', Command.primeRepo(processView, false)));
|
||||
|
||||
|
@ -37,4 +37,12 @@ export default class FilePathUtils {
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
public static fileExtension(fileName: string) {
|
||||
const pieces = fileName.split('.');
|
||||
if (pieces.length > 0) {
|
||||
return pieces[pieces.length - 1];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user