mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-29 09:35:41 -05:00
Reworks git abstraction and acccess
Adds commands module Adds git commit message to blame hover decorator
This commit is contained in:
89
src/git.ts
89
src/git.ts
@@ -4,59 +4,70 @@ import * as fs from 'fs';
|
||||
import * as tmp from 'tmp';
|
||||
import {spawnPromise} from 'spawn-rx';
|
||||
|
||||
export function gitNormalizePath(fileName: string, repoPath: string) {
|
||||
fileName = fileName.replace(/\\/g, '/');
|
||||
return isAbsolute(fileName) ? relative(repoPath, fileName) : fileName;
|
||||
function gitCommand(cwd: string, ...args) {
|
||||
return spawnPromise('git', args, { cwd: cwd });
|
||||
}
|
||||
|
||||
export function gitRepoPath(cwd) {
|
||||
return gitCommand(cwd, 'rev-parse', '--show-toplevel').then(data => data.replace(/\r?\n|\r/g, ''));
|
||||
}
|
||||
export default class Git {
|
||||
static normalizePath(fileName: string, repoPath: string) {
|
||||
fileName = fileName.replace(/\\/g, '/');
|
||||
return isAbsolute(fileName) ? relative(repoPath, fileName) : fileName;
|
||||
}
|
||||
|
||||
export function gitBlame(fileName: string, repoPath: string) {
|
||||
fileName = gitNormalizePath(fileName, repoPath);
|
||||
static repoPath(cwd: string) {
|
||||
return gitCommand(cwd, 'rev-parse', '--show-toplevel').then(data => data.replace(/\r?\n|\r/g, ''));
|
||||
}
|
||||
|
||||
console.log('git', 'blame', '-fnw', '--root', '--', fileName);
|
||||
return gitCommand(repoPath, 'blame', '-fnw', '--root', '--', fileName);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
static blame(fileName: string, repoPath: string) {
|
||||
fileName = Git.normalizePath(fileName, repoPath);
|
||||
|
||||
export function gitGetVersionFile(fileName: string, repoPath: string, sha: string) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
gitGetVersionText(fileName, repoPath, sha).then(data => {
|
||||
let ext = extname(fileName);
|
||||
tmp.file({ prefix: `${basename(fileName, ext)}-${sha}_`, postfix: ext }, (err, destination, fd, cleanupCallback) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
console.log('git', 'blame', '-fnw', '--root', '--', fileName);
|
||||
return gitCommand(repoPath, 'blame', '-fnw', '--root', '--', fileName);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
|
||||
console.log("File: ", destination);
|
||||
console.log("Filedescriptor: ", fd);
|
||||
|
||||
fs.appendFile(destination, data, err => {
|
||||
static getVersionedFile(fileName: string, repoPath: string, sha: string) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
Git.getVersionedFileText(fileName, repoPath, sha).then(data => {
|
||||
let ext = extname(fileName);
|
||||
tmp.file({ prefix: `${basename(fileName, ext)}-${sha}_`, postfix: ext }, (err, destination, fd, cleanupCallback) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(destination);
|
||||
|
||||
console.log("File: ", destination);
|
||||
console.log("Filedescriptor: ", fd);
|
||||
|
||||
fs.appendFile(destination, data, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(destination);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function gitGetVersionText(fileName: string, repoPath: string, sha: string) {
|
||||
fileName = gitNormalizePath(fileName, repoPath);
|
||||
sha = sha.replace('^', '');
|
||||
static getVersionedFileText(fileName: string, repoPath: string, sha: string) {
|
||||
fileName = Git.normalizePath(fileName, repoPath);
|
||||
sha = sha.replace('^', '');
|
||||
|
||||
console.log('git', 'show', `${sha}:${fileName}`);
|
||||
return gitCommand(repoPath, 'show', `${sha}:${fileName}`);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
console.log('git', 'show', `${sha}:${fileName}`);
|
||||
return gitCommand(repoPath, 'show', `${sha}:${fileName}`);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
|
||||
function gitCommand(cwd: string, ...args) {
|
||||
return spawnPromise('git', args, { cwd: cwd });
|
||||
static getCommitMessage(sha: string, repoPath: string) {
|
||||
sha = sha.replace('^', '');
|
||||
|
||||
console.log('git', 'show', '-s', '--format=%B', sha);
|
||||
return gitCommand(repoPath, 'show', '-s', '--format=%B', sha);
|
||||
// .then(s => { console.log(s); return s; })
|
||||
// .catch(ex => console.error(ex));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user