@@ -122,12 +122,29 @@ Git.prototype.getCurrentBranch = function (path, callback) {
122
122
* @param {function } callback - Callback to be execute in error or success case
123
123
*/
124
124
Git . prototype . getCommitHistory = function ( opts , callback ) {
125
- var emoji = require ( './emoji' ) ;
125
+ let emoji = require ( './emoji' ) ,
126
+ skip = ( opts . skip ? `--skip ${ opts . skip } ` : '' ) ,
127
+ filter = '' ,
128
+ command ;
129
+
130
+ if ( opts . filter && opts . filter . text ) {
131
+
132
+ switch ( opts . filter . type ) {
133
+ case 'MESSAGE' :
134
+ filter = `--grep="${ opts . filter . text } "` ;
135
+ break ;
136
+ case 'AUTHOR' :
137
+ filter = `--author="${ opts . filter . text } "` ;
138
+ break ;
139
+ case 'FILE' :
140
+ filter = `-- ${ opts . filter . text } ` ;
141
+ break ;
142
+ }
143
+ }
144
+
145
+ command = `git --no-pager log -n 25 --pretty=format:%an-gtseparator-%cr-gtseparator-%h-gtseparator-%s-gtseparator-%b-gtseparator-%ae-gtseparator-%p-pieLineBreak- ${ skip } ${ filter } ` ;
126
146
127
- performCommand (
128
- "git --no-pager log -n 50 --pretty=format:%an-gtseparator-%cr-gtseparator-%h-gtseparator-%s-gtseparator-%b-gtseparator-%ae-pieLineBreak-" + ( opts . skip ? ' --skip ' . concat ( opts . skip ) : '' ) ,
129
- opts . path ,
130
- function ( error , stdout , stderr ) {
147
+ performCommand ( command , opts . path , function ( error , stdout , stderr ) {
131
148
var lines = stdout . split ( '-pieLineBreak-' ) ,
132
149
historyList = [ ] ,
133
150
err = null ;
@@ -147,7 +164,8 @@ Git.prototype.getCommitHistory = function (opts, callback) {
147
164
hash : historyItem [ 2 ] ,
148
165
message : emoji . parse ( historyItem [ 3 ] ) ,
149
166
body : historyItem [ 4 ] ,
150
- email : historyItem [ 5 ]
167
+ email : historyItem [ 5 ] ,
168
+ parentHash : historyItem [ 6 ]
151
169
} ) ;
152
170
}
153
171
}
@@ -776,6 +794,37 @@ Git.prototype.deleteBranch = function (path, opts) {
776
794
performCommand ( `git branch -D ${ opts . branchName } ` , path , opts . callback ) ;
777
795
} ;
778
796
797
+ Git . prototype . getCommitDiff = function ( path , opts ) {
798
+ opts = opts || { } ;
799
+ let command = `git log --pretty=%an-gtseparator-%h-gtseparator-%s-gtseparator-%aD ${ opts . branchBase . trim ( ) } ..${ opts . branchCompare . trim ( ) } ` ;
800
+
801
+ performCommand ( command , path , function ( error , stdout ) {
802
+ let commits ;
803
+
804
+ if ( ! error ) {
805
+ commits = [ ] ;
806
+
807
+ let lines = stdout . split ( '\n' ) ;
808
+
809
+ for ( let i = 0 ; i < lines . length ; i ++ ) {
810
+
811
+ if ( lines [ i ] ) {
812
+ let commitInfo = lines [ i ] . split ( '-gtseparator-' ) ;
813
+
814
+ commits . push ( {
815
+ author : commitInfo [ 0 ] ,
816
+ hash : commitInfo [ 1 ] ,
817
+ message : commitInfo [ 2 ] ,
818
+ date : new Date ( commitInfo [ 3 ] )
819
+ } ) ;
820
+ }
821
+ }
822
+ }
823
+
824
+ invokeCallback ( opts . callback , [ error , commits ] ) ;
825
+ } ) ;
826
+ } ;
827
+
779
828
Git . prototype . geDiffMerge = function ( path , opts ) {
780
829
opts = opts || { } ;
781
830
0 commit comments