Skip to content

Commit 4fd946f

Browse files
committed
Add have commands. Merge additional pull request from parent repository adding some options, diff2 implementation and fixing edge case output of 'changes'.
1 parent 9ea1cc8 commit 4fd946f

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

index.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ NodeP4.prototype.fstat = function (options, callback)
339339

340340
callback(null, result);
341341
});
342-
}
342+
};
343343

344344
NodeP4.prototype.changes = function (options, callback)
345345
{
@@ -358,7 +358,14 @@ NodeP4.prototype.changes = function (options, callback)
358358
result = stdout.trim().split(/\r\n\r\n|\n\n(?=\.\.\.)/).reduce(function (memo, changeinfo)
359359
{
360360
// process each line of change info, transforming into a hash
361-
memo.push(processZtagOutput(changeinfo));
361+
var item = processZtagOutput(changeinfo);
362+
363+
// If object representing change is not empty, push it onto array
364+
if (Object.keys(item).length != 0)
365+
{
366+
memo.push(item);
367+
}
368+
362369
return memo;
363370
}, []);
364371

@@ -410,6 +417,37 @@ NodeP4.prototype.users = function (options, callback)
410417
});
411418
};
412419

420+
NodeP4.prototype.diff2 = function (options, callback)
421+
{
422+
if (typeof options === 'function')
423+
{
424+
callback = options;
425+
options = undefined;
426+
}
427+
428+
// TODO: Check that no more than two file arguments are provided
429+
execP4('-ztag diff2', options, function (err, stdout)
430+
{
431+
var result;
432+
if (err) return callback(err);
433+
434+
// process each change
435+
result = stdout.trim().split(/\r\n\r\n|\n\n(?=\.\.\.)/).reduce(function (memo, diff2info)
436+
{
437+
// process each line of change info, transforming into a hash
438+
var item = processZtagOutput(diff2info);
439+
440+
// If object representing change is not empty, push it onto array
441+
if (Object.keys(item).length != 0)
442+
memo.push(item);
443+
444+
return memo;
445+
}, []);
446+
447+
callback(null, result);
448+
});
449+
};
450+
413451
NodeP4.prototype.awaitCommand = function (command, options)
414452
{
415453
return new Promise((resolve, reject) =>
@@ -452,7 +490,7 @@ NodeP4.prototype.setDebugMode = function (debug_active)
452490
};
453491

454492
var commonCommands = ['add', 'delete', 'edit', 'revert', 'sync', 'diff', 'reconcile', 'reopen', 'resolved',
455-
'shelve', 'unshelve', 'client', 'resolve', 'submit', 'describe', 'files'];
493+
'shelve', 'unshelve', 'client', 'resolve', 'submit', 'describe', 'files', 'have'];
456494

457495
commonCommands.forEach(function (command)
458496
{

p4options.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ module.exports = {
6161
cmd: '-a',
6262
category: 'unary'
6363
},
64+
quiet: {
65+
cmd: '-q',
66+
category: 'unary'
67+
},
68+
branch: {
69+
cmd: '-b',
70+
type: String,
71+
category: 'mixed'
72+
},
6473
files: {
6574
type: Array,
6675
category: 'mixed'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reckless-node-perforce",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Simplified fork of node-perforce with vulnerable dependencies removed and fixed commands",
55
"main": "index.js",
66
"scripts": {},

0 commit comments

Comments
 (0)