mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
Merge branch 'develop' into more-move-commands
This commit is contained in:
commit
9a12bc3b15
32
package.json
32
package.json
@ -206,6 +206,14 @@
|
||||
{
|
||||
"command": "magit.toggle-fold",
|
||||
"title": "Magit Toggle Fold"
|
||||
},
|
||||
{
|
||||
"command": "magit.toggle-all-folds-in-change-section-at-point",
|
||||
"title": "Magit Toggle All Folds in Change Section at Point"
|
||||
},
|
||||
{
|
||||
"command": "magit.toggle-all-folds-for-change-views",
|
||||
"title": "Magit Toggle All Folds for Change Views"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
@ -367,6 +375,14 @@
|
||||
{
|
||||
"command": "magit.toggle-fold",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.toggle-all-folds-in-change-section-at-point",
|
||||
"when": "editorLangId == magit"
|
||||
},
|
||||
{
|
||||
"command": "magit.toggle-all-folds-for-change-views",
|
||||
"when": "editorLangId == magit"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -453,6 +469,16 @@
|
||||
"superType": "label",
|
||||
"description": "Name of a git ref from a remote."
|
||||
},
|
||||
{
|
||||
"id": "magit-head-name",
|
||||
"superType": "label",
|
||||
"description": "Name of the (local) HEAD git ref."
|
||||
},
|
||||
{
|
||||
"id": "magit-remote-head-name",
|
||||
"superType": "label",
|
||||
"description": "Name of a HEAD git ref on a remote repo."
|
||||
},
|
||||
{
|
||||
"id": "magit-tag-name",
|
||||
"superType": "label",
|
||||
@ -468,6 +494,12 @@
|
||||
"magit-remote-ref-name": [
|
||||
"variable.other.constant"
|
||||
],
|
||||
"magit-head-name": [
|
||||
"entity.name.tag"
|
||||
],
|
||||
"magit-remote-head-name": [
|
||||
"variable.object.property"
|
||||
],
|
||||
"magit-tag-name": [
|
||||
"string.highlight"
|
||||
]
|
||||
|
@ -104,7 +104,7 @@ async function showStash({ repository }: MenuState) {
|
||||
}
|
||||
}
|
||||
|
||||
function stashToMagitChanges(nameStatusText: string, diff: string): MagitChange[] {
|
||||
export function stashToMagitChanges(nameStatusText: string, diff: string): MagitChange[] {
|
||||
const DIFF_PREFIX = 'diff --git';
|
||||
const filesWithStatus = nameStatusText.split(Constants.LineSplitterRegex).filter(t => t !== '').map(s => s.split('\t'));
|
||||
const diffs = diff.split(DIFF_PREFIX).filter(r => r !== '');
|
||||
@ -134,7 +134,7 @@ function getStatusFromString(status: String): number {
|
||||
case 'A':
|
||||
return Status.INDEX_ADDED;
|
||||
case 'C':
|
||||
return Status.INDEX_COPIED ;
|
||||
return Status.INDEX_COPIED;
|
||||
case 'D':
|
||||
return Status.DELETED;
|
||||
case 'R' :
|
||||
|
@ -99,7 +99,16 @@ async function log(repository: MagitRepository, args: string[], revs: string[],
|
||||
const logEntries = parseLog(output.stdout);
|
||||
const revName = revs.join(' ');
|
||||
const uri = LogView.encodeLocation(repository);
|
||||
return ViewUtils.showView(uri, new LogView(uri, { entries: logEntries, revName }));
|
||||
|
||||
let defaultBranches: { [remoteName: string]: string } = {};
|
||||
for await (const remote of repository.remotes) {
|
||||
try {
|
||||
let defaultBranch = await gitRun(repository.gitRepository, ['symbolic-ref', `refs/remotes/${remote.name}/HEAD`], undefined, LogLevel.Error);
|
||||
defaultBranches[remote.name] = defaultBranch.stdout.replace(`refs/remotes/${remote.name}/`, '').trimEnd();
|
||||
} catch { } // gitRun will throw an error if remote/HEAD doesn't exist - we do not need to do anything in this case
|
||||
}
|
||||
|
||||
return ViewUtils.showView(uri, new LogView(uri, { entries: logEntries, revName }, repository, defaultBranches));
|
||||
}
|
||||
|
||||
async function getRevs(repository: MagitRepository) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { commands, TextEditor, Range, window, Selection, TextEditorRevealType, Position } from 'vscode';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { ChangeSectionView } from '../views/changes/changesSectionView';
|
||||
import { ChangeView } from '../views/changes/changeView';
|
||||
import { DocumentView } from '../views/general/documentView';
|
||||
import { View } from '../views/general/view';
|
||||
import { ChangeView } from '../views/changes/changeView';
|
||||
@ -39,6 +40,17 @@ export async function toggleAllFoldsInChangeSection(repo: MagitRepository, view:
|
||||
}
|
||||
}
|
||||
|
||||
export async function toggleAllFoldsForChangeViews(repo: MagitRepository, view: DocumentView) {
|
||||
let changeViews = Array.from(view.walkAllSubViews()).filter(x => x instanceof ChangeView);
|
||||
if (changeViews.length === 0) {
|
||||
return;
|
||||
}
|
||||
const newFoldState = !changeViews[0].folded;
|
||||
for (let changeView of changeViews) {
|
||||
changeView.folded = newFoldState;
|
||||
}
|
||||
}
|
||||
|
||||
const subViewDepthSearchFlatten = (view: View, depth: number = 0): View[] => {
|
||||
if (view.folded || depth >= 3) {
|
||||
return [];
|
||||
|
@ -21,6 +21,7 @@ import { PullRequestView } from '../views/forge/pullRequestView';
|
||||
import { sep } from 'path';
|
||||
import { ErrorMessageView } from '../views/errorMessageView';
|
||||
import { processView } from './processCommands';
|
||||
import { stashToMagitChanges } from './diffingCommands';
|
||||
|
||||
export async function magitVisitAtPoint(repository: MagitRepository, currentView: DocumentView) {
|
||||
|
||||
@ -141,9 +142,11 @@ async function visitHunk(selectedView: HunkView, activePosition?: Position) {
|
||||
}
|
||||
|
||||
export async function visitCommit(repository: MagitRepository, commitHash: string) {
|
||||
const result = await gitRun(repository.gitRepository, ['show', commitHash]);
|
||||
const nameStatus = await gitRun(repository.gitRepository, ['show', '--name-status', '--pretty=format:', commitHash]);
|
||||
const header = await gitRun(repository.gitRepository, ['show', '-s', '--shortstat', commitHash]);
|
||||
const diffs = await gitRun(repository.gitRepository, ['show', '--pretty=format:', commitHash]);
|
||||
const commit: MagitCommit = { hash: commitHash, message: '', parents: [] };
|
||||
|
||||
const uri = CommitDetailView.encodeLocation(repository, commit.hash);
|
||||
return ViewUtils.showView(uri, new CommitDetailView(uri, commit, result.stdout));
|
||||
return ViewUtils.showView(uri, new CommitDetailView(uri, commit, header.stdout, stashToMagitChanges(nameStatus.stdout, diffs.stdout)));
|
||||
}
|
@ -14,5 +14,7 @@ export const MagitDocumentSelector: DocumentSelector = { scheme: MagitUriScheme,
|
||||
export enum SemanticTokenTypes {
|
||||
RefName = 'magit-ref-name',
|
||||
RemoteRefName = 'magit-remote-ref-name',
|
||||
HeadName = 'magit-head-name',
|
||||
RemoteHeadName = 'magit-remote-head-name',
|
||||
TagName = 'magit-tag-name',
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
saveClose,
|
||||
clearSaveClose,
|
||||
quitMagitView,
|
||||
toggleAllFoldsForChangeViews,
|
||||
toggleAllFoldsInChangeSection,
|
||||
moveToPreviousEntity,
|
||||
moveToNextEntity,
|
||||
@ -203,6 +204,7 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.move-to-staged-changes', CommandPrimer.primeRepoAndView(moveToStagedChanges, false)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.toggle-all-folds-in-change-section-at-point', CommandPrimer.primeRepoAndView(toggleAllFoldsInChangeSection, true)));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.toggle-all-folds-for-change-views', CommandPrimer.primeRepoAndView(toggleAllFoldsForChangeViews, true)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.save-and-close-editor', saveClose));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('magit.clear-and-abort-editor', clearSaveClose));
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { Repository } from '../typings/git';
|
||||
import { run, SpawnOptions } from './commandRunner/command';
|
||||
import { window } from 'vscode';
|
||||
import GitProcessLogger from './gitProcessLogger';
|
||||
import * as Constants from '../common/constants';
|
||||
|
||||
export enum LogLevel {
|
||||
None,
|
||||
@ -8,7 +10,10 @@ export enum LogLevel {
|
||||
Detailed
|
||||
}
|
||||
|
||||
export async function gitRun(repository: Repository, args: string[], spawnOptions?: SpawnOptions, logLevel = LogLevel.Detailed) {
|
||||
export async function gitRun(repository: Repository, args: string[], spawnOptions?: SpawnOptions, logLevel = LogLevel.Detailed, showStatus: boolean = true) {
|
||||
if (showStatus) {
|
||||
window.setStatusBarMessage(`Running git ${args.join(' ')}...`);
|
||||
}
|
||||
|
||||
let logEntry;
|
||||
if (logLevel > LogLevel.None) {
|
||||
@ -26,11 +31,18 @@ export async function gitRun(repository: Repository, args: string[], spawnOption
|
||||
GitProcessLogger.logGitResult(result, logEntry);
|
||||
}
|
||||
|
||||
if (showStatus) {
|
||||
window.setStatusBarMessage(`Git finished successfully`, Constants.StatusMessageDisplayTimeout);
|
||||
}
|
||||
return result;
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
if (logLevel > LogLevel.None && logEntry) {
|
||||
GitProcessLogger.logGitError(error, logEntry);
|
||||
}
|
||||
|
||||
if (showStatus) {
|
||||
window.setStatusBarMessage(error.message);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ export default class ViewUtils {
|
||||
return selectedViews;
|
||||
}
|
||||
|
||||
public static generateRefTokensLine(commitHash: string, refs?: Ref[]): (string | Token)[] {
|
||||
public static generateRefTokensLine(commitHash: string, refs?: Ref[], headName?: string, defaultBranches?: { [remoteName: string]: string }): (string | Token)[] {
|
||||
|
||||
const matchingRefs = (refs ?? [])
|
||||
.filter(ref => ref.commit === commitHash)
|
||||
@ -103,7 +103,19 @@ export default class ViewUtils {
|
||||
let m = matchingRefs.find(other => other.name === namePart && other.type === RefType.Head);
|
||||
if (m && m.name) {
|
||||
hasMatchingRemoteBranch[m.name!] = true;
|
||||
refsContent.push(new Token(remotePart + '/', SemanticTokenTypes.RemoteRefName), new Token(m.name ?? '', SemanticTokenTypes.RefName));
|
||||
|
||||
// Determine if local or remote branches are HEADs
|
||||
let remoteRefTokenType = SemanticTokenTypes.RemoteRefName;
|
||||
if (defaultBranches && ref.remote && defaultBranches[ref.remote] === namePart) {
|
||||
remoteRefTokenType = SemanticTokenTypes.RemoteHeadName;
|
||||
}
|
||||
|
||||
let refTokenType = SemanticTokenTypes.RefName;
|
||||
if (m.name === headName) {
|
||||
refTokenType = SemanticTokenTypes.HeadName;
|
||||
}
|
||||
|
||||
refsContent.push(new Token(remotePart + '/', remoteRefTokenType), new Token(m.name ?? '', refTokenType));
|
||||
refsContent.push(' ');
|
||||
return;
|
||||
}
|
||||
@ -114,8 +126,13 @@ export default class ViewUtils {
|
||||
|
||||
let refTokenType = SemanticTokenTypes.RefName;
|
||||
|
||||
if (ref.remote) {
|
||||
if (ref.name === headName) {
|
||||
refTokenType = SemanticTokenTypes.HeadName;
|
||||
} else if (ref.remote) {
|
||||
refTokenType = SemanticTokenTypes.RemoteRefName;
|
||||
if (defaultBranches && ref.remote && ref.remote + '/' + defaultBranches[ref.remote] === ref.name) {
|
||||
refTokenType = SemanticTokenTypes.RemoteHeadName;
|
||||
}
|
||||
} else if (ref.type === RefType.Tag) {
|
||||
refTokenType = SemanticTokenTypes.TagName;
|
||||
}
|
||||
@ -126,4 +143,4 @@ export default class ViewUtils {
|
||||
|
||||
return refsContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
import { DocumentView } from './general/documentView';
|
||||
import { Uri } from 'vscode';
|
||||
import { Section } from './general/sectionHeader';
|
||||
import * as Constants from '../common/constants';
|
||||
import { TextView } from './general/textView';
|
||||
import { MagitCommit } from '../models/magitCommit';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { MagitChange } from '../models/magitChange';
|
||||
import { ChangeSectionView } from './changes/changesSectionView';
|
||||
|
||||
export class CommitDetailView extends DocumentView {
|
||||
|
||||
@ -11,11 +14,14 @@ export class CommitDetailView extends DocumentView {
|
||||
isHighlightable = false;
|
||||
needsUpdate = false;
|
||||
|
||||
constructor(uri: Uri, public commit: MagitCommit, diff: string) {
|
||||
constructor(uri: Uri, public commit: MagitCommit, header: string, diffChanges: MagitChange[]) {
|
||||
super(uri);
|
||||
|
||||
const commitTextView = new TextView(diff);
|
||||
commitTextView.isHighlightable = false;
|
||||
const commitTextView = new ChangeSectionView(Section.Changes, diffChanges);
|
||||
const headerView = new TextView(header);
|
||||
headerView.isHighlightable = false;
|
||||
|
||||
this.addSubview(headerView);
|
||||
this.addSubview(commitTextView);
|
||||
}
|
||||
|
||||
|
@ -85,4 +85,11 @@ export abstract class View {
|
||||
addSubview(...views: View[]) {
|
||||
this.subViews.push(...views);
|
||||
}
|
||||
}
|
||||
|
||||
*walkAllSubViews(): Generator<View> {
|
||||
for (let subView of this.subViews) {
|
||||
yield subView;
|
||||
yield* subView.walkAllSubViews();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,21 @@ import { DocumentView } from './general/documentView';
|
||||
import { TextView } from './general/textView';
|
||||
import { Token } from './general/semanticTextView';
|
||||
import { SemanticTokenTypes } from '../common/constants';
|
||||
import { Ref, RefType } from '../typings/git';
|
||||
import ViewUtils from '../utils/viewUtils';
|
||||
import { MagitRemote } from '../models/magitRemote';
|
||||
|
||||
export default class LogView extends DocumentView {
|
||||
|
||||
static UriPath: string = 'log.magit';
|
||||
|
||||
constructor(uri: Uri, log: MagitLog) {
|
||||
constructor(uri: Uri, log: MagitLog, magitState: MagitRepository, defaultBranches?: { [remoteName: string]: string }) {
|
||||
super(uri);
|
||||
const refs = magitState.remotes.reduce((prev, remote) => remote.branches.concat(prev), magitState.branches.concat(magitState.tags));
|
||||
|
||||
this.subViews = [
|
||||
new TextView(`Commits in ${log.revName}`),
|
||||
...log.entries.map(entry => new CommitLongFormItemView(entry)),
|
||||
...log.entries.map(entry => new CommitLongFormItemView(entry, refs, magitState.HEAD?.name, defaultBranches)),
|
||||
];
|
||||
}
|
||||
|
||||
@ -34,8 +38,8 @@ export default class LogView extends DocumentView {
|
||||
|
||||
export class CommitLongFormItemView extends CommitItemView {
|
||||
|
||||
constructor(public logEntry: MagitLogEntry) {
|
||||
super(logEntry.commit);
|
||||
constructor(public logEntry: MagitLogEntry, refs?: Ref[], headName?: string, defaultBranches?: { [remoteName: string]: string }) {
|
||||
super(logEntry.commit, undefined, refs);
|
||||
|
||||
const timeDistance = formatDistanceToNowStrict(logEntry.time);
|
||||
const hash = `${GitTextUtils.shortHash(logEntry.commit.hash)} `;
|
||||
@ -46,16 +50,8 @@ export class CommitLongFormItemView extends CommitItemView {
|
||||
const msg = GitTextUtils.shortCommitMessage(logEntry.commit.message);
|
||||
this.content.push(`${hash}${graph}`);
|
||||
|
||||
const refTokens: Token[] = logEntry.refs.map(ref => new Token(ref, SemanticTokenTypes.RefName));
|
||||
if (refTokens.length) {
|
||||
|
||||
this.content.push(' (');
|
||||
refTokens.forEach(refToken => {
|
||||
this.content.push(refToken, ' ');
|
||||
});
|
||||
this.content.pop();
|
||||
|
||||
this.content.push(') ');
|
||||
if (logEntry.refs.length) {
|
||||
this.content.push(...ViewUtils.generateRefTokensLine(logEntry.commit.hash, refs, headName, defaultBranches));
|
||||
}
|
||||
|
||||
const availableMsgWidth = 70 - this.content.reduce((prev, v) => prev + v.length, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user