// Ġ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 . update Ċ Ċ import Ġcom . intellij . openapi . progress . Empty Progress Indicator Ċ import Ġcom . intellij . openapi . util . io . File Util Ċ import Ġcom . intellij . openapi . vcs . Executor . cd Ċ import Ġcom . intellij . openapi . vcs . update . Updated Files Ċ import Ġcom . intellij . vcs . log . impl . Hash Impl Ċ import Ġgit 4 idea . config . Update Method . RE BASE Ċ import Ġgit 4 idea . repo . Git Repository Ċ import Ġgit 4 idea . test .* Ċ import Ġjava . io . File Ċ Ċ class ĠGit Single Repo Update Test Ġ: ĠGit Update Base Test () Ġ{ ĊĊĠ Ġprivate Ġlateinit Ġvar Ġrepo : ĠGit Repository ĊĠ Ġprivate Ġlateinit Ġvar Ġbro Repo Ġ: ĠFile ĊĊĠ Ġoverride Ġfun ĠsetUp () Ġ{ ĊĠĠĠ Ġsuper . setUp () ĊĊĠĠĠ Ġrepo Ġ= Ġcreate Repository ( project , Ġproject Path , Ġtrue ) ĊĠĠĠ Ġcd ( project Path ) ĊĊĠĠĠ Ġval Ġparent Ġ= Ġprepare Remote Repo ( repo ) ĊĠĠĠ Ġgit (" push Ġ- u Ġorigin Ġmaster ") ĊĠĠĠ Ġbro Repo Ġ= Ġcreate Bro Repo (" bro ", Ġparent ) ĊĠĠĠ Ġrepo . update () ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget Debug Log Categories () Ġ= Ġsuper . get Debug Log Categories (). plus ("# git 4 idea . update ") ĊĊĠ Ġfun Ġ` test Ġst ash Ġis Ġcalled Ġfor Ġrebase Ġif Ġthere Ġare Ġlocal Ġchanges Ġand Ġlocal Ġcommits `() Ġ{ ĊĠĠĠ Ġbro Repo . commit And Push () ĊĠĠĠ Ġt ac (" a . txt ") ĊĠĠĠ Ġval Ġlocal File Ġ= Ġfile (" a . txt "). append (" content "). add (). file ĊĠĠĠ Ġupdate Change List Manager () ĊĊĠĠĠ Ġvar Ġst ash Called Ġ= Ġfalse ĊĠĠĠ Ġgit . stash Listener Ġ= Ġ{ ĊĠĠĠĠĠ Ġst ash Called Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġresult Ġ= Ġupdate With Re base () ĊĠĠĠ Ġassert Successful Update ( result ) ĊĠĠĠ ĠassertTrue (" St ash Ġshould Ġhave Ġbeen Ġcalled Ġfor Ġdirty Ġworking Ġtree ", Ġst ash Called ) ĊĠĠĠ Ġrepo . assert Status ( local File , Ġ' M ') ĊĠ Ġ} ĊĊĠ Ġ// Ġ" Fast - forward Ġmerge " Ġoptimization ĊĠ Ġfun Ġ` test Ġst ash Ġis Ġnot Ġcalled Ġfor Ġrebase Ġif Ġthere Ġare Ġlocal Ġchanges , Ġbut Ġno Ġlocal Ġcommits `() Ġ{ ĊĠĠĠ Ġbro Repo . commit And Push () ĊĠĠĠ Ġval Ġlocal File Ġ= Ġfile (" a . txt "). append (" content "). add (). file ĊĠĠĠ Ġupdate Change List Manager () ĊĊĠĠĠ Ġvar Ġst ash Called Ġ= Ġfalse ĊĠĠĠ Ġgit . stash Listener Ġ= Ġ{ ĊĠĠĠĠĠ Ġst ash Called Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġresult Ġ= Ġupdate With Re base () ĊĠĠĠ Ġassert Successful Update ( result ) ĊĠĠĠ ĠassertFalse (" St ash Ġshouldn 't Ġbe Ġcalled , Ġbecause Ġof Ġfast - forward Ġmerge Ġoptimization ", Ġst ash Called ) ĊĠĠĠ Ġrepo . assert Status ( local File , Ġ' A ') ĊĠ Ġ} ĊĊĠ Ġ// ĠIDEA - 1 6 7 6 8 8 ĊĠ Ġfun Ġ` test Ġst ash Ġis Ġnot Ġcalled Ġfor Ġrebase Ġif Ġthere Ġare Ġno Ġlocal Ġchanges `() Ġ{ ĊĠĠĠ Ġbro Repo . commit And Push () ĊĊĠĠĠ Ġvar Ġst ash Called Ġ= Ġfalse ĊĠĠĠ Ġgit . stash Listener Ġ= Ġ{ ĊĠĠĠĠĠ Ġst ash Called Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġupdate With Re base () ĊĠĠĠ ĠassertFalse (" St ash Ġshouldn 't Ġbe Ġcalled Ġfor Ġclean Ġworking Ġtree ", Ġst ash Called ) ĊĠ Ġ} ĊĊĠ Ġ// ĠIDEA - 7 6 7 6 0 ĊĠ Ġfun Ġ` test Ġst ash Ġis Ġcalled Ġfor Ġrebase Ġin Ġcase Ġof ĠAD Ġchanges `() Ġ{ ĊĠĠĠ Ġbro Repo . commit And Push () ĊĊĠĠĠ Ġvar Ġst ash Called Ġ= Ġfalse ĊĠĠĠ Ġgit . stash Listener Ġ= Ġ{ ĊĠĠĠĠĠ Ġst ash Called Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcd ( repo ) ĊĠĠĠ Ġval Ġfile Ġ= Ġfile (" a . txt "). create (). add (). delete (). file ĊĠĠĠ Ġupdate Change List Manager () ĊĊĠĠĠ Ġval Ġresult Ġ= Ġupdate With Re base () ĊĠĠĠ Ġassert Successful Update ( result ) ĊĠĠĠ ĠassertTrue (" St ash Ġshould Ġbe Ġcalled Ġfor Ġclean Ġworking Ġtree ", Ġst ash Called ) ĊĠĠĠ Ġrepo . assert Status ( file , Ġ' A ') ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġupdate Ġrange Ġif Ġonly Ġincoming Ġcommits `() Ġ{ ĊĠĠĠ Ġcd ( bro Repo ) ĊĠĠĠ Ġval Ġbefore Ġ= Ġlast (). as Hash () ĊĠĠĠ Ġcommit Something To Bro Repo () ĊĠĠĠ Ġcommit Something To Bro Repo () ĊĠĠĠ Ġval Ġafter Ġ= Ġlast (). as Hash () ĊĠĠĠ Ġgit (" push Ġ- u Ġorigin Ġmaster ") ĊĊĠĠĠ Ġval Ġupdate Process Ġ= Ġupdate Process () ĊĠĠĠ Ġupdate Process . update ( RE BASE ) ĊĊĠĠĠ Ġval Ġrange Ġ= Ġupdate Process . updated Ranges ! ![ repo ] !! ĊĠĠĠ ĠassertEquals (" Updated Ġrange Ġis Ġincorrect ", ĠHash Range ( before , Ġafter ), Ġrange ) ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġupdate Ġrange Ġif Ġtracked Ġbranch Ġhas Ġbeen Ġfetched Ġbefore Ġupdate `() Ġ{ ĊĠĠĠ Ġcd ( bro Repo ) ĊĠĠĠ Ġval Ġbefore Ġ= Ġlast (). as Hash () ĊĠĠĠ Ġcommit Something To Bro Repo () ĊĠĠĠ Ġgit (" push Ġ- u Ġorigin Ġmaster ") ĊĊĠĠĠ Ġcd ( repo ) ĊĠĠĠ Ġgit (" fetch ") ĊĊĠĠĠ Ġcd ( bro Repo ) ĊĠĠĠ Ġcommit Something To Bro Repo () ĊĠĠĠ Ġval Ġafter Ġ= Ġlast (). as Hash () ĊĠĠĠ Ġgit (" push Ġ- u Ġorigin Ġmaster ") ĊĊĠĠĠ Ġval Ġupdate Process Ġ= Ġupdate Process () ĊĠĠĠ Ġupdate Process . update ( RE BASE ) ĊĊĠĠĠ Ġval Ġrange Ġ= Ġupdate Process . updated Ranges ! ![ repo ] !! ĊĠĠĠ ĠassertEquals (" Updated Ġrange Ġis Ġincorrect ", ĠHash Range ( before , Ġafter ), Ġrange ) ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġupdate Ġrange Ġif Ġthere Ġare Ġun pus hed Ġcommits `() Ġ{ ĊĠĠĠ Ġcd ( bro Repo ) ĊĠĠĠ Ġval Ġbefore Ġ= Ġlast (). as Hash () ĊĠĠĠ Ġcommit Something To Bro Repo () ĊĠĠĠ Ġcommit Something To Bro Repo () ĊĠĠĠ Ġval Ġafter Ġ= Ġlast (). as Hash () ĊĠĠĠ Ġgit (" push Ġ- u Ġorigin Ġmaster ") ĊĊĠĠĠ Ġcd ( repo ) ĊĠĠĠ Ġfile (" local . txt "). append (" initial Ġcontent \ n "). add Commit (" created Ġlocal . txt ") ĊĊĠĠĠ Ġval Ġupdate Process Ġ= Ġupdate Process () ĊĠĠĠ Ġupdate Process . update ( RE BASE ) ĊĊĠĠĠ Ġval Ġrange Ġ= Ġupdate Process . updated Ranges ! ![ repo ] !! ĊĠĠĠ ĠassertEquals (" Updated Ġrange Ġis Ġincorrect ", ĠHash Range ( before , Ġafter ), Ġrange ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġupdate With Re base () Ġ= Ġupdate Process (). update ( RE BASE ) ĊĊĠ Ġprivate Ġfun Ġupdate Process () Ġ= ĠGit Update Process ( project , ĠEmpty Progress Indicator (), ĠlistOf ( repo ), ĠUpdated Files . create (), Ġfalse , Ġtrue ) ĊĊĠ Ġprivate Ġfun ĠFile . commit And Push () Ġ{ ĊĠĠĠ Ġcd ( this ) ĊĠĠĠ Ġcommit Something To Bro Repo () ĊĠĠĠ Ġgit (" push Ġ- u Ġorigin Ġmaster ") ĊĠĠĠ Ġcd ( repo ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcommit Something To Bro Repo () Ġ{ ĊĠĠĠ Ġcd ( bro Repo ) ĊĠĠĠ Ġval Ġfile Ġ= ĠFile ( bro Repo , Ġ" bro . txt ") ĊĠĠĠ Ġval Ġcontent Ġ= Ġ" content -${ Math . random () }\ n " ĊĠĠĠ ĠFile Util . write ToFile ( file , Ġcontent . toByteArray (), Ġtrue ) ĊĠĠĠ Ġadd Commit (" modified Ġbro . txt ") ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠString . as Hash () Ġ= ĠHash Impl . build ( this ) ĊĊĠ Ġprivate Ġfun Ġassert Successful Update ( result : ĠGit Update Result ) Ġ{ ĊĠĠĠ ĠassertEquals (" Incorrect Ġupdate Ġresult ", ĠGit Update Result . SUCCESS , Ġresult ) ĊĠ Ġ} ĊĊĠ Ġinternal Ġfun Ġfile ( path : ĠString ) Ġ= Ġrepo . file ( path ) Ċ }