// ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġgit 4 idea . tests Ċ Ċ import Ġcom . intellij . openapi . application . invoke And Wait IfNeeded Ċ import Ġcom . intellij . openapi . application . run Read Action Ċ import Ġcom . intellij . openapi . application . run Write Action Ċ import Ġcom . intellij . openapi . editor . Document Ċ import Ġcom . intellij . openapi . file Editor . File Document Manager Ċ import Ġcom . intellij . openapi . vcs . Executor . child Ċ import Ġcom . intellij . openapi . vcs . changes . Changes Util Ċ import Ġcom . intellij . openapi . vcs . changes . Local Change List Ċ import Ġcom . intellij . openapi . vcs . ex . Partial Local Line Status Tracker Ċ import Ġcom . intellij . openapi . vcs . impl . Line Status Tracker Manager Ċ import Ġcom . intellij . openapi . vfs . Local FileSystem Ċ import Ġcom . intellij . util . ui . UI Util Ċ import Ġgit 4 idea . test . Git Single Repo Test Ċ import Ġgit 4 idea . test . assert Commit ted Ċ import Ġgit 4 idea . test . git As Bytes Ċ import Ġgit 4 idea . test . tac Ċ Ċ class ĠGit Partial Commit Test Ġ: ĠGit Single Repo Test () Ġ{ ĊĠ Ġfun Ġ` test Ġpartial Ġcommit Ġwith Ġchange lists `() Ġ{ ĊĠĠĠ Ġt ac (" a . java ", Ġ" A \ nB \ n C ") ĊĊĠĠĠ Ġval Ġtest Change List Ġ= Ġchange List Manager . add Change List (" Test ", Ġnull ) ĊĊĠĠĠ Ġwith Tracked Document (" a . java ", Ġ" X \ nB \ n Z ") Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġval Ġranges Ġ= Ġtracker . get Ranges () !! ĊĠĠĠĠĠ Ġtracker . moveTo Change list ( ranges [ 1 ], Ġtest Change List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġchanges Ġ= Ġchange List Manager . find Change List (" Test ") !!. changes ĊĠĠĠ Ġcommit ( changes ) ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġrepo . assert Commit ted Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" A \ nB \ n Z ") ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġpartial Ġcommit Ġwith Ġexcluded Ġrange `() Ġ{ ĊĠĠĠ Ġt ac (" a . java ", Ġ" A \ nB \ n C ") ĊĊĠĠĠ Ġwith Tracked Document (" a . java ", Ġ" X \ nB \ n Z ") Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġval Ġranges Ġ= Ġtracker . get Ranges () !! ĊĠĠĠĠĠ Ġtracker . set Excluded From Commit ( ranges [ 1 ], Ġtrue ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġchanges Ġ= Ġchange List Manager . find Change List ( Local Change List . getDefault Name ()) !!. changes ĊĠĠĠ Ġcommit ( changes ) ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġrepo . assert Commit ted Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" X \ nB \ n C ") ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġfull Ġcommit Ġwith Ġchange lists `() Ġ{ ĊĠĠĠ Ġt ac (" a . java ", Ġ" A \ nB \ n C ") ĊĊĠĠĠ Ġval Ġtest Change List Ġ= Ġchange List Manager . add Change List (" Test ", Ġnull ) ĊĊĠĠĠ Ġwith Tracked Document (" a . java ", Ġ" X \ nB \ n Z ") Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġval Ġranges Ġ= Ġtracker . get Ranges () !! ĊĠĠĠĠĠ Ġtracker . moveTo Change list ( ranges [ 1 ], Ġtest Change List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġchanges Ġ= Ġchange List Manager . all Changes ĊĠĠĠ Ġcommit ( changes ) ĊĊĠĠĠ Ġassert No Changes () ĊĠĠĠ Ġrepo . assert Commit ted Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" X \ nB \ n Z ") ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġpartial Ġcommit Ġwith Ġchange lists Ġ& Ġdon 't Ġcommit Ġst aged Ġchange `() Ġ{ ĊĠĠĠ Ġt ac (" a . java ", Ġ" A \ nB \ n C ") ĊĠĠĠ Ġt ac (" b . java ", Ġ" A \ nB \ n C ") ĊĊĠĠĠ Ġval Ġtest Change List Ġ= Ġchange List Manager . add Change List (" Test ", Ġnull ) ĊĊĠĠĠ Ġwith Tracked Document (" a . java ", Ġ" X \ nB \ n Z ") Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġval Ġranges Ġ= Ġtracker . get Ranges () !! ĊĠĠĠĠĠ Ġtracker . moveTo Change list ( ranges [ 1 ], Ġtest Change List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġwith Tracked Document (" b . java ", Ġ" X 1 \ nB \ n Z 2 ") Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġval Ġranges Ġ= Ġtracker . get Ranges () !! ĊĠĠĠĠĠ Ġtracker . moveTo Change list ( ranges [ 1 ], Ġtest Change List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠĠĠ Ġmodified (" b . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġchanges Ġ= Ġchange List Manager . find Change List (" Test ") !!. changes ĊĠĠĠĠĠ Ġ. filter Ġ{ ĠChanges Util . get FilePath ( it ). name Ġ== Ġ" a . java " Ġ} ĊĠĠĠ Ġcommit ( changes ) ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠĠĠ Ġmodified (" b . java ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġrepo . assert Commit ted Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" A \ nB \ n Z ") ĊĠĠĠ Ġassert Commit ted Content (" b . java ", Ġ" A \ nB \ n C ") ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġpartial Ġcommit Ġwith Ġchange lists Ġ& Ġenabled Ġaut ocr lf Ġconversions `() Ġ{ ĊĠĠĠ Ġgit (" config Ġcore . aut ocr lf Ġtrue ") ĊĠĠĠ Ġt ac (" a . java ", Ġ" A \ r \ nB \ r \ n C ") ĊĊĠĠĠ Ġval Ġtest Change List Ġ= Ġchange List Manager . add Change List (" Test ", Ġnull ) ĊĊĠĠĠ Ġwith Tracked Document (" a . java ", Ġ" X \ nB \ n Z ") Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġval Ġranges Ġ= Ġtracker . get Ranges () !! ĊĠĠĠĠĠ Ġtracker . moveTo Change list ( ranges [ 1 ], Ġtest Change List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġchanges Ġ= Ġchange List Manager . find Change List (" Test ") !!. changes ĊĠĠĠ Ġcommit ( changes ) ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġrepo . assert Commit ted Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" A \ nB \ n Z ") ĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" A \ r \ nB \ r \ n Z ", Ġtrue ) ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġpartial Ġcommit Ġwith Ġchange lists Ġ& Ġdisabled Ġaut ocr lf Ġconversions `() Ġ{ ĊĠĠĠ Ġgit (" config Ġcore . aut ocr lf Ġfalse ") ĊĠĠĠ Ġt ac (" a . java ", Ġ" A \ r \ nB \ r \ n C ") ĊĊĠĠĠ Ġval Ġtest Change List Ġ= Ġchange List Manager . add Change List (" Test ", Ġnull ) ĊĊĠĠĠ Ġwith Tracked Document (" a . java ", Ġ" X \ nB \ n Z ") Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġval Ġranges Ġ= Ġtracker . get Ranges () !! ĊĠĠĠĠĠ Ġtracker . moveTo Change list ( ranges [ 1 ], Ġtest Change List ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġchanges Ġ= Ġchange List Manager . find Change List (" Test ") !!. changes ĊĠĠĠ Ġcommit ( changes ) ĊĊĠĠĠ Ġassert Change sWith Refresh Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġrepo . assert Commit ted Ġ{ ĊĠĠĠĠĠ Ġmodified (" a . java ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" A \ r \ nB \ r \ n Z ") ĊĠĠĠ Ġassert Commit ted Content (" a . java ", Ġ" A \ r \ nB \ r \ n Z ", Ġtrue ) ĊĠ Ġ} ĊĊĊĠ Ġprivate Ġfun Ġassert Commit ted Content ( fileName : ĠString , Ġexpected Content : ĠString , Ġuse Filters : ĠBoolean Ġ= Ġfalse ) Ġ{ ĊĠĠĠ Ġval Ġactual Content Ġ= Ġrepo . git As Bytes (" cat - file " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ( if Ġ( use Filters ) Ġ" Ġ-- filters " Ġelse Ġ" Ġ- p ") Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Ġ: $ fileName ") ĊĠĠĠ ĠassertEquals ( expected Content , ĠString ( actual Content , ĠChar sets . UTF _ 8 )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġwith Tracked Document ( fileName : ĠString , Ġnew Content : ĠString , Ġtask : Ġ( Document , ĠPartial Local Line Status Tracker ) Ġ-> ĠUnit ) Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= ĠLocal FileSystem . getInstance (). refresh And Find File By Io File ( child ( fileName )) !! ĊĊĠĠĠ Ġwith Partial Tracker ( file , Ġnew Content ) Ġ{ Ġdocument , Ġtracker Ġ-> ĊĠĠĠĠĠ Ġ// ĠAssume Ġthat Ġinitial Ġchanges Ġare Ġincluded Ġinto Ġcommit ĊĠĠĠĠĠ Ġtracker . set Excluded From Commit ( false ) ĊĊĠĠĠĠĠ Ġtask ( document , Ġtracker ) ĊĠĠĠĠĠ ĠFile Document Manager . getInstance (). save All Documents () ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }