// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 Ġ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 . re base Ċ Ċ import Ġcom . intellij . dv cs . repo . Repository . State .* Ċ import Ġcom . intellij . openapi . action System . An ActionEvent Ċ import Ġcom . intellij . openapi . action System . Common Data Keys Ċ import Ġcom . intellij . openapi . diagnostic . logger Ċ import Ġcom . intellij . openapi . progress . Progress Manager Ċ import Ġcom . intellij . openapi . project . D umb Aware Action Ċ import Ġcom . intellij . openapi . ui . Messages Ċ import Ġcom . intellij . openapi . vfs . Virtual File Ċ import Ġcom . intellij . vcs . log .* Ċ import Ġcom . intellij . vcs . log . data . V cs Log Data Ċ import Ġgit 4 idea . Git Util . HEAD Ċ import Ġgit 4 idea . Git Util . getRepository Manager Ċ import Ġgit 4 idea . find Protected Remote Branch Ċ import Ġgit 4 idea . i 1 8 n . Git Bundle Ċ import Ġgit 4 idea . repo . Git Repository Ċ import Ġorg . jetbrains . annotations . Called In Any Ċ import Ġorg . jetbrains . annotations . N ls Ċ Ċ /** Ċ Ġ* ĠBase Ġclass Ġfor ĠGit Ġaction Ġwhich Ġis Ġgoing Ġto Ġedit Ġexisting Ġcommits , Ċ Ġ* Ġi . e . Ġshould Ġbe Ġenabled Ġonly Ġon Ġcommits Ġnot Ġpushed Ġto Ġa Ġprotected Ġbranch . Ċ Ġ*/ Ċ abstract Ġclass ĠGit Commit Editing Action Ġ: ĠD umb Aware Action () Ġ{ ĊĊĠ Ġprivate Ġval ĠLOG Ġ= Ġlogger < Git Commit Editing Action >() ĊĊĠ Ġoverride Ġfun Ġupdate ( e : ĠAn ActionEvent ) Ġ{ ĊĠĠĠ Ġsuper . update ( e ) ĊĠĠĠ Ġval Ġproject Ġ= Ġe . project ĊĠĠĠ Ġval Ġlog Ġ= Ġe . getData ( V cs Log Data Keys . V CS _ LOG ) ĊĠĠĠ Ġval Ġdata Ġ= Ġe . getData ( V cs Log Data Keys . V CS _ LOG _ DATA _ PROVIDER ) Ġas ĠV cs Log Data ? ĊĠĠĠ Ġval Ġui Ġ= Ġe . getData ( V cs Log Data Keys . V CS _ LOG _ UI ) ĊĠĠĠ Ġif Ġ( project Ġ== Ġnull Ġ|| Ġlog Ġ== Ġnull Ġ|| Ġdata Ġ== Ġnull Ġ|| Ġui Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠ Ġe . presentation . isEnabled And Visible Ġ= Ġfalse ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġselected Commits Ġ= Ġlog . selected Short Details . size ĊĠĠĠ Ġif Ġ( selected Commits Ġ!= Ġ 1 ) Ġ{ ĊĠĠĠĠĠ Ġe . presentation . isEnabled And Visible Ġ= Ġfalse ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġcommit Ġ= Ġlog . selected Short Details [ 0 ] ĊĠĠĠ Ġval Ġrepository Manager Ġ= Ġget Repository Manager ( project ) ĊĠĠĠ Ġval Ġrepository Ġ= Ġrepository Manager . getRepository For Root Quick ( commit . root ) ĊĠĠĠ Ġif Ġ( repository Ġ== Ġnull Ġ|| Ġrepository Manager . is External ( repository )) Ġ{ ĊĠĠĠĠĠ Ġe . presentation . isEnabled And Visible Ġ= Ġfalse ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// Ġediting Ġmerge Ġcommit Ġor Ġroot Ġcommit Ġis Ġnot Ġallowed ĊĠĠĠ Ġval Ġparents Ġ= Ġcommit . parents . size ĊĠĠĠ Ġif Ġ( parents Ġ!= Ġ 1 ) Ġ{ ĊĠĠĠĠĠ Ġe . presentation . isEnabled Ġ= Ġfalse ĊĠĠĠĠĠ Ġe . presentation . description Ġ= ĠGit Bundle . message (" re base . log . commit . editing . action . disabled . parents . description ", Ġparents ) ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// Ġallow Ġediting Ġonly Ġin Ġthe Ġcurrent Ġbranch ĊĠĠĠ Ġval Ġbranches Ġ= Ġlog . get Containing Branches ( commit . id , Ġcommit . root ) ĊĠĠĠ Ġif Ġ( branches Ġ!= Ġnull ) Ġ{ Ġ// Ġotherwise Ġthe Ġinformation Ġis Ġnot Ġavailable Ġyet , Ġand Ġwe 'll Ġre check Ġharder Ġin ĠactionPerformed ĊĠĠĠĠĠ Ġif Ġ(! branches . contains ( HEAD )) Ġ{ ĊĠĠĠĠĠĠĠ Ġe . presentation . isEnabled Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġe . presentation . description Ġ= ĠGit Bundle . getString (" re base . log . commit . editing . action . commit . not . in . head . error . text ") ĊĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġ// Ġand Ġnot Ġif Ġpushed Ġto Ġa Ġprotected Ġbranch ĊĠĠĠĠĠ Ġval Ġprotected Branch Ġ= Ġfind Protected Remote Branch ( repository , Ġbranches ) ĊĠĠĠĠĠ Ġif Ġ( protected Branch Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġe . presentation . isEnabled Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġe . presentation . description Ġ= Ġcommit P ushed To Protected Branch Error ( protected Branch ) ĊĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġe . presentation . isEnabled And Visible Ġ= Ġtrue ĊĠ Ġ} ĊĊĠ Ġfinal Ġoverride Ġfun ĠactionPerformed ( e : ĠAn ActionEvent ) Ġ{ ĊĠĠĠ Ġval Ġproject Ġ= Ġe . get Required Data ( Common Data Keys . PROJECT ) ĊĠĠĠ Ġval Ġdata Ġ= Ġe . get Required Data ( V cs Log Data Keys . V CS _ LOG _ DATA _ PROVIDER ) Ġas ĠV cs Log Data ĊĠĠĠ Ġval Ġlog Ġ= Ġe . get Required Data ( V cs Log Data Keys . V CS _ LOG ) ĊĊĠĠĠ Ġval Ġcommit Ġ= Ġlog . selected Short Details [ 0 ] ĊĠĠĠ Ġval Ġrepository Ġ= Ġget Repository Manager ( project ). getRepository For Root Quick ( commit . root ) !! ĊĊĠĠĠ Ġval Ġbranches Ġ= Ġfind Containing Branches ( data , Ġcommit . root , Ġcommit . id ) ĊĊĠĠĠ Ġif Ġ(! branches . contains ( HEAD )) Ġ{ ĊĠĠĠĠĠ ĠMessages . show Error Dialog ( project , ĠGit Bundle . getString (" re base . log . commit . editing . action . commit . not . in . head . error . text "), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġget Failure Title ()) ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ// Ġand Ġnot Ġif Ġpushed Ġto Ġa Ġprotected Ġbranch ĊĠĠĠ Ġval Ġprotected Branch Ġ= Ġfind Protected Remote Branch ( repository , Ġbranches ) ĊĠĠĠ Ġif Ġ( protected Branch Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠ ĠMessages . show Error Dialog ( project , Ġcommit P ushed To Protected Branch Error ( protected Branch ), Ġget Failure Title ()) ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠactionPerformed After Checks ( e ) ĊĠ Ġ} ĊĊĠ Ġabstract Ġfun ĠactionPerformed After Checks ( e : ĠAn ActionEvent ) ĊĊĠ Ġprotected Ġfun Ġget Log ( e : ĠAn ActionEvent ): ĠV cs Log Ġ= Ġe . get Required Data ( V cs Log Data Keys . V CS _ LOG ) ĊĊĠ Ġprotected Ġfun Ġget Log Data ( e : ĠAn ActionEvent ): ĠV cs Log Data Ġ= Ġe . get Required Data ( V cs Log Data Keys . V CS _ LOG _ DATA _ PROVIDER ) Ġas ĠV cs Log Data ĊĊĠ Ġprotected Ġfun Ġget Ui ( e : ĠAn ActionEvent ): ĠV cs Log Ui Ġ= Ġe . get Required Data ( V cs Log Data Keys . V CS _ LOG _ UI ) ĊĊĠ Ġprotected Ġfun Ġget Selected Commit ( e : ĠAn ActionEvent ): ĠV cs Short Commit Details Ġ= Ġget Log ( e ). selected Short Details [ 0 ] !! ĊĊĠ Ġ@ Called In Any ĊĠ Ġprotected Ġfun Ġget Repository ( e : ĠAn ActionEvent ): ĠGit Repository Ġ= Ġget Repository Manager ( e . project !! ). getRepository For Root Quick ( getSelected Commit ( e ). root ) !! ĊĊĠ Ġprotected Ġabstract Ġfun Ġget Failure Title (): ĠString ĊĊĠ Ġprotected Ġfun Ġfind Containing Branches ( data : ĠV cs Log Data , Ġroot : ĠVirtual File , Ġhash : ĠHash ): ĠList < String > Ġ{ ĊĠĠĠ Ġval Ġbranches Getter Ġ= Ġdata . containing Branches Getter ĊĠĠĠ Ġreturn Ġbranches Getter . get Containing Branches Quick ly ( root , Ġhash ) Ġ?: ĊĠĠĠĠĠĠĠĠĠĠ ĠProgress Manager . getInstance (). run Process With Progress S ynchronously < List < String >, ĠRuntimeException >({ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġbranches Getter . get Containing Branches S ynchronously ( root , Ġhash ) ĊĠĠĠĠĠĠĠĠĠĠ Ġ}, ĠGit Bundle . getString (" re base . log . commit . editing . action . progress . containing . branches . title "), Ġtrue , Ġdata . project ) ĊĠ Ġ} ĊĊĠ Ġprotected Ġfun Ġcommit P ushed To Protected Branch Error ( protected Branch : ĠString ) Ġ= ĊĠĠĠ ĠGit Bundle . message (" re base . log . commit . editing . action . commit . pus hed . to . protected . branch . error . text ", Ġprotected Branch ) ĊĊĠ Ġprotected Ġfun Ġpro hibit Re base During Re base ( e : ĠAn ActionEvent , Ġ@ N ls Ġoperation : ĠString , Ġallow Re base If Head Commit : ĠBoolean Ġ= Ġfalse ) Ġ{ ĊĠĠĠ Ġif Ġ( e . presentation . isEnabled And Visible ) Ġ{ ĊĠĠĠĠĠ Ġval Ġmessage Ġ= Ġget Pro hibited State Message ( e , Ġoperation , Ġallow Re base If Head Commit ) ĊĠĠĠĠĠ Ġif Ġ( message Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġe . presentation . isEnabled Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġe . presentation . description Ġ= Ġmessage ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprotected Ġfun Ġget Pro hibited State Message ( e : ĠAn ActionEvent , Ġ@ N ls Ġoperation : ĠString , Ġallow Re base If Head Commit : ĠBoolean Ġ= Ġfalse ): ĠString ? Ġ{ ĊĠĠĠ Ġval Ġstate Ġ= Ġget Repository ( e ). state ĊĠĠĠ Ġif Ġ( state Ġ== ĠNORMAL Ġ|| Ġstate Ġ== ĠDET ACHED ) Ġ{ ĊĠĠĠĠĠ Ġreturn Ġnull ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( state Ġ== ĠRE BAS ING Ġ&& Ġallow Re base If Head Commit Ġ&& Ġis Head Commit ( e )) Ġ{ ĊĠĠĠĠĠ Ġreturn Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġwhen Ġ( state ) Ġ{ ĊĠĠĠĠĠ ĠRE BAS ING Ġ-> ĠGit Bundle . message (" re base . log . commit . editing . action . pro hibit . state . re bas ing ", Ġoperation ) ĊĠĠĠĠĠ ĠMER GING Ġ-> ĠGit Bundle . message (" re base . log . commit . editing . action . pro hibit . state . mer ging ", Ġoperation ) ĊĠĠĠĠĠ ĠG RA FT ING Ġ-> ĠGit Bundle . message (" re base . log . commit . editing . action . pro hibit . state . gr aft ing ", Ġoperation ) ĊĠĠĠĠĠ ĠRE VERT ING Ġ-> ĠGit Bundle . message (" re base . log . commit . editing . action . pro hibit . state . re verting ", Ġoperation ) ĊĠĠĠĠĠ Ġelse Ġ-> ĠGit Bundle . message (" re base . log . commit . editing . action . pro hibit . state ", Ġoperation ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprotected Ġfun Ġis Head Commit ( e : ĠAn ActionEvent ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn Ġget Selected Commit ( e ). id . asString () Ġ== Ġget Repository ( e ). current Revision ĊĠ Ġ} Ċ } Ċ