TDD with git. Long live engineering.

023b04c98f39cc041293d780352432ff?s=47 Koichi ITO
October 03, 2020

TDD with git. Long live engineering.

Kaigi on Rails STAY HOME Edition (https://kaigionrails.org/)

023b04c98f39cc041293d780352432ff?s=128

Koichi ITO

October 03, 2020
Tweet

Transcript

  1. Koichi ITO / ESM, Inc. Kaigi on Rails STAY HOME

    Edition TDD with git. Long live engineering. 2020-10-03(Sat)
  2. @koic • RuboCop core team • OSS Programmer • Agile

    software development practitioner • Distinguished Engineer at ESM, Inc. Me and @amapyon, @fkino, @sizuhiko
  3. None
  4. +0900 UTC+0200 +0300 +0800 -0400 Core developers

  5. &4. *OD

  6. None
  7. &4.͔Β ࡾਓ໨ ͷൃදऀ

  8. Support OSS community

  9. None
  10. An agile project in the real world

  11. None
  12. ͻͱͭͷ13͸ͻͱ ͭͷίϛοτʹ͢Δ A or B? ͻͱͭͷ13ʹෳ਺ ίϛοτΛؚΊΔ

  13. ͻͱͭͷ13͸ͻͱ ͭͷίϛοτʹ͢Δ A or B? or C? ͻͱͭͷ13ʹෳ਺ ίϛοτΛؚΊΔ

  14. SBJMTSBJMT *NQSPWF"DUJPO$BCMFSFDPOOFDUJPOSFMJBCJMJUZ

  15. None
  16. 独⽴してリバートできる独⽴した変更単位にしておく

  17. None
  18. None
  19. IUUQTSBJMTDPOGDPNWJEFPLFOUCFDLUJEZpSTU

  20. High Cohesion Low Coupling コミット粒度への設計における⾼凝集、疎結合

  21. ⼀番重要なのは独⽴してリバートできる アトミックな変更単位でコミットされて いるかどうかです。 そうでなければ変更理由ではなく 作業⼿順になっている可能性が あります。 l @koic says

  22. Koichi ITO / ESM, Inc. Kaigi on Rails STAY HOME

    Edition TDD with git. Long live engineering. 2020-10-03(Sat)
  23. Learn from history (SFFO 3FE 3FGBDUPS

  24. 1999 1994 2000 2002 2003 The dawn of modern engineering

  25. Green Red Test first (SFFO 3FE

  26. Green Refactor Red Test first and Refactoring (SFFO 3FE 3FGBDUPS

  27. 1999 1994 2000 2002 2003 TDD with CVS (2002-)

  28. Green Refactor Red Test Driven Development (SFFO 3FE 3FGBDUPS ಈ͔ͳ͍͔Βಈ͘΁ɺԚ͍͔Β៉ྷ΁

  29. Green Refactor Red TDD with SCM (SFFO 3FE 3FGBDUPS DPNNJU

    DPNNJU DPNNJU (SFFO DPNNJU Green
  30. 2005 2006 2007 2009 2008 Rails with SCM (2005-)

  31. • Rails͕࢓ࣄͰ࢖ΘΕ࢝Ίͨ2007೥ࠒͷόʔ δϣϯ؅ཧʹ͸Subversion͕࢖ΘΕ͍ͯͨ • git ͰͷϩʔΧϧϦϙδτϦͱ͍͏ͷ͸ͳ͘ɺ ྫ͑͹ϒϥϯνΛ࡞Ε͹ϦϞʔτϦϙδτϦ Ͱϒϥϯν͕࡞ΒΕɺίϛοτ͢Ε͹ϦϞʔ τϦϙδτϦͰνʔϜશମͰڞ༗͞Εͨ खʹ׼ѲΔSubversion࣌୅

  32. 2005 2006 2007 2009 2008 DSCM wars (Around 2008) HJUIHXBS

  33. • ෼ࢄSCMͰ͋ΔGit / Mercurial (hg) / Bazaar ͋ͨΓͰ೼ݖΛ૪͍ͬͯͨ • GitoliteͳͲͰࣾ಺GitαʔόʔΛཱͯͯɺmaster

    ʹ௚઀push͍ͯͨ͠ • git logͰmaster (main) ͷίʔυΛͲΕ͚ͩϨ Ϗϡʔ͠·͔͢ʁ GitHubҎલͷGitར༻ࣄྫ
  34. 2005 2006 2007 2009 2008 Raise of GitHub (2008) HJUIH

    XBS
  35. • GitHubొ৔ҎલͰɺCSV΍SubversionͰϒϥϯνΛ ࡞Δͷ͸ٽ͖ผΕͷϦϦʔεϒϥϯνͷ࡞੒΍trunk ʹࠞͥͨ͘ͳ͍ػೳΛฒߦ։ൃ͍ͨ͠ͱ͖ͩͬͨ • GitHubͷίʔυϨϏϡʔొ৔ʹΑΓPRͷͨΊͭ·Γ ίʔυϨϏϡʔͷͨΊʹϒϥϯνΛ࡞੒͢ΔΑ͏ʹ ͳͬͨ ϨϏϡʔͷͨΊͷϒϥϯν࡞੒͕ొ৔͢Δ

  36. ϨϏϡΞʔ͔Βͷఏ ҊʹΑΔϦϑΝΫλ Ϧϯάɺमਖ਼ ηϧϑϨϏϡʔΛ܁ Γฦ͢தͰͷϦϑΝ ΫλϦϯάɺमਖ਼ Refactoring with social coding

    Before PR After PR
  37. • ίʔυͷ੒௕ͷϨϕϧΞοϓ … master (main) ʹೖ Δલͷஈ֊Ͱɺࣗଞͷίʔυ͕ʮݟ͑ΔԽʯ͞Εͯ ΑΓྑ͍࣮૷ͷఏҊ΍ɺཁ݅΁ͷൈ͚࿙ΕΛϑΟʔ υόοΫͰ͖Δ •

    ਓͷϨϕϧΞοϓ … ࣗ෼ͷॻ͍ͨಈ͘ίʔυ΁ͷ ίʔυϨϏϡʔ͸ϦϙδτϦʹࢀՃ͍ͯ͠ΔγχΞ ͷࢹ఺Λ֫ಘ͢Δݱࡏ࠷ߴͷΤϯδχΞҭ੒ํ๏ ίʔυϨϏϡʔʹΑΔಇ͖ํվֵ
  38. 2005 2006 2007 2009 2008 Rails with Git/GitHub (2008-) HJUIH

    XBS
  39. SVNは⼆次元、 gitは三次元 l @amatsuda says দాޠ࿥ (2009೥)

  40. 10೥΋gitΛ৮͍ͬͯΔͱ Ͳ͏3࣍ݩͳͷ͔ͷղऍ͕ ੜ·Ε͍ͯΔͷͰ࿩͠·͢

  41. TDD with git (SFFO 3FE 3FGBDUPS

  42. TDD with git 5%% (JU

  43. Green Refactor Red Test Driven DevelopmentͷجຊϦζϜ (SFFO 3FE 3FGBDUPS 5%%

    (JU
  44. Green Refactor Red ࣮ફతͳTDDͷϦζϜ (SFFO 3FE 3FGBDUPS commit commit commit

    Basic 5%% (JU
  45. Green Refactor Red Consider `git push` (SFFO 3FE 3FGBDUPS commit

    commit commit (SFFO push CI Basic 5%% (JU
  46. Green Refactor Red ϩʔΧϧ͔ΒϦϞʔτʹpush͢Δͱ͸ʁ (SFFO 3FE 3FGBDUPS commit commit commit

    (SFFO push CI Basic 5%% (JU
  47. • ݸਓͷίʔυΛνʔϜͷίʔυʹ͢Δߦҝ • ݸਓͷίϛοτ͸࡞ۀͷ۠੾ΓͰ·Ίʹίϛοτ͢Δ Red, Green, Refactor…
 
 
 


    • νʔϜͷίϛοτͰ͸มߋཧ༝ΛḷΕΔΑ͏ʹ੔͑Δ git push (towards “Collective Ownership”) IUUQTUXJUUFSDPNU@XBEBTUBUVT
  48. Green Refactor Red ୭ͷͨΊͷίʔυʁ (SFFO 3FE 3FGBDUPS commit commit commit

    (SFFO push CI Basic 5%% (JU Personal Code Team’s Code $PMMFDUJWF 0XOFSTIJQ
  49. ͖Έ͸ݸਓͷ੒ޭͱνʔϜͷ੒ޭ ͲͪΒΛબͿʁ ಉ͡&DMJQTF*%&Λ࢖ͬͨ ϖΞϓϩάϥϛϯάͰΩʔόΠϯυ ͕͋Θͳ͍ɻ8%:5 @KKD asked @KentBeck KKD఻ฉ (2006೥ࠒ)

  50. Green Refactor Red ୭ͷͨΊͷίʔυʁ (SFFO 3FE 3FGBDUPS commit commit commit

    (SFFO push CI Basic 5%% (JU Personal Code Team’s Code $PMMFDUJWF 0XOFSTIJQ
  51. Green Refactor Red Advanced translation technique (SFFO 3FE 3FGBDUPS commit

    commit commit (SFFO push squash (and amend) CI Basic Advanced 5%% (JU 3FGBDUPS Personal Code Team’s Code commit design $PMMFDUJWF 0XOFSTIJQ
  52. HJUCMBNF ͳͲͰ௥੻͠΍͍͢ Α͏ʹมߋཧ༝ͷ୯ ҐͰίϛοτΛ·ͱ Ί͓ͯ͘ มߋཧ༝ʹ ج͍ͮͨ࡞ۀΛ͸͡ Ίͯɺ࡞ۀͷ੾Ε໨ ੾Ε໨Ͱςετͱί ϛοτΛ͍ͯ͘͠

    ϦϑΝΫλϦϯάաఔͱϦϑΝΫλϦϯάޙ pushޙ (ϝϯςφϯεͰಡΉͱ͖) pushલ (ίʔυΛॻ͍͍ͯΔͱ͖) ಈࢺͱͯ͠ͷϦϑΝΫλϦϯάΛਐΊ͍ͯΔ΋ͷ ϦϑΝΫλϦϯάͷ݁Ռ (Χλϩάͷafter) Λ squash͔ͨ͋ͨ͠΋࠷ॳ͔Β៉ྷͳίʔυ
  53. • ࠷ॳ͔Β៉ྷͳίʔυΛॻ͚ΔεʔύʔΤϯδχΞʹ͸ ϦϑΝΫλϦϯά͸ෆཁ͔΋͠Εͳ͍ • ࠷ॳ͔Β៉ྷͳίʔυΛॻ͘͜ͱ͕೉ͯ͘͠΋ςετΛݩʹ ϦϑΝΫλϦϯάΛ܁ΓฦͤΔͱ͍͏TDDͱ͍͏εΩϧ • TDD (Baby steps

    by XP) ʹΑͬͯ࡞ۀܦաίϛοτ͕૿͑Δ • ࡞ۀͷ్தܦաΛsquash͢Δ͜ͱͰεʔύʔΤϯδχΞͱಉ ݁͡Ռʹ͚ۙͮͨίϯτϦϏϡʔγϣϯΛνʔϜʹͰ͖Δ ;ͭ͏ͷਓͷͨΊͷTDDϦϑΝΫλϦϯάͱͦͷઌ
  54. pick, squash, or another PR? ࣮૷աఔͰͷςετ௥Ճɺ όάϑΟοΫε΍খ͞ͳϦ ϑΝΫλϦϯάͰ͔͢ʁ TRVBTI QJDL

    ϦϦʔεࠩ͠໭͠ͷͱ͖ ͳͲಠཱͯ͠Ϧόʔτ͠ ͍ͨίϛοτͰ͔͢ʁ "OPUIFS 13 ͻͱͭͷϒϥϯνʹͻ ͱͭͷίϛοτ͚ͩͰ ͔͢ʁ ػೳͷ௥Ճมߋͱ෼཭ Ͱ͖Δطଘػೳ΁ͷϦ ϑΝΫλϦϯάͰ͔͢ʁ ΋͠ϨϏϡʔͰͷࢦఠͰͳ ࣗ͘ྗͰؾ͍͍ͮͯͨΒ ίϛοτΛ෼͚·͔͢ʁ ͻͱͭͷPRʹෳ਺ͷػ ೳཁٻʹର͢Δมߋ͕ ࠞ͟Γ·͔͢ʁ No Yes Yes No Yes No Yes Yes No Yes No No Start ಠཱͯ͠ϚʔδͰ͖Δ
  55. ฏ໘ͰੵΉ͚͔ͩ͠Ͱ͖ͳ͔ͬͨೋ࣍ݩ͔Β ཱମతʹ੔͑ΒΕΔࡾ࣍ݩ΁ ϦϑΝΫλϦϯάͷ݁ՌΛsquashͯ͠ (ίʔυϨϏϡʔ) ͔͋ͨ΋ ࠷ॳͷίϛοτ͔Β ಈ͘៉ྷͳίʔυʹͰ͖Δ

  56. Refactoring commits (SFFO 3FE 3FGBDUPS

  57. ,BUB

  58. • ʮၗຫɺଵଦɺ୹ؾʯͷඒֶʹͷͬͱͬͯɺࣗ෼ͷ ࡞ۀޮ཰Λ೗Կʹ্͛Δ͔ͱ͍͏໋୊ • ߟ͑ͳͯ͘΋ख͕ಈ͘͘Β͍ͷࣗ෼ͷKataͮ͘Γ • ࡞ۀͷ੾Ε໨ͱͯ͠ͷ fixup ίϛοτͱɺมߋ୯Ґ ͷίϛοτ͕͋ͬͯɺࣗ෼͸ΤΠϦΞεΛ࢖ͬͯ

    git ૢ࡞ϨϕϧͰ෼͚͍ͯ·͢ (զྲྀΤΠϦΞε) TDD with git commit (ࢲͷܕ)
  59. Use `--fixup` to temporary commit HDJNb"EEOFXA'PP#BSADPQ` <UPQJDBDFD>"EEOFXA'PP#BSADPQ HDJNb&YUSBDUNFUIPE` <UPQJDGEED>&YUSBDUNFUIPE HDJNb'JYBUZQP`

    <UPQJDGEED>'JYBUZQP HDJNb3FOBNFNFUIPE` <UPQJDGEED>3FOBNFNFUIPE HSJHJUSFCBTFJ)&"%d 3FNPWFDPNNJUNFTTBHFTPUIFSUIBO UIFpSTUNFTTBHFBOERVJUUIFFEJUPS git commit HDJNb"EEOFXA'PP#BSADPQ` <UPQJDBDFD>"EEOFXA'PP#BSADPQ HDG <UPQJDGEED>pYVQ"EEOFXA'PP#BSADPQ HDG <UPQJDGEED>pYVQpYVQ"EEOFXA'PP#BSA DPQ HDG <UPQJDGEED>pYVQpYVQpYVQ"EEOFX A'PP#BSADPQ HSJ 2VJUUIFFEJUPS git commit --fixup=HEAD Before Current
  60. ࡞ۀཧ༝ͷίϛοτϝοηʔδΛؤுΒͳ͍ HDJNb"EEOFXA'PP#BSADPQ` <UPQJDBDFD>"EEOFXA'PP#BSADPQ HDJNb&YUSBDUNFUIPE` <UPQJDGEED>&YUSBDUNFUIPE HDJNb'JYBUZQP` <UPQJDGEED>'JYBUZQP HDJNb3FOBNFNFUIPE` <UPQJDGEED>3FOBNFNFUIPE HSJHJUSFCBTFJ)&"%d

    3FNPWFDPNNJUNFTTBHFTPUIFSUIBO UIFpSTUNFTTBHFBOERVJUUIFFEJUPS commit commit commit commit
  61. ΤΠϦΞεΛ׆༻͢Δ e.g.: git config --global alias.ci commit

  62. Four my git aliases I use a lot SJTIDHJUSFCBTFJ)&"%d 1.

    First commit in the new branch 2. Second commit and the subsequence 3. Squash the above commits into one DGDPNNJUWpYVQ)&"% DJDPNNJUW DBDPNNJUWBNFOE 4. Amend a commit message
  63. Before HDJNb"EEOFXA'PP#BSADPQ` <UPQJDBDFD>"EEOFXA'PP#BSADPQ HDJNb&YUSBDUNFUIPE <UPQJDGEED>&YUSBDUNFUIPE HDJNb'JYBUZQP <UPQJDGEED>'JYBUZQP HDJNb3FOBNFNFUIPE` <UPQJDGEED>3FOBNFNFUIPE HSJ

    3FNPWFDPNNJUNFTTBHFTPUIFSUIBO UIFpSTUNFTTBHFBOERVJUUIFFEJUPS git commit ΛϦϑΝΫλϦϯάͷ౎౓ͯ͠ɺ࠷ޙʹsquash͢Δ 5IJOLBCPVUUIFDPNNJUNFTTBHF 5IJOLBCPVUUIFDPNNJUNFTTBHF 5IJOLBCPVUUIFDPNNJUNFTTBHF 5IJOLBCPVUUIFDPNNJUNFTTBHF /FFEUPBEKVTUUPDPNNJUNFTTBHF
  64. Current HDJNb"EEOFXA'PP#BSADPQ` <UPQJDBDFD>"EEOFXA'PP#BSADPQ HDG <UPQJDGEED>pYVQ"EEOFXA'PP#BSADPQ HDG <UPQJDGEED>pYVQpYVQ"EEOFXA'PP#BSA DPQ HDG <UPQJDGEED>pYVQpYVQpYVQ"EEOFX

    A'PP#BSADPQ HSJ 2VJUUIFFEJUPS git commit —fixup=HEAD Ͱ਺चͭͳ͗ͯ͠ɺsquash Ͱ·ͱΊΔ %PO`U5IJOLBCPVUUIFDPNNJUNFTTBHF %PO`U5IJOLBCPVUUIFDPNNJUNFTTBHF 5IJOLBCPVUUIFDPNNJUNFTTBHF %PO`U5IJOLBCPVUUIFDPNNJUNFTTBHF /PBEKVTUNFOUUPDPNNJUNFTTBHFSFRVJSFE You can think about the details of the commit message
  65. ci = commit -v ͱ͍͏ΤΠϦΞεͰɺPRϒϥϯν΁ ͷ࠷ॳͷίϛοτʹ g ci . -m

    'message' Λ࢖͏ 2 types of commit methods มߋཧ༝΁ͷίϛοτ ࡞ۀͷ੾Ε໨΁ͷίϛοτ cf = commit -v --fixup=HEAD ͱ͍͏ΤΠϦΞεͰɺ
 PRϒϥϯν΁ͷϦϑΝΫλϦϯάͰg cf . Λ૬౰ʹ࢖͏
  66. • git commit --fixupʹΑͬͯɺ࡞ۀͷηʔϒϙΠϯτ ͱͳΔίϛοτϝοηʔδ΁ͷߟྀෛՙΛͳ͘͢ • fixupίϛοτ͸͋ͱͰrebase (squash)͢Δͱ͖ ʹɺσϑΥϧτͰfixupʹͳ͍ͬͯΔͷͰศར •

    fixup͸squashͱҟͳΓίϛοτϝοηʔδͷฤूʹ ίϛοτϝοηʔδͷλΠτϧ͕ग़ͯͣ͜ฤूෆཁ fixup vs squash
  67. `fixup! `Ͱ࢝·Δίϛοτؚ͕·ΕΔ৔߹ʹ pushͨ͘͠ͳ͚Ε͹git hookͰࣗಈԽ git hookͰ`fixup!`ίϛοτͷpush๷ࢭ CJOTI JG< HJUMPHPOFMJOFNBTUFSIFBEcHSFQpYVQ >UIFO

    FDIPa<N<"#035>:PVDBOOPUQVTIBDPNNJUXIPTFUJUMFTUBSUTaApYVQaA a<N FYJU p FYJU
  68. • SubversionͰ͸ϦϑΝΫλϦϯάதͷηʔϒϙΠϯτ Ͱͷίϛοτ͕νʔϜͰڞ༗͞Ε͍ͯͨ • gitͰ͸࡞ۀखॱͰ͸ͳ͘ɺมߋཧ༝ͷཻ౓ʹฤूͨ͠ ίϛοτʹ·ͱΊ͔ͯΒνʔϜͰڞ༗Ͱ͖ΔΑ͏ʹ ͳͬͨ • εʔύʔΤϯδχΞͰͳͯ͘΋࠷ॳ͔ΒΫΦϦςΟͷ ߴ͘Ұචॻ͖͕Ͱ͖͔ͨͷΑ͏ͳίϛοτΛ࡞ΕΔ

    ίϛοτͷཻ౓Λ࡞ۀखॱͰ͸ͳ͘มߋཧ༝ʹͰ͖Δ
  69. Conclusion (SFFO 3FE 3FGBDUPS

  70. • TDDͰ͸খ͘͞খ͘͞ͷίϛοτཻ౓ͱͳΔ • ڞ༗ϦϙδτϦʹ͸มߋཧ༝Ͱͷίϛοτཻ౓Λ࢒͢ • ϩάΛḷΔࡍʹɺςετϑΝʔετͰ࣮૷ͨ͠΋ͷ͔ɺςετϥε τͰ࣮૷ͨ͠΋ͷ͔ɺϨϏϡʔͷ൓ө͔Ͳ͏͔͸ॏཁͰ͸ͳ͍ • ͦΕΒҟͳΔཻ౓΁ม׵͢Δͷ͕rebaseͰ͋ΓSubversionͰ͸Ͱ ͖ͳ͔ͬͨ͜ͱ

    • ίʔυઃܭͷΑ͏ʹίϛοτઃܭΛ͢Δ͜ͱͰɺϝϯςφϏϦ ςΟΛ্͛Δ͜ͱ͕Ͱ͖Δ ৽ੈلίϛοτઃܭ
  71. ਓؒ͸ͩΜͩΜͱ ͏·͘ͳ͍ͬͯ͘

  72. “Tools and techniques change often, but they don't change a

    lot People, however, change slowly but deeply. XPE2nd Chap. 23 ツールと技術は頻繁に変わるが、⼤幅に変わることはない。 しかし、⼈はゆっくりだが深く変わっていく。 Embrace Change (มԽϮ๊༴ηϤ)
  73. Have a happy engineering by TDD with git!