Skip to content

Commit 9ec4ee4

Browse files
committed
git commands, show mode changes in workspace
1 parent cd5450e commit 9ec4ee4

File tree

8 files changed

+108
-72
lines changed

8 files changed

+108
-72
lines changed

airflow_code_editor/git.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def prepare_git_env() -> Dict[str, str]:
248248
# Don't prompt on the terminal
249249
env['GIT_TERMINAL_PROMPT'] = '0'
250250
env['GIT_ASKPASS'] = '/bin/true'
251+
env['GIT_EDITOR'] = '/bin/false'
251252
# Author
252253
git_author_name = get_plugin_config('git_author_name')
253254
if not git_author_name:

airflow_code_editor/static/airflow_code_editor.js

Lines changed: 52 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airflow_code_editor/static/airflow_code_editor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airflow_code_editor/static/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commons.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ export function showNotification(options) {
6464
});
6565
}
6666

67+
export function showError(message, options) {
68+
if (vueApp) {
69+
vueApp.showError(message, options);
70+
}
71+
}
72+
73+
export function showWarning(message, options) {
74+
if (vueApp) {
75+
options = (options !== undefined) ? options : {};
76+
options['type'] = options.type || 'warning';
77+
vueApp.showError(message, options);
78+
}
79+
}
80+
6781
export function normalize(path) {
6882
if (path[0] != '/') {
6983
path = '/' + path;
@@ -128,24 +142,42 @@ export function initCsrfToken(tokenParam) {
128142

129143
export async function git_async(args, options) {
130144
options = (options !== undefined) ? options : {};
145+
const title = options?.title || 'Git';
131146
const payload = { args: [].concat.apply([], args.filter(x => x != null)) }; // flat the array
132-
const pre = (options.type == 'terminal') ? '$ git ' + payload.args.join(' ') + '\n' : '';
147+
const command = '$ git ' + payload.args.join(' ') + '\n';
133148
try {
134149
const response = await axios.post(prepareHref('repo'), payload);
135150
if (response.data.returncode != 0) {
136-
const message = pre + response.data.error.message;
137-
showNotification({ title: options?.title || 'Git', message: message, type: 'error' });
151+
const message = response.data?.error?.message || response.data?.data;
152+
if (options?.type == 'terminal') {
153+
showWarning(command + message, options);
154+
} else {
155+
showNotification({ title: title, message: message, type: 'error' });
156+
}
138157
return null;
139158
}
140159
// Return code is 0 but there is stderr output: this is a warning message
141160
if (response.data.error) {
142-
const message = pre + response.data.error.message;
143-
showNotification({ title: options?.title || 'Git', message: message, type: 'warn' });
161+
const message = response.data.error.message;
162+
if (options?.type == 'terminal') {
163+
showWarning(command + message, options);
164+
} else {
165+
showNotification({ title: title, message: message, type: 'warn' });
166+
}
167+
}
168+
if (options?.forceTerminal) {
169+
// Force terminal output
170+
const message = command + response.data.data;
171+
showWarning(message, options);
144172
}
145173
return response.data.data
146174
} catch(error) {
147-
const message = error.response && error.response.data.error ? error.response.data.error.message : error;
148-
showNotification({ title: options?.title || 'Git', message: message, type: 'error' });
175+
const message = error?.response?.data?.error?.message || error;
176+
if (options?.type == 'terminal') {
177+
showError(message, options);
178+
} else {
179+
showNotification({ title: title, message: message, type: 'error' });
180+
}
149181
return null;
150182
}
151183
}

src/components/ShowDiff.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
display: block;
1313
flex: 1;
1414
overflow: auto;
15-
background-color: #fff;
15+
background-color: #f2f2f2;
16+
padding-top: 1em;
1617
}
1718
.show-diff {
1819
font-family: monospace;
@@ -22,13 +23,11 @@
2223
padding-left: 2em;
2324
}
2425
.show-diff .diff-file-header {
25-
font-weight: bold;
26-
line-height: 3.6em;
2726
padding-left: 1em;
28-
border-bottom: 1px solid #eee;
29-
margin-bottom: 1em;
30-
background-color: #f6f6f6;
31-
font-family: sans-serif;
27+
font-family: monospace;
28+
}
29+
.show-diff .diff-filename{
30+
font-weight: bold;
3231
}
3332
.show-diff .diff-line-add {
3433
background-color: #e6ffec;
@@ -62,12 +61,14 @@ export default defineComponent({
6261
let classes = '';
6362
let skip = false;
6463
if ((!this.inFileHeader) && (line.startsWith('diff --git'))) {
65-
skip = true;
64+
//skip = true;
6665
this.inFileHeader = true;
6766
} else if (this.inFileHeader) { // file header
68-
skip = true;
67+
//skip = true;
68+
this.inFileHeader = true;
69+
classes += " diff-file-header";
6970
if (line.startsWith('+++ ')) { // filename
70-
classes += " diff-file-header";
71+
classes += " diff-filename";
7172
line = line.substring(5);
7273
if (line.startsWith('dev/null')) {
7374
line = this.last.substring(5);

src/components/dialogs/ErrorDialog.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<style>
1313
.airflow-code-editor-modal-terminal {
1414
width: 95%;
15+
font-family: "Menlo", "Monaco", "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", serif;
16+
line-height: 1.4em;
1517
}
1618
.airflow-code-editor-modal-terminal label {
1719
white-space: pre;

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ window.search = async function(query) {
2828

2929
window.git = async function(args) {
3030
let gitArgs = shlex.split(args);
31-
let result = await git_async(gitArgs);
31+
let result = await git_async(gitArgs, {type: 'terminal', forceTerminal: true});
3232
if (result) {
3333
console.log(result);
3434
}

0 commit comments

Comments
 (0)