1
1
mirror of https://github.com/kahole/edamagit.git synced 2024-09-11 07:15:31 +03:00
This commit is contained in:
kahole 2019-12-14 18:54:18 +01:00
parent ca95f92fc0
commit a0adac82e8
14 changed files with 193 additions and 102 deletions

View File

@ -4,6 +4,8 @@
make magit, but the fancy stuff should be vscode like
## UI
- Hide line numbers?
- Command pallete
When a command should be available: https://code.visualstudio.com/api/extension-guides/command#controlling-when-a-command-shows-up-in-the-command-palette
https://code.visualstudio.com/api/extension-guides/command#enablement-of-commands

View File

@ -122,6 +122,11 @@
"configuration": "./languages/magit.language-configuration.json"
}
],
"configurationDefaults": {
"[magit-status]": {
"editor.lineNumbers": "off"
}
},
"grammars": [
{
"language": "magit-status",

View File

@ -1,6 +1,7 @@
import { BranchingMenu } from "../menus/branching/branchingMenu";
import { MagitPicker } from "../menus/magitPicker";
import { MagitRepository } from "../models/magitRepository";
export function branching() {
MagitPicker.showMagitPicker(new BranchingMenu());
export function branching(repository: MagitRepository) {
// MagitPicker.showMagitPicker(new BranchingMenu(repository.branches));
}

View File

@ -0,0 +1,25 @@
import MagitUtils from "../utils/magitUtils";
export class CommandPrimer {
static prime(command: Function, needsView?: boolean, needsSelectedView?: boolean) {
if (needsView) {
return () => {
let [repository, currentView] = MagitUtils.getCurrentMagitRepoAndView();
if (currentView) {
command(repository, currentView);
}
};
} else {
return () => {
let repository = MagitUtils.getCurrentMagitRepo();
if (repository) {
command(repository);
}
};
}
}
}

View File

@ -10,15 +10,15 @@ export function pushing() {
console.log("Working tree changes, but from pushing command");
console.log(currentRepository.magitState!.workingTreeChanges);
MagitPicker.showMagitPicker(new PushingMenu());
MagitPicker.showMagitPicker(new PushingMenu(undefined, undefined));
// Hvordan git push kommandoen bygges opp:
// https://github.com/microsoft/vscode/blob/master/extensions/git/src/git.ts#L1491
// kun "git push" slik den står nå
currentRepository._repository.pushTo()
.then(() => console.log("klarte å pushe ?"))
.catch(console.log);
// currentRepository._repository.pushTo()
// .then(() => console.log("klarte å pushe ?"))
// .catch(console.log);
}
// _repository pushTo(remote?: string, name?: string, setUpstream?: boolean, forcePushMode?: ForcePushMode): Promise<void>

View File

@ -6,84 +6,72 @@ import FilePathUtils from "../utils/filePathUtils";
import { ChangeSectionView } from "../views/changes/changesSectionView";
import { Section } from "../views/sectionHeader";
import { TextEncoder } from "util";
import { MagitRepository } from "../models/magitRepository";
import { View } from "../views/abstract/view";
export function magitStage() {
// TODO:
// Can make a command runner thing
// so that repository and currentView get passed in NOT nullable
// multiple types of commands:
// view + repo
// only repo
export function magitStage(repository: MagitRepository, currentView: View) {
// TODO:
// Bytt til ASYNC-AWAIT!!!!!??????
let [repository, currentView] = MagitUtils.getCurrentMagitRepoAndView();
let clickedView = currentView.click(window.activeTextEditor!.selection.active);
let currentRepository = repository!;
if (currentView) {
let clickedView = currentView.click(window.activeTextEditor!.selection.active);
let currentRepository = repository!;
if (clickedView instanceof HunkView) {
let changeHunkDiff = (clickedView as HunkView).changeHunk.diff;
if (clickedView instanceof HunkView) {
let changeHunkDiff = (clickedView as HunkView).changeHunk.diff;
// TODO
var enc = new TextEncoder();
workspace.fs.writeFile(Uri.parse("file:///tmp/minmagitdiffpatchting"),
enc.encode(clickedView.changeHunk.diffHeader + changeHunkDiff + "\n"))
.then(() => {
// stage hunk
currentRepository
.apply("/tmp/minmagitdiffpatchting")
.then(MagitUtils.magitStatusAndUpdate(currentRepository, currentView));
});
// TODO
var enc = new TextEncoder();
workspace.fs.writeFile(Uri.parse("file:///tmp/minmagitdiffpatchting"),
enc.encode(clickedView.changeHunk.diffHeader + changeHunkDiff + "\n"))
.then( () => {
// stage hunk
currentRepository
.apply("/tmp/minmagitdiffpatchting")
.then(MagitUtils.magitStatusAndUpdate(currentRepository, currentView));
});
} else if (clickedView instanceof ChangeView) {
} else if (clickedView instanceof ChangeView) {
let magitChange = (clickedView as ChangeView).change;
let magitChange = (clickedView as ChangeView).change;
currentRepository
._repository
.add([magitChange.uri], { update: true }) // TODO: litt usikker om update eller ikke
.then(MagitUtils.magitStatusAndUpdate(currentRepository, currentView));
currentRepository
._repository
.add([magitChange.uri], { update: true }) // TODO: litt usikker om update eller ikke
.then(MagitUtils.magitStatusAndUpdate(currentRepository, currentView));
} else if (clickedView instanceof ChangeSectionView) {
let section = (clickedView as ChangeSectionView).section;
} else if (clickedView instanceof ChangeSectionView) {
let section = (clickedView as ChangeSectionView).section;
switch (section) {
case Section.Untracked:
magitStageAll(StageAllKind.AllUntracked);
break;
case Section.Unstaged:
magitStageAll(StageAllKind.AllTracked);
break;
default:
break;
}
} else {
// TODO:
// Switch to a quick pick where i can pass data, and have a title
// Maybe make a simple wrapper
// This should NOT be the same as a menu!
window.showQuickPick([
...currentRepository.magitState?.workingTreeChanges!,
...currentRepository.magitState?.indexChanges!,
...currentRepository.magitState?.untrackedFiles!,
// ...currentRepository.magitState?.mergeChanges
].map(c => FilePathUtils.pathRelativeTo(c.uri, currentRepository.rootUri)),
{ placeHolder: "Stage" }
)
.then(chosenFilePath => {
// TODO
})
.then(MagitUtils.magitStatusAndUpdate(currentRepository, currentView));
switch (section) {
case Section.Untracked:
magitStageAll(StageAllKind.AllUntracked);
break;
case Section.Unstaged:
magitStageAll(StageAllKind.AllTracked);
break;
default:
break;
}
} else {
// TODO:
// Switch to a quick pick where i can pass data, and have a title
// Maybe make a simple wrapper
// This should NOT be the same as a menu!
window.showQuickPick([
...currentRepository.magitState?.workingTreeChanges!,
...currentRepository.magitState?.indexChanges!,
...currentRepository.magitState?.untrackedFiles!,
// ...currentRepository.magitState?.mergeChanges
].map(c => FilePathUtils.pathRelativeTo(c.uri, currentRepository.rootUri)),
{ placeHolder: "Stage" }
)
.then(chosenFilePath => {
// NB! Trenger kanskje headeren til hele diffen for å utføre disse.
// Den kan hektes på i et eget felt i Hunk-modellen, null stress joggedress!
// TODO
})
.then(MagitUtils.magitStatusAndUpdate(currentRepository, currentView));
}
}

View File

@ -12,6 +12,7 @@ import { magitStage, magitStageAll, magitUnstageAll, magitUnstage } from './comm
import { saveClose } from './commands/macros';
import FoldingRangeProvider from './foldingRangeProvider';
import HighlightProvider from './highlightProvider';
import { CommandPrimer } from './commands/commandPrimer';
export const magitRepositories: { [id: string]: MagitRepository } = {};
@ -55,7 +56,7 @@ export function activate(context: ExtensionContext) {
}));
context.subscriptions.push(commands.registerCommand('extension.magit-pushing', pushing));
context.subscriptions.push(commands.registerCommand('extension.magit-branching', branching));
context.subscriptions.push(commands.registerCommand('extension.magit-stage', magitStage));
context.subscriptions.push(commands.registerCommand('extension.magit-stage', CommandPrimer.prime(magitStage, true, true)));
context.subscriptions.push(commands.registerCommand('extension.magit-stage-all', magitStageAll));
context.subscriptions.push(commands.registerCommand('extension.magit-unstage', magitUnstage));
context.subscriptions.push(commands.registerCommand('extension.magit-unstage-all', magitUnstageAll));

View File

@ -1,6 +0,0 @@
export interface PushingInput {
remote?: string;
upstream?: string;
}

View File

@ -1,6 +1,5 @@
import { Menu } from "../abstract/menu";
import { MenuItem } from "../abstract/menuItem";
import { MagitState } from "../../models/magitStatus";
import { PushingSwitches } from "./switches";
enum Items {
@ -12,7 +11,7 @@ export class PushingMenu implements Menu {
title: string = "Pushing";
items: MenuItem[];
constructor() {
constructor(remote?: string, upstream?: string) {
// TODO: take in some state to customize and narrow selection!
this.items = [{id: Items.Switches, label: "-", description: "Switches"}];
}

View File

@ -0,0 +1,35 @@
import { View } from "../abstract/view";
import { Section, SectionHeaderView } from "../sectionHeader";
import { LineBreakView } from "../lineBreakView";
import { Stash } from "../../common/gitApiExtensions";
import { TextView } from "../abstract/textView";
import { Remote } from "../../typings/git";
// https://emacs.stackexchange.com/questions/26247/meaning-of-magit-status-buffer-head-merge-push
// https://magit.vc/manual/magit/The-Two-Remotes.html
// export class BranchHeaderSectionView extends View {
// constructor(head: Branch, remotes: Remote) {
// super();
// this.subViews = [
// new SectionHeaderView(Section.Stashes, stashes.length),
// ...stashes.map(stash => new BranchHeaderView(stash)),
// new LineBreakView()
// ];
// }
// }
// export class BranchHeaderView extends TextView {
// constructor (stash: Stash) {
// super();
// this.textContent = `stash@{${stash.index}} ${stash.description}`;
// }
// }

View File

@ -0,0 +1,27 @@
import { View } from "../abstract/view";
import { Section, SectionHeaderView } from "../sectionHeader";
import { LineBreakView } from "../lineBreakView";
import { Stash } from "../../common/gitApiExtensions";
import { TextView } from "../abstract/textView";
import { Commit } from "../../typings/git";
export class CommitSectionView extends View {
isFoldable = true;
constructor(private commits: Commit[]) {
super();
this.subViews = [
new SectionHeaderView(Section.RecentCommits),
...commits.map(commit => new CommitItemView(commit)),
new LineBreakView()
];
}
}
export class CommitItemView extends TextView {
constructor (private commit: Commit) {
super();
this.textContent = `${commit.hash.slice(0, 7)} ${commit.message}`;
}
}

View File

@ -4,12 +4,16 @@ import { ChangeSectionView } from './changes/changesSectionView';
import { Section } from './sectionHeader';
import { RestView } from './restView';
import { DocumentView } from './abstract/documentView';
import { StashSectionView } from './stashes/stashSectionView';
import { CommitSectionView } from './commits/commitSectionView';
export default class MagitStatusView extends DocumentView {
constructor(uri: vscode.Uri, emitter: vscode.EventEmitter<vscode.Uri>, magitState: MagitState) {
super(uri, emitter);
this.subViews.push(new RestView(magitState));
if (magitState.untrackedFiles && magitState.untrackedFiles.length > 0) {
this.subViews.push(new ChangeSectionView(Section.Untracked, magitState.untrackedFiles));
}
@ -22,7 +26,13 @@ export default class MagitStatusView extends DocumentView {
this.subViews.push(new ChangeSectionView(Section.Staged, magitState.indexChanges));
}
this.subViews.push(new RestView(magitState));
if (magitState.stashes && magitState.stashes?.length > 0) {
this.subViews.push(new StashSectionView(magitState.stashes));
}
if (magitState.log && magitState.log.length > 0) {
this.subViews.push(new CommitSectionView(magitState.log));
}
}
public triggerUpdate() {

View File

@ -4,34 +4,12 @@ import { TextView } from "./abstract/textView";
export class RestView extends TextView {
private _lines: string[] = [];
private readonly SECTION_FOLD_REGION_END: string = '.';
constructor(private magitStatus: MagitState) {
super();
this._lines.push(`Head: ${magitStatus._state.HEAD!.name} ${magitStatus.commitCache[magitStatus._state.HEAD!.commit!].message}`);
this._lines.push('');
if (magitStatus.stashes) {
this._lines.push(`Stashes (${magitStatus.stashes.length})`);
magitStatus.stashes
.forEach(stash => {
this._lines.push(`stash@{${stash.index}} ${stash.description}`);
});
this._lines.push(this.SECTION_FOLD_REGION_END);
}
if (magitStatus.log) {
this._lines.push(`Recent commits`);
magitStatus.log
.forEach(commit => {
this._lines.push(`${commit.hash.slice(0, 7)} ${commit.message}`);
});
this._lines.push(this.SECTION_FOLD_REGION_END);
}
this._lines.push('');
this.textContent = this._lines.join('\n');
}

View File

@ -0,0 +1,26 @@
import { View } from "../abstract/view";
import { Section, SectionHeaderView } from "../sectionHeader";
import { LineBreakView } from "../lineBreakView";
import { Stash } from "../../common/gitApiExtensions";
import { TextView } from "../abstract/textView";
export class StashSectionView extends View {
isFoldable = true;
constructor(private stashes: Stash[]) {
super();
this.subViews = [
new SectionHeaderView(Section.Stashes, stashes.length),
...stashes.map(stash => new StashItemView(stash)),
new LineBreakView()
];
}
}
export class StashItemView extends TextView {
constructor (private stash: Stash) {
super();
this.textContent = `stash@{${stash.index}} ${stash.description}`;
}
}