Compare commits
No commits in common. "master" and "v3.0.3" have entirely different histories.
63
changelog.md
63
changelog.md
@ -1,63 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
## 2024-06-23 - 3.1.1 - fix(documentation)
|
|
||||||
Remove outdated changelog entries
|
|
||||||
|
|
||||||
## 2024-06-23 - 3.1.0 - gitrepo
|
|
||||||
Enhancements and fixes to GitRepo
|
|
||||||
|
|
||||||
- Enhance GitRepo to include commit date and version information
|
|
||||||
|
|
||||||
## 2024-06-22 - 3.0.3 to 3.0.4 - core & GitRepo
|
|
||||||
General updates and new feature addition
|
|
||||||
|
|
||||||
- Fixed core functionality
|
|
||||||
- Added diff function in GitRepo
|
|
||||||
|
|
||||||
## 2023-11-15 - 3.0.1 to 3.0.2 - core, tsconfig, npmextra
|
|
||||||
Minor updates and fixes
|
|
||||||
|
|
||||||
- Fixed core functionality
|
|
||||||
- Updated tsconfig and npmextra.json
|
|
||||||
|
|
||||||
## 2023-07-10 - 3.0.0 - core
|
|
||||||
Structural changes to organization scheme
|
|
||||||
|
|
||||||
- Switched to a new organizational scheme
|
|
||||||
|
|
||||||
## 2023-07-27 - 3.0.0 to 3.0.1 - core
|
|
||||||
Structural changes and updates
|
|
||||||
|
|
||||||
- Fixed core functionality
|
|
||||||
- Switched to new organizational scheme
|
|
||||||
|
|
||||||
## 2022-07-31 - 2.0.2 to 3.0.0 - core
|
|
||||||
Breaking changes and updates
|
|
||||||
|
|
||||||
- Switching to ESM for core
|
|
||||||
- Fixed core functionality
|
|
||||||
|
|
||||||
## 2021-10-22 - 1.0.18 to 2.0.1 - dependencies, core
|
|
||||||
Breaking changes and updates
|
|
||||||
|
|
||||||
- Switched to isomorphic git dependencies
|
|
||||||
- Fixed core functionality
|
|
||||||
|
|
||||||
## 2020-08-15 - 1.0.14 to 1.0.18 - core
|
|
||||||
Fixes
|
|
||||||
|
|
||||||
- Fixed core functionality in multiple patches
|
|
||||||
|
|
||||||
## 2019-06-18 - 1.0.5 to 1.0.10 - core
|
|
||||||
Fixes
|
|
||||||
|
|
||||||
- Fixed core functionality in multiple patches
|
|
||||||
|
|
||||||
## 2016-06-23 - 0.0.10 to 0.1.11 - gitlab & other fixes
|
|
||||||
Initial implementations and setup
|
|
||||||
|
|
||||||
- Fixed README and merge issues
|
|
||||||
- Updated gitlab.yml and CI settings
|
|
||||||
- Implemented new class approach and other updates
|
|
||||||
- Removed unnecessary imports, postinstall
|
|
||||||
- Added npmextra.json, CI tests, SSH key support
|
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartgit",
|
"name": "@push.rocks/smartgit",
|
||||||
"version": "3.1.1",
|
"version": "3.0.3",
|
||||||
"description": "A smart wrapper for nodegit that simplifies Git operations in Node.js.",
|
"description": "A smart wrapper for nodegit that simplifies Git operations in Node.js.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
@ -38,7 +38,6 @@
|
|||||||
"@push.rocks/smartpromise": "^4.0.2",
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
"@push.rocks/smartshell": "^3.0.5",
|
"@push.rocks/smartshell": "^3.0.5",
|
||||||
"@push.rocks/smartstring": "^4.0.15",
|
"@push.rocks/smartstring": "^4.0.15",
|
||||||
"@push.rocks/smarttime": "^4.0.6",
|
|
||||||
"@types/diff": "^5.2.1",
|
"@types/diff": "^5.2.1",
|
||||||
"@types/minimatch": "^5.1.2",
|
"@types/minimatch": "^5.1.2",
|
||||||
"diff": "^5.2.0",
|
"diff": "^5.2.0",
|
||||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -26,9 +26,6 @@ importers:
|
|||||||
'@push.rocks/smartstring':
|
'@push.rocks/smartstring':
|
||||||
specifier: ^4.0.15
|
specifier: ^4.0.15
|
||||||
version: 4.0.15
|
version: 4.0.15
|
||||||
'@push.rocks/smarttime':
|
|
||||||
specifier: ^4.0.6
|
|
||||||
version: 4.0.6
|
|
||||||
'@types/diff':
|
'@types/diff':
|
||||||
specifier: ^5.2.1
|
specifier: ^5.2.1
|
||||||
version: 5.2.1
|
version: 5.2.1
|
||||||
|
14
test/test.ts
14
test/test.ts
@ -34,18 +34,4 @@ tap.test('should open a repo', async () => {
|
|||||||
console.log(diff);
|
console.log(diff);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get the diff to HEAD', async () => {
|
|
||||||
const gitRepo = await testSmartgitInstance.createRepoByOpen(packageDir);
|
|
||||||
const diff = await gitRepo.getUncommittedDiff([
|
|
||||||
'pnpm-lock.yaml',
|
|
||||||
]);
|
|
||||||
console.log(diff);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should print all commit messages', async () => {
|
|
||||||
const gitRepo = await testSmartgitInstance.createRepoByOpen(packageDir);
|
|
||||||
const commitMessages = await gitRepo.getAllCommitMessages();
|
|
||||||
console.log(commitMessages);
|
|
||||||
});
|
|
||||||
|
|
||||||
await tap.start();
|
await tap.start();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @push.rocks/commitinfo
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartgit',
|
name: '@push.rocks/smartgit',
|
||||||
version: '3.1.1',
|
version: '3.0.3',
|
||||||
description: 'A smart wrapper for nodegit that simplifies Git operations in Node.js.'
|
description: 'A smart wrapper for nodegit that simplifies Git operations in Node.js.'
|
||||||
}
|
}
|
||||||
|
@ -131,98 +131,45 @@ export class GitRepo {
|
|||||||
|
|
||||||
// Handle modified files
|
// Handle modified files
|
||||||
if (head !== 0 && workdir !== 0 && head !== workdir) {
|
if (head !== 0 && workdir !== 0 && head !== workdir) {
|
||||||
headContent = await plugins.isomorphicGit
|
headContent = await plugins.isomorphicGit.readBlob({
|
||||||
.readBlob({
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
dir: this.repoDir,
|
||||||
|
oid: await plugins.isomorphicGit.resolveRef({
|
||||||
fs: this.smartgitRef.envDeps.fs,
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
dir: this.repoDir,
|
dir: this.repoDir,
|
||||||
oid: await plugins.isomorphicGit.resolveRef({
|
ref: 'HEAD',
|
||||||
fs: this.smartgitRef.envDeps.fs,
|
}),
|
||||||
dir: this.repoDir,
|
filepath,
|
||||||
ref: 'HEAD',
|
}).then(result => new TextDecoder().decode(result.blob));
|
||||||
}),
|
|
||||||
filepath,
|
|
||||||
})
|
|
||||||
.then((result) => new TextDecoder().decode(result.blob));
|
|
||||||
|
|
||||||
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(
|
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(plugins.path.join(this.repoDir, filepath), 'utf8');
|
||||||
plugins.path.join(this.repoDir, filepath),
|
|
||||||
'utf8'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle added files
|
// Handle added files
|
||||||
if (head === 0 && workdir !== 0) {
|
if (head === 0 && workdir !== 0) {
|
||||||
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(
|
workdirContent = await this.smartgitRef.envDeps.fs.promises.readFile(plugins.path.join(this.repoDir, filepath), 'utf8');
|
||||||
plugins.path.join(this.repoDir, filepath),
|
|
||||||
'utf8'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle deleted files
|
// Handle deleted files
|
||||||
if (head !== 0 && workdir === 0) {
|
if (head !== 0 && workdir === 0) {
|
||||||
headContent = await plugins.isomorphicGit
|
headContent = await plugins.isomorphicGit.readBlob({
|
||||||
.readBlob({
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
|
dir: this.repoDir,
|
||||||
|
oid: await plugins.isomorphicGit.resolveRef({
|
||||||
fs: this.smartgitRef.envDeps.fs,
|
fs: this.smartgitRef.envDeps.fs,
|
||||||
dir: this.repoDir,
|
dir: this.repoDir,
|
||||||
oid: await plugins.isomorphicGit.resolveRef({
|
ref: 'HEAD',
|
||||||
fs: this.smartgitRef.envDeps.fs,
|
}),
|
||||||
dir: this.repoDir,
|
filepath,
|
||||||
ref: 'HEAD',
|
}).then(result => new TextDecoder().decode(result.blob));
|
||||||
}),
|
|
||||||
filepath,
|
|
||||||
})
|
|
||||||
.then((result) => new TextDecoder().decode(result.blob));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headContent || workdirContent) {
|
if (headContent || workdirContent) {
|
||||||
const diff = plugins.diff.createTwoFilesPatch(
|
const diff = plugins.diff.createTwoFilesPatch(filepath, filepath, headContent, workdirContent);
|
||||||
filepath,
|
|
||||||
filepath,
|
|
||||||
headContent,
|
|
||||||
workdirContent
|
|
||||||
);
|
|
||||||
diffs.push(diff);
|
diffs.push(diff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return diffs;
|
return diffs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all commit messages with their dates and package.json version at each commit
|
|
||||||
*/
|
|
||||||
public async getAllCommitMessages(): Promise<
|
|
||||||
{ date: string; version: string; message: string }[]
|
|
||||||
> {
|
|
||||||
const commits = await plugins.isomorphicGit.log({
|
|
||||||
fs: this.smartgitRef.envDeps.fs,
|
|
||||||
dir: this.repoDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
const results = [];
|
|
||||||
|
|
||||||
for (const commit of commits) {
|
|
||||||
let version = 'unknown';
|
|
||||||
try {
|
|
||||||
const packageJsonBlob = await plugins.isomorphicGit.readBlob({
|
|
||||||
fs: this.smartgitRef.envDeps.fs,
|
|
||||||
dir: this.repoDir,
|
|
||||||
oid: commit.oid,
|
|
||||||
filepath: 'package.json',
|
|
||||||
});
|
|
||||||
const packageJson = JSON.parse(new TextDecoder().decode(packageJsonBlob.blob));
|
|
||||||
version = packageJson.version;
|
|
||||||
} catch (error) {
|
|
||||||
// If package.json does not exist or any error occurs, leave version as 'unknown'
|
|
||||||
}
|
|
||||||
|
|
||||||
results.push({
|
|
||||||
date: new plugins.smarttime.ExtendedDate(commit.commit.committer.timestamp * 1000).exportToHyphedSortableDate(),
|
|
||||||
version: version,
|
|
||||||
message: commit.commit.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,8 @@ import * as smartfile from '@push.rocks/smartfile';
|
|||||||
import * as smartpath from '@push.rocks/smartpath';
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
import * as smartpromise from '@push.rocks/smartpromise';
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
import * as smartstring from '@push.rocks/smartstring';
|
import * as smartstring from '@push.rocks/smartstring';
|
||||||
import * as smarttime from '@push.rocks/smarttime';
|
|
||||||
|
|
||||||
export { smartenv, smartfile, smartpath, smartpromise, smartstring, smarttime };
|
export { smartenv, smartfile, smartpath, smartpromise, smartstring };
|
||||||
|
|
||||||
// third party
|
// third party
|
||||||
import * as diff from 'diff';
|
import * as diff from 'diff';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user