Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b5bdd3b

Browse files
Initial prototype working
1 parent 786314e commit b5bdd3b

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

‎src/webviews/apps/rebase/rebase.ts

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
import { App } from '../shared/appBase';
2020
import { DOM } from '../shared/dom';
2121

22-
const rebaseActions = ['pick', 'reword', 'edit', 'squash', 'fixup', 'drop'];
22+
const rebaseActions = ['pick', 'reword', 'edit', 'squash', 'fixup', 'drop','update-ref'];
2323
const rebaseActionsMap = new Map<string, RebaseEntryAction>([
2424
['p', 'pick'],
2525
['P', 'pick'],
@@ -33,6 +33,8 @@ const rebaseActionsMap = new Map<string, RebaseEntryAction>([
3333
['F', 'fixup'],
3434
['d', 'drop'],
3535
['D', 'drop'],
36+
['u', 'update-ref'],
37+
['U', 'update-ref'],
3638
]);
3739

3840
class RebaseEditor extends App<State> {
@@ -414,6 +416,7 @@ class RebaseEditor extends App<State> {
414416
index: 0,
415417
message: commit.message,
416418
sha: state.onto.sha,
419+
branch: undefined!,
417420
},
418421
state,
419422
++tabIndex,
@@ -448,6 +451,7 @@ class RebaseEditor extends App<State> {
448451
$entry.classList.add('entry', `entry--${action}`);
449452
$entry.classList.toggle('entry--squash-to', squashToHere);
450453
$entry.dataset.sha = entry.sha;
454+
$entry.dataset.branch = entry.branch;
451455

452456
let $content: HTMLElement = $entry;
453457
if (action === 'base') {
@@ -467,24 +471,30 @@ class RebaseEditor extends App<State> {
467471
$selectContainer.classList.add('entry-action', 'select-container');
468472
$entry.appendChild($selectContainer);
469473

470-
const $select = document.createElement('select');
471-
$select.dataset.sha = entry.sha;
472-
$select.name = 'action';
473-
474-
const $options = document.createDocumentFragment();
475-
for (const action of rebaseActions) {
476-
const $option = document.createElement('option');
477-
$option.value = action;
478-
$option.text = action;
474+
if (action === 'update-ref') {
475+
const $updateRefAction = document.createElement('span');
476+
$updateRefAction.textContent = 'Update Ref';
477+
$selectContainer.appendChild($updateRefAction);
478+
} else {
479+
const $select = document.createElement('select');
480+
$select.dataset.sha = entry.sha;
481+
$select.name = 'action';
482+
483+
const $options = document.createDocumentFragment();
484+
for (const action of rebaseActions) {
485+
const $option = document.createElement('option');
486+
$option.value = action;
487+
$option.text = action;
488+
489+
if (entry.action === action) {
490+
$option.selected = true;
491+
}
479492

480-
if (entry.action === action) {
481-
$option.selected = true;
493+
$options.appendChild($option);
482494
}
483-
484-
$options.appendChild($option);
495+
$select.appendChild($options);
496+
$selectContainer.appendChild($select);
485497
}
486-
$select.appendChild($options);
487-
$selectContainer.appendChild($select);
488498
}
489499

490500
const commit = entry.commit;
@@ -537,11 +547,18 @@ class RebaseEditor extends App<State> {
537547
}
538548
}
539549

540-
const $sha = document.createElement('a');
541-
$sha.classList.add('entry-sha', 'icon--commit');
542-
$sha.href = state.commands.commit.replace(this.commitTokenRegex, commit?.sha ?? entry.sha);
543-
$sha.textContent = entry.sha.substr(0, 7);
544-
$content.appendChild($sha);
550+
if (entry.action != 'update-ref') {
551+
const $sha = document.createElement('a');
552+
$sha.classList.add('entry-sha', 'icon--commit');
553+
$sha.href = state.commands.commit.replace(this.commitTokenRegex, commit?.sha ?? entry.sha);
554+
$sha.textContent = entry.sha.substr(0, 7);
555+
$content.appendChild($sha);
556+
} else {
557+
const $branch = document.createElement('span');
558+
$branch.classList.add('entry-sha', 'icon--branch');
559+
$branch.textContent = entry.branch;
560+
$content.appendChild($branch);
561+
}
545562

546563
return [$entry, tabIndex];
547564
}

‎src/webviews/rebase/protocol.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ export interface State extends WebviewState<CustomEditorIds> {
2020
export interface RebaseEntry {
2121
readonly action: RebaseEntryAction;
2222
readonly sha: string;
23+
readonly branch: string;
2324
readonly message: string;
2425
readonly index: number;
2526

2627
commit?: Commit;
28+
refUpdate?: RefUpdate;
2729
}
2830

29-
export type RebaseEntryAction = 'pick' | 'reword' | 'edit' | 'squash' | 'fixup' | 'break' | 'drop';
31+
export type RebaseEntryAction = 'pick' | 'reword' | 'edit' | 'squash' | 'fixup' | 'break' | 'drop'|'update-ref';
3032

3133
export interface Author {
3234
readonly author: string;
@@ -46,6 +48,10 @@ export interface Commit {
4648
// readonly command: string;
4749
}
4850

51+
export interface RefUpdate {
52+
readonly branch: string;
53+
}
54+
4955
// COMMANDS
5056

5157
export const AbortCommand = new IpcCommand(scope, 'abort');

‎src/webviews/rebase/rebaseEditor.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const ipcSequencer = getScopedCounter();
5656
const webviewIdGenerator = getScopedCounter();
5757

5858
const rebaseRegex = /^\s?#\s?Rebase\s([0-9a-f]+)(?:..([0-9a-f]+))?\sonto\s([0-9a-f]+)\s.*$/im;
59-
const rebaseCommandsRegex = /^\s?(p|pick|r|reword|e|edit|s|squash|f|fixup|d|drop)\s([0-9a-f]+?)\s(.*)$/gm;
59+
const rebaseCommandsRegex =
60+
/^\s?(p|pick|r|reword|e|edit|s|squash|f|fixup|d|drop|u|update-ref)(?:\s([0-9a-f]+)\s(.*)|\s(refs\/heads\/\S+))$/gm;
6061

6162
const rebaseActionsMap = new Map<string, RebaseEntryAction>([
6263
['p', 'pick'],
@@ -71,6 +72,8 @@ const rebaseActionsMap = new Map<string, RebaseEntryAction>([
7172
['fixup', 'fixup'],
7273
['d', 'drop'],
7374
['drop', 'drop'],
75+
['u', 'update-ref'],
76+
['update-ref', 'update-ref'],
7477
]);
7578

7679
interface RebaseEditorContext {
@@ -440,7 +443,13 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl
440443
}
441444

442445
edit.delete(context.document.uri, range);
443-
edit.insert(context.document.uri, new Position(newLine, 0), `${action} ${entry.sha} ${entry.message}\n`);
446+
let entryToInsert = '';
447+
if (entry.action === 'update-ref') {
448+
entryToInsert = `${action}${entry.branch}\n`;
449+
} else {
450+
entryToInsert = `${action} ${entry.sha} ${entry.message}\n`;
451+
}
452+
edit.insert(context.document.uri, new Position(newLine, 0), entryToInsert);
444453

445454
await workspace.applyEdit(edit);
446455
}
@@ -701,18 +710,20 @@ function parseRebaseTodoEntries(contentsOrDocument: string | TextDocument): Reba
701710
let action;
702711
let sha;
703712
let message;
713+
let branch;
704714

705715
do {
706716
match = rebaseCommandsRegex.exec(contents);
707717
if (match == null) break;
708718

709-
[, action, sha, message] = match;
719+
[, action, sha, message,branch] = match;
710720

711721
entries.push({
712722
index: match.index,
713723
action: rebaseActionsMap.get(action) ?? 'pick',
714724
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
715-
sha: ` ${sha}`.substr(1),
725+
sha: sha ? ` ${sha}`.substr(1) : `UpdateRefId${match.index}`,
726+
branch: ` ${branch}`,
716727
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
717728
message: message == null || message.length === 0 ? '' : ` ${message}`.substr(1),
718729
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /