git-er-done 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-er-done",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Utility for dealing with modified, created, deleted files since a git commit",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -33,6 +33,10 @@
|
|
|
33
33
|
"types": "./types/git/getGitRoot.d.ts",
|
|
34
34
|
"default": "./src/git/getGitRoot.js"
|
|
35
35
|
},
|
|
36
|
+
"./get-current-branch": {
|
|
37
|
+
"types": "./types/git/getCurrentBranch.d.ts",
|
|
38
|
+
"default": "./src/git/getCurrentBranch.js"
|
|
39
|
+
},
|
|
36
40
|
"./get-files": {
|
|
37
41
|
"types": "./types/git/getGitFiles.d.ts",
|
|
38
42
|
"default": "./src/git/getGitFiles.js"
|
|
@@ -75,7 +79,7 @@
|
|
|
75
79
|
"dependencies": {
|
|
76
80
|
"debug": "^4.1.1",
|
|
77
81
|
"json5": "^2.1.1",
|
|
78
|
-
"jsonpointer": "^
|
|
82
|
+
"jsonpointer": "^5.0.1",
|
|
79
83
|
"lodash.includes": "^4.3.0",
|
|
80
84
|
"lodash.isobject": "^3.0.2",
|
|
81
85
|
"lodash.keys": "^4.2.0",
|
|
@@ -83,17 +87,17 @@
|
|
|
83
87
|
"lodash.memoize": "^4.1.2",
|
|
84
88
|
"micromatch": "^4.0.2",
|
|
85
89
|
"parse-diff": "^0.6.0",
|
|
86
|
-
"rfc6902": "^
|
|
90
|
+
"rfc6902": "^5.1.2"
|
|
87
91
|
},
|
|
88
92
|
"repository": {
|
|
89
93
|
"type": "git",
|
|
90
94
|
"url": "https://github.com/DavidWells/components/tree/master/packages/util-git-info"
|
|
91
95
|
},
|
|
92
96
|
"devDependencies": {
|
|
93
|
-
"@davidwells/extract-deps": "^0.0.
|
|
97
|
+
"@davidwells/extract-deps": "^0.0.6",
|
|
94
98
|
"@davidwells/git-split-diffs": "^2.2.1",
|
|
95
99
|
"@types/node": "^22.10.1",
|
|
96
|
-
"configorama": "^0.
|
|
100
|
+
"configorama": "^0.7.1",
|
|
97
101
|
"minimatch": "^10.0.1",
|
|
98
102
|
"typescript": "^5.7.2",
|
|
99
103
|
"uvu": "^0.5.6"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Gets the current git branch name
|
|
2
|
+
const { executeCommand } = require('./utils/exec')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gets the current branch name of the git repository
|
|
6
|
+
* @returns {Promise<string>} A promise that resolves to the current branch name
|
|
7
|
+
*/
|
|
8
|
+
function getCurrentBranch() {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
executeCommand('git rev-parse --abbrev-ref HEAD', (err, res) => {
|
|
11
|
+
if (err) return reject(err)
|
|
12
|
+
resolve(res.trim())
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
if (require.main === module) {
|
|
19
|
+
getCurrentBranch().then(res => {
|
|
20
|
+
console.log('getCurrentBranch', res)
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
/** */
|
|
24
|
+
|
|
25
|
+
module.exports = { getCurrentBranch }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Tests for getCurrentBranch utility
|
|
2
|
+
const { test } = require('uvu')
|
|
3
|
+
const assert = require('uvu/assert')
|
|
4
|
+
const { getCurrentBranch } = require('./getCurrentBranch')
|
|
5
|
+
|
|
6
|
+
test('getCurrentBranch returns a string', async () => {
|
|
7
|
+
const branch = await getCurrentBranch()
|
|
8
|
+
assert.type(branch, 'string')
|
|
9
|
+
assert.ok(branch.length > 0, 'branch name should not be empty')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
test('getCurrentBranch returns expected branch name', async () => {
|
|
13
|
+
const branch = await getCurrentBranch()
|
|
14
|
+
// We're on master based on git status
|
|
15
|
+
assert.is(branch, 'master')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test.run()
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Tests for rfc6902 and jsonpointer usage (used in gitJSONToGitDSL)
|
|
2
|
+
const { test } = require('uvu')
|
|
3
|
+
const assert = require('uvu/assert')
|
|
4
|
+
const jsonDiff = require('rfc6902')
|
|
5
|
+
const jsonpointer = require('jsonpointer')
|
|
6
|
+
|
|
7
|
+
// Tests for rfc6902.createPatch - used in JSONPatchForFile
|
|
8
|
+
test('rfc6902.createPatch detects added keys', () => {
|
|
9
|
+
const before = { name: 'test' }
|
|
10
|
+
const after = { name: 'test', version: '1.0.0' }
|
|
11
|
+
const patch = jsonDiff.createPatch(before, after)
|
|
12
|
+
|
|
13
|
+
assert.is(patch.length, 1)
|
|
14
|
+
assert.is(patch[0].op, 'add')
|
|
15
|
+
assert.is(patch[0].path, '/version')
|
|
16
|
+
assert.is(patch[0].value, '1.0.0')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('rfc6902.createPatch detects removed keys', () => {
|
|
20
|
+
const before = { name: 'test', version: '1.0.0' }
|
|
21
|
+
const after = { name: 'test' }
|
|
22
|
+
const patch = jsonDiff.createPatch(before, after)
|
|
23
|
+
|
|
24
|
+
assert.is(patch.length, 1)
|
|
25
|
+
assert.is(patch[0].op, 'remove')
|
|
26
|
+
assert.is(patch[0].path, '/version')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('rfc6902.createPatch detects changed values', () => {
|
|
30
|
+
const before = { version: '1.0.0' }
|
|
31
|
+
const after = { version: '2.0.0' }
|
|
32
|
+
const patch = jsonDiff.createPatch(before, after)
|
|
33
|
+
|
|
34
|
+
assert.is(patch.length, 1)
|
|
35
|
+
assert.is(patch[0].op, 'replace')
|
|
36
|
+
assert.is(patch[0].path, '/version')
|
|
37
|
+
assert.is(patch[0].value, '2.0.0')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('rfc6902.createPatch handles nested objects', () => {
|
|
41
|
+
const before = { deps: { lodash: '4.0.0' } }
|
|
42
|
+
const after = { deps: { lodash: '4.0.0', axios: '1.0.0' } }
|
|
43
|
+
const patch = jsonDiff.createPatch(before, after)
|
|
44
|
+
|
|
45
|
+
assert.is(patch.length, 1)
|
|
46
|
+
assert.is(patch[0].op, 'add')
|
|
47
|
+
assert.is(patch[0].path, '/deps/axios')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('rfc6902.createPatch handles arrays', () => {
|
|
51
|
+
const before = { items: ['a', 'b'] }
|
|
52
|
+
const after = { items: ['a', 'b', 'c'] }
|
|
53
|
+
const patch = jsonDiff.createPatch(before, after)
|
|
54
|
+
|
|
55
|
+
assert.is(patch.length, 1)
|
|
56
|
+
assert.is(patch[0].op, 'add')
|
|
57
|
+
assert.is(patch[0].path, '/items/-') // RFC 6902 uses - for array append
|
|
58
|
+
assert.is(patch[0].value, 'c')
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('rfc6902.createPatch returns empty array for identical objects', () => {
|
|
62
|
+
const obj = { name: 'test', version: '1.0.0' }
|
|
63
|
+
const patch = jsonDiff.createPatch(obj, obj)
|
|
64
|
+
|
|
65
|
+
assert.is(patch.length, 0)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Tests for jsonpointer.get - used in JSONDiffForFile
|
|
69
|
+
test('jsonpointer.get retrieves root level values', () => {
|
|
70
|
+
const obj = { name: 'test', version: '1.0.0' }
|
|
71
|
+
|
|
72
|
+
assert.is(jsonpointer.get(obj, '/name'), 'test')
|
|
73
|
+
assert.is(jsonpointer.get(obj, '/version'), '1.0.0')
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test('jsonpointer.get retrieves nested values', () => {
|
|
77
|
+
const obj = { deps: { lodash: '4.0.0' } }
|
|
78
|
+
|
|
79
|
+
assert.is(jsonpointer.get(obj, '/deps/lodash'), '4.0.0')
|
|
80
|
+
assert.equal(jsonpointer.get(obj, '/deps'), { lodash: '4.0.0' })
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('jsonpointer.get retrieves array elements', () => {
|
|
84
|
+
const obj = { items: ['a', 'b', 'c'] }
|
|
85
|
+
|
|
86
|
+
assert.is(jsonpointer.get(obj, '/items/0'), 'a')
|
|
87
|
+
assert.is(jsonpointer.get(obj, '/items/2'), 'c')
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('jsonpointer.get returns undefined for missing paths', () => {
|
|
91
|
+
const obj = { name: 'test' }
|
|
92
|
+
|
|
93
|
+
assert.is(jsonpointer.get(obj, '/missing'), undefined)
|
|
94
|
+
assert.is(jsonpointer.get(obj, '/deep/missing/path'), undefined)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// Tests for jsonpointer.set - used in JSONDiffForFile
|
|
98
|
+
test('jsonpointer.set creates root level values', () => {
|
|
99
|
+
const obj = {}
|
|
100
|
+
jsonpointer.set(obj, '/name', 'test')
|
|
101
|
+
|
|
102
|
+
assert.is(obj.name, 'test')
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
test('jsonpointer.set creates nested values', () => {
|
|
106
|
+
const obj = { deps: {} }
|
|
107
|
+
jsonpointer.set(obj, '/deps/lodash', '4.0.0')
|
|
108
|
+
|
|
109
|
+
assert.is(obj.deps.lodash, '4.0.0')
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('jsonpointer.set overwrites existing values', () => {
|
|
113
|
+
const obj = { version: '1.0.0' }
|
|
114
|
+
jsonpointer.set(obj, '/version', '2.0.0')
|
|
115
|
+
|
|
116
|
+
assert.is(obj.version, '2.0.0')
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Integration test - simulates JSONDiffForFile behavior
|
|
120
|
+
test('integration: build diff object from patches', () => {
|
|
121
|
+
const before = {
|
|
122
|
+
name: 'my-pkg',
|
|
123
|
+
dependencies: { lodash: '4.0.0' }
|
|
124
|
+
}
|
|
125
|
+
const after = {
|
|
126
|
+
name: 'my-pkg',
|
|
127
|
+
dependencies: { lodash: '4.0.0', axios: '1.0.0' }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const patches = jsonDiff.createPatch(before, after)
|
|
131
|
+
const result = Object.create(null)
|
|
132
|
+
|
|
133
|
+
for (const patch of patches) {
|
|
134
|
+
const pathSteps = patch.path.split('/')
|
|
135
|
+
const backAStepPath = pathSteps.length <= 2
|
|
136
|
+
? patch.path
|
|
137
|
+
: pathSteps.slice(0, pathSteps.length - 1).join('/')
|
|
138
|
+
|
|
139
|
+
const diff = {
|
|
140
|
+
before: jsonpointer.get(before, backAStepPath) || null,
|
|
141
|
+
after: jsonpointer.get(after, backAStepPath) || null
|
|
142
|
+
}
|
|
143
|
+
jsonpointer.set(result, backAStepPath, diff)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
assert.equal(result.dependencies, {
|
|
147
|
+
before: { lodash: '4.0.0' },
|
|
148
|
+
after: { lodash: '4.0.0', axios: '1.0.0' }
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test.run()
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const { getLastCommit } = require('./git/commits/getLastCommit')
|
|
|
5
5
|
const { getAllCommits } = require('./git/commits/getAllCommits')
|
|
6
6
|
const { getGitFiles } = require('./git/getGitFiles')
|
|
7
7
|
const { getGitRoot } = require('./git/getGitRoot')
|
|
8
|
+
const { getCurrentBranch } = require('./git/getCurrentBranch')
|
|
8
9
|
const { getRemotes, getRemote } = require('./git/remotes/getRemotes')
|
|
9
10
|
const { getFileAtCommit } = require('./git/getFileAtCommit')
|
|
10
11
|
const {
|
|
@@ -17,6 +18,7 @@ module.exports = {
|
|
|
17
18
|
// Get Git Details
|
|
18
19
|
gitDetails,
|
|
19
20
|
getGitRoot,
|
|
21
|
+
getCurrentBranch,
|
|
20
22
|
// Get Commits
|
|
21
23
|
getCommit,
|
|
22
24
|
getAllCommits,
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { gitDetails } from "./git/getDetails";
|
|
2
2
|
import { getGitRoot } from "./git/getGitRoot";
|
|
3
|
+
import { getCurrentBranch } from "./git/getCurrentBranch";
|
|
3
4
|
import { getCommit } from "./git/commits/getCommit";
|
|
4
5
|
import { getAllCommits } from "./git/commits/getAllCommits";
|
|
5
6
|
import { getFirstCommit } from "./git/commits/getFirstCommit";
|
|
@@ -11,4 +12,4 @@ import { getFileCreatedTimeStamp } from "./git/dates/getFileDates";
|
|
|
11
12
|
import { getFileDates } from "./git/dates/getFileDates";
|
|
12
13
|
import { getRemotes } from "./git/remotes/getRemotes";
|
|
13
14
|
import { getRemote } from "./git/remotes/getRemotes";
|
|
14
|
-
export { gitDetails, getGitRoot, getCommit, getAllCommits, getFirstCommit, getLastCommit, getGitFiles, getFileAtCommit, getFileModifiedTimeStamp, getFileCreatedTimeStamp, getFileDates, getRemotes, getRemote };
|
|
15
|
+
export { gitDetails, getGitRoot, getCurrentBranch, getCommit, getAllCommits, getFirstCommit, getLastCommit, getGitFiles, getFileAtCommit, getFileModifiedTimeStamp, getFileCreatedTimeStamp, getFileDates, getRemotes, getRemote };
|