mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
adds some discard commands and makes things prettier
This commit is contained in:
parent
4d50a8d8f4
commit
9fc7583807
@ -8,6 +8,11 @@
|
||||
## Auto refresh
|
||||
- FileChangeEvent
|
||||
|
||||
## Highlighter
|
||||
- hunk @@ blabla @@ line needs to be highlighted a bit
|
||||
> can this be done with syntax?
|
||||
- branch names
|
||||
|
||||
## DIFF view
|
||||
- can use VSCODE diff command to show diff for a file? or something
|
||||
|
||||
|
13
package.json
13
package.json
@ -28,6 +28,10 @@
|
||||
"command": "extension.magit-apply-at-point",
|
||||
"title": "Magit Apply-at-point"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-discard-at-point",
|
||||
"title": "Magit Discard-at-point"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-commit",
|
||||
"title": "Magit Commit"
|
||||
@ -79,6 +83,10 @@
|
||||
"command": "extension.magit-apply-at-point",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-discard-at-point",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-stage",
|
||||
"when": "editorLangId == magit"
|
||||
@ -159,6 +167,11 @@
|
||||
"key": "a",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-discard-at-point",
|
||||
"key": "k",
|
||||
"when": "editorTextFocus && editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-commit",
|
||||
"key": "c",
|
||||
|
@ -94,10 +94,9 @@ async function deleteBranch({ repository, currentView }: MenuState) {
|
||||
await repository.deleteBranch(ref, false);
|
||||
} catch (error) {
|
||||
if (error.gitErrorCode === GitErrorCodes.BranchNotFullyMerged) {
|
||||
try {
|
||||
await MagitUtils.confirmAction(`Delete unmerged branch ${ref}?`);
|
||||
if (await MagitUtils.confirmAction(`Delete unmerged branch ${ref}?`)) {
|
||||
return repository.deleteBranch(ref, true);
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -115,10 +114,9 @@ async function resetBranch({ repository, currentView }: MenuState) {
|
||||
|
||||
if (MagitUtils.magitAnythingModified(repository)) {
|
||||
|
||||
try {
|
||||
await MagitUtils.confirmAction(`Uncommitted changes will be lost. Proceed?`);
|
||||
if(await MagitUtils.confirmAction(`Uncommitted changes will be lost. Proceed?`)) {
|
||||
return repository._repository.reset(resetToRef, true);
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const args = ['update-ref', `refs/heads/${ref}`, `refs/heads/${resetToRef}`];
|
||||
|
@ -1,3 +1,34 @@
|
||||
import { window } from 'vscode';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { CommitItemView } from '../views/commits/commitSectionView';
|
||||
import { DocumentView } from '../views/general/documentView';
|
||||
import { gitRun } from '../utils/gitRawRunner';
|
||||
import { StashItemView, StashSectionView } from '../views/stashes/stashSectionView';
|
||||
import { ChangeView } from '../views/changes/changeView';
|
||||
import { HunkView } from '../views/changes/HunkView';
|
||||
import MagitUtils from '../utils/magitUtils';
|
||||
|
||||
export async function magitDiscardAtPoint(repository: MagitRepository, currentView: DocumentView): Promise<any> {
|
||||
|
||||
// k - Discard at point
|
||||
const selectedView = currentView.click(window.activeTextEditor!.selection.active);
|
||||
|
||||
if (selectedView instanceof HunkView) {
|
||||
|
||||
} else if (selectedView instanceof ChangeView) {
|
||||
|
||||
} else if (selectedView instanceof StashSectionView) {
|
||||
|
||||
if (await MagitUtils.confirmAction('Drop all stashes in ref/stash?')) {
|
||||
const args = ['stash', 'clear'];
|
||||
return gitRun(repository, args);
|
||||
}
|
||||
} else if (selectedView instanceof StashItemView) {
|
||||
|
||||
const stash = (selectedView as StashItemView).stash;
|
||||
|
||||
if (await MagitUtils.confirmAction(`Drop stash stash@{${stash.index}}?`)) {
|
||||
const args = ['stash', 'drop', `stash@{${stash.index}}`];
|
||||
return gitRun(repository, args);
|
||||
}
|
||||
}
|
||||
}
|
@ -109,8 +109,7 @@ export async function magitUnstage(repository: MagitRepository, currentView: Doc
|
||||
|
||||
export async function magitUnstageAll(repository: MagitRepository, currentView: DocumentView): Promise<void> {
|
||||
|
||||
try {
|
||||
await MagitUtils.confirmAction('Unstage all changes?');
|
||||
return commands.executeCommand('git.unstageAll');
|
||||
} catch { }
|
||||
if (await MagitUtils.confirmAction('Unstage all changes?')) {
|
||||
return commands.executeCommand('git.unstageAll');
|
||||
}
|
||||
}
|
@ -106,17 +106,19 @@ export async function internalMagitStatus(repository: MagitRepository): Promise<
|
||||
const workingTreeChanges_NoUntracked = repository.state.workingTreeChanges
|
||||
.filter(c => {
|
||||
if (c.status === Status.UNTRACKED) {
|
||||
untrackedFiles.push(c);
|
||||
const magitChange: MagitChange = c;
|
||||
magitChange.relativePath = FilePathUtils.uriPathRelativeTo(c.uri, repository.rootUri);
|
||||
untrackedFiles.push(magitChange);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const workingTreeChangesTasks = Promise.all(workingTreeChanges_NoUntracked
|
||||
.map(async change => {
|
||||
const diff = await repository.diffWithHEAD(change.uri.path);
|
||||
const magitChange: MagitChange = change;
|
||||
magitChange.relativePath = FilePathUtils.uriPathRelativeTo(change.uri, repository.rootUri);
|
||||
magitChange.hunks = GitTextUtils.diffToHunks(diff, change.uri);
|
||||
return magitChange;
|
||||
}));
|
||||
@ -125,6 +127,7 @@ export async function internalMagitStatus(repository: MagitRepository): Promise<
|
||||
.map(async change => {
|
||||
const diff = await repository.diffIndexWithHEAD(change.uri.path);
|
||||
const magitChange: MagitChange = change;
|
||||
magitChange.relativePath = FilePathUtils.uriPathRelativeTo(change.uri, repository.rootUri);
|
||||
magitChange.hunks = GitTextUtils.diffToHunks(diff, change.uri);
|
||||
return magitChange;
|
||||
}));
|
||||
|
@ -19,6 +19,7 @@ import { pulling } from './commands/pullingCommands';
|
||||
import { stashing } from './commands/stashingCommands';
|
||||
import { DocumentView } from './views/general/documentView';
|
||||
import { magitApplyEntityAtPoint } from './commands/applyCommands';
|
||||
import { magitDiscardAtPoint } from './commands/discardCommands';
|
||||
|
||||
export const magitRepositories: Map<string, MagitRepository> = new Map<string, MagitRepository>();
|
||||
export const views: Map<string, DocumentView> = new Map<string, DocumentView>();
|
||||
@ -58,6 +59,8 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-commit', CommandPrimer.primeRepoAndView(magitCommit)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-visit-at-point', CommandPrimer.primeRepoAndView(magitVisitAtPoint, false)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-apply-at-point', CommandPrimer.primeRepoAndView(magitApplyEntityAtPoint)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-discard-at-point', CommandPrimer.primeRepoAndView(magitDiscardAtPoint)));
|
||||
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-help', magitHelp));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-pulling', CommandPrimer.primeRepoAndView(pulling)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-pushing', CommandPrimer.primeRepoAndView(pushing)));
|
||||
|
@ -3,4 +3,5 @@ import { MagitChangeHunk } from './magitChangeHunk';
|
||||
|
||||
export interface MagitChange extends Change {
|
||||
hunks?: MagitChangeHunk[];
|
||||
relativePath?: string;
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ export default class MagitUtils {
|
||||
const confirmed = await window.showInputBox({ prompt: `${prompt} (${yesNo})` });
|
||||
if ((hardConfirm && confirmed?.toLowerCase() === 'yes') || (!hardConfirm && confirmed?.toLowerCase().charAt(0) === 'y')) {
|
||||
return true;
|
||||
} else {
|
||||
throw new Error('Action not confirmed');
|
||||
}
|
||||
window.setStatusBarMessage('Abort');
|
||||
return false;
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ export class ChangeHeaderView extends TextView {
|
||||
constructor(private change: MagitChange) {
|
||||
super();
|
||||
const statusLabel = mapFileStatusToLabel(this.change.status);
|
||||
this.textContent = `${statusLabel ? statusLabel + ' ' : ''}${this.change.uri.path}`;
|
||||
this.textContent = `${statusLabel ? statusLabel + ' ' : ''}${this.change.relativePath}`;
|
||||
}
|
||||
|
||||
onClicked() { return undefined; }
|
||||
|
@ -13,6 +13,12 @@
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#sectionHeader"
|
||||
},
|
||||
{
|
||||
"include": "#modified"
|
||||
},
|
||||
{
|
||||
"include": "#high"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -20,7 +26,15 @@
|
||||
"match": "Untracked files|((Unstaged|Staged) changes)|Stashes|Recent commits|Unmerged into|Unpulled from|GitError!",
|
||||
"name": "markup.bold keyword.section.header.magit"
|
||||
},
|
||||
"diff": {
|
||||
"modified": {
|
||||
"match": "^modified .*$",
|
||||
"name": "markup.bold string"
|
||||
},
|
||||
"high": {
|
||||
"match": "^@@.*@@.*$",
|
||||
"name": "markup.inline.raw"
|
||||
},
|
||||
"diff": {
|
||||
"begin": "(?=^@@)",
|
||||
"end": "^$",
|
||||
"patterns": [
|
||||
|
Loading…
Reference in New Issue
Block a user