Sfoglia il codice sorgente

Fixes #381 - Unable to save stash with older Git

main
Eric Amodio 6 anni fa
parent
commit
85d9b500a6
4 ha cambiato i file con 24 aggiunte e 8 eliminazioni
  1. +5
    -0
      src/commands/stashSave.ts
  2. +1
    -1
      src/extension.ts
  3. +14
    -5
      src/gitService.ts
  4. +4
    -2
      src/system/version.ts

+ 5
- 0
src/commands/stashSave.ts Vedi File

@ -60,6 +60,11 @@ export class StashSaveCommand extends Command {
}
catch (ex) {
Logger.error(ex, 'StashSaveCommand');
const msg = ex && ex.message;
if (msg.includes('newer version of Git')) {
return window.showErrorMessage(`Unable to save stash. ${msg}`);
}
return window.showErrorMessage(`Unable to save stash. See output channel for more details`);
}
}

+ 1
- 1
src/extension.ts Vedi File

@ -299,7 +299,7 @@ async function migrateSettings(context: ExtensionContext, previousVersion: strin
}
function notifyOnUnsupportedGitVersion(version: string) {
if (GitService.validateGitVersion(2, 2)) return;
if (GitService.compareGitVersion('2.2.0') !== -1) return;
// If git is less than v2.2.0
Messages.showGitVersionUnsupportedErrorMessage(version);

+ 14
- 5
src/gitService.ts Vedi File

@ -1,5 +1,5 @@
'use strict';
import { Iterables, Objects, Strings, TernarySearchTree } from './system';
import { Iterables, Objects, Strings, TernarySearchTree, Versions } from './system';
import { ConfigurationChangeEvent, Disposable, Event, EventEmitter, Range, TextEditor, Uri, window, WindowState, workspace, WorkspaceFolder, WorkspaceFoldersChangeEvent } from 'vscode';
import { configuration, IRemotesConfig } from './configuration';
import { CommandContext, DocumentSchemes, setCommandContext } from './constants';
@ -1506,6 +1506,9 @@ export class GitService extends Disposable {
Logger.log(`stashSave('${repoPath}', '${message}', ${uris})`);
if (uris === undefined) return Git.stash_save(repoPath, message);
GitService.ensureGitVersion('2.13.2', 'Stashing individual files');
const pathspecs = uris.map(u => Git.splitPath(u.fsPath, repoPath)[0]);
return Git.stash_push(repoPath, pathspecs, message);
}
@ -1560,8 +1563,14 @@ export class GitService extends Disposable {
: sha;
}
static validateGitVersion(major: number, minor: number): boolean {
const [gitMajor, gitMinor] = this.getGitVersion().split('.');
return (parseInt(gitMajor, 10) >= major && parseInt(gitMinor, 10) >= minor);
static compareGitVersion(version: string, throwIfLessThan?: Error) {
return Versions.compare(Versions.fromString(this.getGitVersion()), Versions.fromString(version));
}
static ensureGitVersion(version: string, feature: string): void {
const gitVersion = this.getGitVersion();
if (Versions.compare(Versions.fromString(gitVersion), Versions.fromString(version)) === -1) {
throw new Error(`${feature} requires a newer version of Git (>= ${version}) than is currently installed (${gitVersion}). Please install a more recent version of Git to use this GitLens feature.`);
}
}
}
}

+ 4
- 2
src/system/version.ts Vedi File

@ -1,6 +1,8 @@
'use strict';
export namespace Versions {
declare type VersionComparisonResult = -1 | 0 | 1;
export interface Version {
major: number;
minor: number;
@ -8,7 +10,7 @@ export namespace Versions {
pre?: string;
}
export function compare(v1: Version, v2: Version): number {
export function compare(v1: Version, v2: Version): VersionComparisonResult {
if (v1.major > v2.major) return 1;
if (v1.major < v2.major) return -1;
@ -21,7 +23,7 @@ export namespace Versions {
if (v1.pre === undefined && v2.pre !== undefined) return 1;
if (v1.pre !== undefined && v2.pre === undefined) return -1;
if (v1.pre !== undefined && v2.pre !== undefined) return v1.pre.localeCompare(v2.pre);
if (v1.pre !== undefined && v2.pre !== undefined) return v1.pre.localeCompare(v2.pre) as VersionComparisonResult;
return 0;
}

Caricamento…
Annulla
Salva