resulgit 1.0.4 → 1.0.6
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/lib/blame.js +79 -0
- package/lib/errors.js +213 -0
- package/lib/hooks.js +251 -0
- package/lib/log-viz.js +188 -0
- package/lib/validation.js +260 -0
- package/package.json +4 -3
- package/resulgit.js +88 -79
package/lib/log-viz.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git Log Visualization
|
|
3
|
+
* Creates ASCII graph visualization of commit history
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generate ASCII graph for commit history
|
|
8
|
+
*/
|
|
9
|
+
function generateLogGraph(commits, options = {}) {
|
|
10
|
+
const { includeGraph = true, colors = true, maxCommits = 50 } = options
|
|
11
|
+
|
|
12
|
+
const COLORS = {
|
|
13
|
+
reset: '\x1b[0m',
|
|
14
|
+
yellow: '\x1b[33m',
|
|
15
|
+
cyan: '\x1b[36m',
|
|
16
|
+
green: '\x1b[32m',
|
|
17
|
+
blue: '\x1b[34m',
|
|
18
|
+
red: '\x1b[31m',
|
|
19
|
+
dim: '\x1b[2m',
|
|
20
|
+
bold: '\x1b[1m'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const limitedCommits = commits.slice(0, maxCommits)
|
|
24
|
+
const lines = []
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < limitedCommits.length; i++) {
|
|
27
|
+
const commit = limitedCommits[i]
|
|
28
|
+
const isFirst = i === 0
|
|
29
|
+
const isLast = i === limitedCommits.length - 1
|
|
30
|
+
|
|
31
|
+
// Graph symbols
|
|
32
|
+
let graph = ''
|
|
33
|
+
if (includeGraph) {
|
|
34
|
+
if (isFirst) {
|
|
35
|
+
graph = '* '
|
|
36
|
+
} else if (isLast) {
|
|
37
|
+
graph = '* '
|
|
38
|
+
} else {
|
|
39
|
+
graph = '* '
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Add branch lines
|
|
43
|
+
if (!isLast) {
|
|
44
|
+
graph = `${graph}`
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Commit ID
|
|
49
|
+
const commitId = (commit.id || commit._id || '').slice(0, 7)
|
|
50
|
+
const coloredId = colors ? `${COLORS.yellow}${commitId}${COLORS.reset}` : commitId
|
|
51
|
+
|
|
52
|
+
// Author
|
|
53
|
+
const author = commit.author?.name || 'Unknown'
|
|
54
|
+
const authorShort = author.slice(0, 20)
|
|
55
|
+
const coloredAuthor = colors ? `${COLORS.cyan}${authorShort}${COLORS.reset}` : authorShort
|
|
56
|
+
|
|
57
|
+
// Date
|
|
58
|
+
const date = commit.createdAt || commit.committer?.date || ''
|
|
59
|
+
const dateObj = new Date(date)
|
|
60
|
+
const relativeDate = getRelativeDate(dateObj)
|
|
61
|
+
const coloredDate = colors ? `${COLORS.green}${relativeDate}${COLORS.reset}` : relativeDate
|
|
62
|
+
|
|
63
|
+
// Message
|
|
64
|
+
const message = (commit.message || 'No message').split('\n')[0].slice(0, 80)
|
|
65
|
+
const coloredMessage = colors ? `${COLORS.bold}${message}${COLORS.reset}` : message
|
|
66
|
+
|
|
67
|
+
// Branch tags (if any)
|
|
68
|
+
const tags = []
|
|
69
|
+
if (commit.branches && commit.branches.length > 0) {
|
|
70
|
+
tags.push(...commit.branches.map(b => `branch: ${b}`))
|
|
71
|
+
}
|
|
72
|
+
if (commit.tags && commit.tags.length > 0) {
|
|
73
|
+
tags.push(...commit.tags.map(t => `tag: ${t}`))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let tagStr = ''
|
|
77
|
+
if (tags.length > 0) {
|
|
78
|
+
const tagText = tags.join(', ')
|
|
79
|
+
tagStr = colors ? ` ${COLORS.red}(${tagText})${COLORS.reset}` : ` (${tagText})`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Construct line
|
|
83
|
+
const line = `${graph}${coloredId} - ${coloredMessage}${tagStr} ${COLORS.dim}${coloredDate} ${coloredAuthor}${COLORS.reset}`
|
|
84
|
+
lines.push(line)
|
|
85
|
+
|
|
86
|
+
// Add connecting line if not last
|
|
87
|
+
if (!isLast && includeGraph) {
|
|
88
|
+
lines.push('|')
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (commits.length > maxCommits) {
|
|
93
|
+
lines.push('')
|
|
94
|
+
lines.push(`... ${commits.length - maxCommits} more commits`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return lines.join('\n')
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get relative date string
|
|
102
|
+
*/
|
|
103
|
+
function getRelativeDate(date) {
|
|
104
|
+
const now = new Date()
|
|
105
|
+
const diffMs = now - date
|
|
106
|
+
const diffSecs = Math.floor(diffMs / 1000)
|
|
107
|
+
const diffMins = Math.floor(diffSecs / 60)
|
|
108
|
+
const diffHours = Math.floor(diffMins / 60)
|
|
109
|
+
const diffDays = Math.floor(diffHours / 24)
|
|
110
|
+
const diffWeeks = Math.floor(diffDays / 7)
|
|
111
|
+
const diffMonths = Math.floor(diffDays / 30)
|
|
112
|
+
const diffYears = Math.floor(diffDays / 365)
|
|
113
|
+
|
|
114
|
+
if (diffYears > 0) return `${diffYears} year${diffYears > 1 ? 's' : ''} ago`
|
|
115
|
+
if (diffMonths > 0) return `${diffMonths} month${diffMonths > 1 ? 's' : ''} ago`
|
|
116
|
+
if (diffWeeks > 0) return `${diffWeeks} week${diffWeeks > 1 ? 's' : ''} ago`
|
|
117
|
+
if (diffDays > 0) return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`
|
|
118
|
+
if (diffHours > 0) return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`
|
|
119
|
+
if (diffMins > 0) return `${diffMins} minute${diffMins > 1 ? 's' : ''} ago`
|
|
120
|
+
return 'just now'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Format compact log (one line per commit)
|
|
125
|
+
*/
|
|
126
|
+
function formatCompactLog(commits, colors = true) {
|
|
127
|
+
const COLORS = {
|
|
128
|
+
reset: '\x1b[0m',
|
|
129
|
+
yellow: '\x1b[33m',
|
|
130
|
+
dim: '\x1b[2m'
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return commits.map(commit => {
|
|
134
|
+
const id = (commit.id || commit._id || '').slice(0, 7)
|
|
135
|
+
const message = (commit.message || 'No message').split('\n')[0].slice(0, 60)
|
|
136
|
+
|
|
137
|
+
if (colors) {
|
|
138
|
+
return `${COLORS.yellow}${id}${COLORS.reset} ${message}`
|
|
139
|
+
}
|
|
140
|
+
return `${id} ${message}`
|
|
141
|
+
}).join('\n')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Generate commit statistics
|
|
146
|
+
*/
|
|
147
|
+
function generateCommitStats(commits) {
|
|
148
|
+
const stats = {
|
|
149
|
+
totalCommits: commits.length,
|
|
150
|
+
authors: {},
|
|
151
|
+
datesRange: { earliest: null, latest: null },
|
|
152
|
+
commitsPerDay: {}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const commit of commits) {
|
|
156
|
+
// Author stats
|
|
157
|
+
const authorName = commit.author?.name || 'Unknown'
|
|
158
|
+
stats.authors[authorName] = (stats.authors[authorName] || 0) + 1
|
|
159
|
+
|
|
160
|
+
// Date stats
|
|
161
|
+
const date = new Date(commit.createdAt || commit.committer?.date || new Date())
|
|
162
|
+
if (!stats.datesRange.earliest || date < stats.datesRange.earliest) {
|
|
163
|
+
stats.datesRange.earliest = date
|
|
164
|
+
}
|
|
165
|
+
if (!stats.datesRange.latest || date > stats.datesRange.latest) {
|
|
166
|
+
stats.datesRange.latest = date
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Commits per day
|
|
170
|
+
const dayKey = date.toISOString().split('T')[0]
|
|
171
|
+
stats.commitsPerDay[dayKey] = (stats.commitsPerDay[dayKey] || 0) + 1
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Sort authors by commit count
|
|
175
|
+
stats.topAuthors = Object.entries(stats.authors)
|
|
176
|
+
.sort(([, a], [, b]) => b - a)
|
|
177
|
+
.slice(0, 5)
|
|
178
|
+
.map(([name, count]) => ({ name, commits: count }))
|
|
179
|
+
|
|
180
|
+
return stats
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = {
|
|
184
|
+
generateLogGraph,
|
|
185
|
+
formatCompactLog,
|
|
186
|
+
generateCommitStats,
|
|
187
|
+
getRelativeDate
|
|
188
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Validation Module
|
|
3
|
+
* Provides validation functions for user inputs to prevent security issues
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const path = require('path')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validates repository ID format
|
|
10
|
+
*/
|
|
11
|
+
function validateRepoId(repoId) {
|
|
12
|
+
if (!repoId || typeof repoId !== 'string') {
|
|
13
|
+
throw new Error('Invalid repository ID: must be a non-empty string')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Allow alphanumeric, hyphens, underscores, and UUIDs
|
|
17
|
+
const validPattern = /^[a-zA-Z0-9_-]+$/
|
|
18
|
+
if (!validPattern.test(repoId)) {
|
|
19
|
+
throw new Error('Invalid repository ID: contains invalid characters')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (repoId.length > 100) {
|
|
23
|
+
throw new Error('Invalid repository ID: too long (max 100 characters)')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return repoId.trim()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Validates branch name format
|
|
31
|
+
*/
|
|
32
|
+
function validateBranchName(branchName) {
|
|
33
|
+
if (!branchName || typeof branchName !== 'string') {
|
|
34
|
+
throw new Error('Invalid branch name: must be a non-empty string')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const trimmed = branchName.trim()
|
|
38
|
+
|
|
39
|
+
// Git branch naming rules
|
|
40
|
+
const invalidPatterns = [
|
|
41
|
+
/\.\./, // No double dots
|
|
42
|
+
/\/$/, // Cannot end with /
|
|
43
|
+
/^\//, // Cannot start with /
|
|
44
|
+
/\@\{/, // No @{
|
|
45
|
+
/\\/, // No backslash
|
|
46
|
+
/[\x00-\x1f\x7f]/, // No control characters
|
|
47
|
+
/[\s~^:?*\[]/, // No whitespace or special chars
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
for (const pattern of invalidPatterns) {
|
|
51
|
+
if (pattern.test(trimmed)) {
|
|
52
|
+
throw new Error(`Invalid branch name: "${branchName}" violates Git naming rules`)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (trimmed.length > 255) {
|
|
57
|
+
throw new Error('Invalid branch name: too long (max 255 characters)')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return trimmed
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Validates file path to prevent path traversal attacks
|
|
65
|
+
*/
|
|
66
|
+
function validateFilePath(filePath, allowAbsolute = false) {
|
|
67
|
+
if (!filePath || typeof filePath !== 'string') {
|
|
68
|
+
throw new Error('Invalid file path: must be a non-empty string')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const normalized = path.normalize(filePath)
|
|
72
|
+
|
|
73
|
+
// Prevent path traversal
|
|
74
|
+
if (normalized.includes('..')) {
|
|
75
|
+
throw new Error('Invalid file path: path traversal detected')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Check for absolute paths if not allowed
|
|
79
|
+
if (!allowAbsolute && path.isAbsolute(normalized)) {
|
|
80
|
+
throw new Error('Invalid file path: absolute paths not allowed')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Prevent null bytes
|
|
84
|
+
if (normalized.includes('\0')) {
|
|
85
|
+
throw new Error('Invalid file path: null byte detected')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Check length
|
|
89
|
+
if (normalized.length > 4096) {
|
|
90
|
+
throw new Error('Invalid file path: too long (max 4096 characters)')
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return normalized
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Validates commit message
|
|
98
|
+
*/
|
|
99
|
+
function validateCommitMessage(message) {
|
|
100
|
+
if (!message || typeof message !== 'string') {
|
|
101
|
+
throw new Error('Invalid commit message: must be a non-empty string')
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const trimmed = message.trim()
|
|
105
|
+
|
|
106
|
+
if (trimmed.length === 0) {
|
|
107
|
+
throw new Error('Invalid commit message: cannot be empty or whitespace only')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (trimmed.length > 10000) {
|
|
111
|
+
throw new Error('Invalid commit message: too long (max 10000 characters)')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return trimmed
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Validates email address format
|
|
119
|
+
*/
|
|
120
|
+
function validateEmail(email) {
|
|
121
|
+
if (!email || typeof email !== 'string') {
|
|
122
|
+
throw new Error('Invalid email: must be a non-empty string')
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const trimmed = email.trim()
|
|
126
|
+
|
|
127
|
+
// Basic email validation
|
|
128
|
+
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
|
129
|
+
if (!emailPattern.test(trimmed)) {
|
|
130
|
+
throw new Error('Invalid email format')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (trimmed.length > 254) {
|
|
134
|
+
throw new Error('Invalid email: too long (max 254 characters)')
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return trimmed
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Validates URL format
|
|
142
|
+
*/
|
|
143
|
+
function validateUrl(url) {
|
|
144
|
+
if (!url || typeof url !== 'string') {
|
|
145
|
+
throw new Error('Invalid URL: must be a non-empty string')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const parsed = new URL(url)
|
|
150
|
+
|
|
151
|
+
// Only allow http and https
|
|
152
|
+
if (!['http:', 'https:'].includes(parsed.protocol)) {
|
|
153
|
+
throw new Error('Invalid URL: only HTTP and HTTPS protocols are allowed')
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return url
|
|
157
|
+
} catch (err) {
|
|
158
|
+
throw new Error(`Invalid URL format: ${err.message}`)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Validates username format
|
|
164
|
+
*/
|
|
165
|
+
function validateUsername(username) {
|
|
166
|
+
if (!username || typeof username !== 'string') {
|
|
167
|
+
throw new Error('Invalid username: must be a non-empty string')
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const trimmed = username.trim()
|
|
171
|
+
|
|
172
|
+
// Alphanumeric, hyphens, underscores only
|
|
173
|
+
const validPattern = /^[a-zA-Z0-9_-]+$/
|
|
174
|
+
if (!validPattern.test(trimmed)) {
|
|
175
|
+
throw new Error('Invalid username: only alphanumeric characters, hyphens, and underscores allowed')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (trimmed.length < 3) {
|
|
179
|
+
throw new Error('Invalid username: too short (min 3 characters)')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (trimmed.length > 39) {
|
|
183
|
+
throw new Error('Invalid username: too long (max 39 characters)')
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return trimmed
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Validates commit ID (hash) format
|
|
191
|
+
*/
|
|
192
|
+
function validateCommitId(commitId) {
|
|
193
|
+
if (!commitId || typeof commitId !== 'string') {
|
|
194
|
+
throw new Error('Invalid commit ID: must be a non-empty string')
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const trimmed = commitId.trim()
|
|
198
|
+
|
|
199
|
+
// Allow HEAD or valid hex hash
|
|
200
|
+
if (trimmed.toLowerCase() === 'head') {
|
|
201
|
+
return trimmed.toUpperCase()
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// SHA-1 hash (40 chars) or short hash (7-40 chars)
|
|
205
|
+
const hashPattern = /^[a-f0-9]{7,40}$/i
|
|
206
|
+
if (!hashPattern.test(trimmed)) {
|
|
207
|
+
throw new Error('Invalid commit ID: must be "HEAD" or a valid commit hash')
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return trimmed
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Validates repository name
|
|
215
|
+
*/
|
|
216
|
+
function validateRepoName(name) {
|
|
217
|
+
if (!name || typeof name !== 'string') {
|
|
218
|
+
throw new Error('Invalid repository name: must be a non-empty string')
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const trimmed = name.trim()
|
|
222
|
+
|
|
223
|
+
if (trimmed.length < 1) {
|
|
224
|
+
throw new Error('Invalid repository name: cannot be empty')
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (trimmed.length > 100) {
|
|
228
|
+
throw new Error('Invalid repository name: too long (max 100 characters)')
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Prevent path traversal in repo names
|
|
232
|
+
if (trimmed.includes('..') || trimmed.includes('/') || trimmed.includes('\\')) {
|
|
233
|
+
throw new Error('Invalid repository name: cannot contain path separators or ".."')
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return trimmed
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Sanitizes text input for display
|
|
241
|
+
*/
|
|
242
|
+
function sanitizeText(text) {
|
|
243
|
+
if (typeof text !== 'string') return String(text)
|
|
244
|
+
|
|
245
|
+
// Remove control characters except newline and tab
|
|
246
|
+
return text.replace(/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]/g, '')
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
module.exports = {
|
|
250
|
+
validateRepoId,
|
|
251
|
+
validateBranchName,
|
|
252
|
+
validateFilePath,
|
|
253
|
+
validateCommitMessage,
|
|
254
|
+
validateEmail,
|
|
255
|
+
validateUrl,
|
|
256
|
+
validateUsername,
|
|
257
|
+
validateCommitId,
|
|
258
|
+
validateRepoName,
|
|
259
|
+
sanitizeText
|
|
260
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resulgit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A powerful CLI tool for version control system operations - clone, commit, push, pull, merge, branch management, and more",
|
|
5
5
|
"main": "resulgit.js",
|
|
6
6
|
"bin": {
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"files": [
|
|
36
36
|
"resulgit.js",
|
|
37
|
-
"README.md"
|
|
37
|
+
"README.md",
|
|
38
|
+
"lib"
|
|
38
39
|
],
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"ora": "^5.4.1"
|
|
@@ -42,4 +43,4 @@
|
|
|
42
43
|
"devDependencies": {
|
|
43
44
|
"jest": "^29.7.0"
|
|
44
45
|
}
|
|
45
|
-
}
|
|
46
|
+
}
|