@@ -8,6 +8,8 @@ var Commit = NodeGit.Commit;
88var normalizeOptions = NodeGit . Utils . normalizeOptions ;
99var shallowClone = NodeGit . Utils . shallowClone ;
1010var path = require ( "path" ) ;
11+ var Filter = NodeGit . Filter ;
12+ var FilterList = NodeGit . FilterList ;
1113var Reference = NodeGit . Reference ;
1214var Remote = NodeGit . Remote ;
1315var Repository = NodeGit . Repository ;
@@ -37,7 +39,6 @@ function applySelectedLinesToTarget
3739 var oldIndex = 0 ;
3840 var linesPromises = [ ] ;
3941
40- // split the original file into lines
4142 var oldLines = originalContent . toString ( ) . split ( "\n" ) ;
4243
4344 // if no selected lines were sent, return the original content
@@ -121,6 +122,7 @@ function applySelectedLinesToTarget
121122 }
122123 }
123124 }
125+
124126 return newContent ;
125127 } ) ;
126128}
@@ -155,7 +157,7 @@ function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) {
155157 if ( ! ( status & NodeGit . Status . STATUS . WT_MODIFIED ) &&
156158 ! ( status & NodeGit . Status . STATUS . INDEX_MODIFIED ) ) {
157159 return Promise . reject
158- ( "Selected staging is only available on modified files." ) ;
160+ ( "Selected staging is only available on modified files." ) ;
159161 }
160162 return diff . patches ( ) ;
161163 } ) ;
@@ -729,15 +731,28 @@ Repository.prototype.discardLines =
729731 var fullFilePath = path . join ( repo . workdir ( ) , filePath ) ;
730732 var index ;
731733 var originalContent ;
734+ var filterList ;
732735
733736 return repo . refreshIndex ( )
734737 . then ( function ( indexResult ) {
735738 index = indexResult ;
739+ return FilterList . load ( repo , null , filePath , Filter . MODE . CLEAN , Filter . FLAG . DEFAULT ) ;
740+ } )
741+ . then ( function ( _filterList ) {
742+ filterList = _filterList ;
743+
744+ if ( filterList ) {
745+ return filterList . applyToFile ( repo , filePath ) ;
746+ }
736747
737748 return fse . readFile ( fullFilePath , "utf8" ) ;
738749 } )
739750 . then ( function ( content ) {
740751 originalContent = content ;
752+ if ( filterList ) {
753+ filterList . free ( ) ;
754+ filterList = null ;
755+ }
741756
742757 return getPathHunks ( repo , index , filePath , false , additionalDiffOptions ) ;
743758 } )
@@ -747,7 +762,23 @@ Repository.prototype.discardLines =
747762 ) ;
748763 } )
749764 . then ( function ( newContent ) {
750- return fse . writeFile ( fullFilePath , newContent ) ;
765+ return FilterList . load ( repo , null , filePath , Filter . MODE . SMUDGE , Filter . FLAG . DEFAULT )
766+ . then ( function ( _filterList ) {
767+ filterList = _filterList ;
768+ if ( filterList ) {
769+ return filterList . applyToData ( new String ( newContent ) ) ;
770+ }
771+
772+ return newContent ;
773+ } ) ;
774+ } )
775+ . then ( function ( filteredContent ) {
776+ if ( filterList ) {
777+ filterList . free ( ) ;
778+ filterList = null ;
779+ }
780+
781+ return fse . writeFile ( fullFilePath , filteredContent ) ;
751782 } ) ;
752783} ;
753784
0 commit comments