added a warning when user tries to commit, and there are unsaved files

This commit is contained in:
Pradeep Murugesan
2017-10-16 15:47:22 +02:00
parent b22bd4778f
commit 3a10793dad
2 changed files with 14 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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;
}