mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
added a warning when user tries to commit, and there are unsaved files
This commit is contained in:
@@ -10,7 +10,7 @@ import { Ref, RefType, Git, GitErrorCodes, Branch } from './git';
|
||||
import { Repository, Resource, Status, CommitOptions, ResourceGroupType } from './repository';
|
||||
import { Model } from './model';
|
||||
import { toGitUri, fromGitUri } from './uri';
|
||||
import { grep } from './util';
|
||||
import { grep, hasUnSavedFiles } from './util';
|
||||
import { applyLineChanges, intersectDiffWithRange, toLineRanges, invertLineChange } from './staging';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
@@ -927,6 +927,12 @@ export class CommandCenter {
|
||||
const noStagedChanges = repository.indexGroup.resourceStates.length === 0;
|
||||
const noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0;
|
||||
|
||||
if (hasUnSavedFiles()) {
|
||||
const message = localize('unsaved files', "There are some unsaved files.\n\n Save the files before proceeding");
|
||||
window.showInformationMessage(message, { modal: true });
|
||||
return false;
|
||||
}
|
||||
|
||||
// no changes, and the user has not configured to commit all in this case
|
||||
if (!noUnstagedChanges && noStagedChanges && !enableSmartCommit) {
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { Event } from 'vscode';
|
||||
import { Event, workspace } from 'vscode';
|
||||
import { dirname } from 'path';
|
||||
import { Readable } from 'stream';
|
||||
import * as fs from 'fs';
|
||||
@@ -273,4 +273,10 @@ export function detectUnicodeEncoding(buffer: Buffer): Encoding | null {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function hasUnSavedFiles(): boolean {
|
||||
return workspace.textDocuments
|
||||
.filter(textDocument => !textDocument.isUntitled && textDocument.isDirty)
|
||||
.length > 0;
|
||||
}
|
||||
Reference in New Issue
Block a user