Skip to content

Commit

Permalink
added a warning when user tries to commit, and there are unsaved files
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepmurugesan committed Nov 21, 2017
1 parent b22bd47 commit 3a10793
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {

Expand Down
8 changes: 7 additions & 1 deletion extensions/git/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}

0 comments on commit 3a10793

Please sign in to comment.