SlideShare a Scribd company logo
Practical SVN  for PHP Developers Matthew Weier O'Phinney Project Lead Zend Framework Lorna Jane Mitchell Software Engineer Ibuildings
What is Version Control?
What did  you  change from the previous revision? What changes have  others  recorded since your last local update? Change Management
Types of  Version Control
Each checkout is a fully functional repository Anybody may accept patches from anyone else Anybody may send patches to anyone else Ideal for projects with parallel feature developement Distributed
One canonical repository  All changes are submitted to the repository All changes are retrieved from the repository Ideal when: a canonical version is required,  access to the repository should be controlled Non-Distributed
What is Subversion?
Non-Distributed Version Control System Successor to CVS Stores and versions: source code documentation anything, really Subversion is...
Installing Subversion
Choose a Protocol
give repo access to local users give users and/or groups read/write on the repo to grant access file:///home/lorna/svn-repos/main/trunk/ Local filesystem
give repo access to users with ssh credentials  give users and/or groups read/write on the repo to grant access svn+ssh svn://rivendell/home/lorna/svn-repos/main/trunk svn+ssh
make repo web-browseable and have apache handle credentials basic or digest HTTP authentication (e.g., .htpasswd) mod_authz_svn - an Apache module to give finer access control http://svn.example.com/main/trunk WebDAV via HTTP/S
Installing on Linux
Debian/Ubuntu:  aptitude install subversion Fedora/RedHat:  yum install subversion Distribution packages
download from http://subversion.tigris.org check dependencies (install apache, mod_dav, etc., first) compile From source
Setting up a repository
What  is  a repository ?
The place all changesets are stored A black box; you may only interact with it using svn tools A repository is...
Creating the repository
Use ā€œsvnadmin createā€
Create initial content
Commit initial structure
Alternate way: import into the repo
About repository structure
Trunk  – the main code version Branches  – copies of code which can be modified Tags  – copies of code which are never changed All are ā€œcheapā€ copies Repository Structure
Using Subversion
Checkout: svn checkout (co)
.svn directory
Status: svn status (st)
' ' no modifications 'A' Added 'C' Conflicted 'D' Deleted 'M' Modified '?' item is not under version control '!' item is missing (removed by non-svn command) or incomplete 'X' external resource managed by svn (svn:externals) Common status codes
Add to repo: svn add
Commit to repo: svn commit (ci)
Changelog: svn log
Dealing with missing files
ā€œ !ā€ in the status listing Usually because something was moved or deleted  without using the svn tools Always  use svn rm and svn mv To fix: update (svn up) and try again Missing files - ! in the status
What and When to commit
hourly, semi-daily, daily checkins code only, tests only, docs only Bad  practices
Each commit should include all code, tests, and docs related to a discrete behavior or set of functionality. The  Best Practice:
Easy to ā€œcherry-pickā€ changesets between branches Trivial to identify changesets to rollback Why?
Examples
Examples
PLAN your project; break it into distinct units of functionality Use an issue tracker; issues should include expectations, actual results, and reproduce code (these become your tests!) No unit of functionality should take more than 3-4 hours to implement; longer, and it likely should be broken into sub-tasks. How?
Conflicts
svn  blame / annotate / praise shows who last edited which line svn blame
Example
Two people change same line of same file svn will ask user to choose Conflicts
index.php.r4  version from before either your changes or the commit that has conflicted index.php.r6  current repo version index.php.mine  working copy before server showed conflict index.php  whole file with some markup to show just the conflict(s) in place Example: conflict adds files
edit index.php until correct may copy one of the "extra" files into place of this one let SVN know you're all sorted svn resolved
Good team communication Update often Commit first! Avoiding Conflicts
Branching and Tagging
Patterns
Feature Branches Graph by Eli White
Pros: Features may be developed in isolation Trunk always contains ā€œfinishedā€ features Cons: Features may be developed in isolation Hard to cleanly merge at times if multiple features touch the same areas of code Harder to rollback (trunk doesn't always have discrete featuresets) Feature Branches
Long-lived Branches Graph by Eli White
Pros: Production is always stable Rollback by pointing to production tags Cons: Long-lived feature development often lags trunk features Difficult to determine what to merge Difficult to do parallel feature development More difficult to rollback specific features Long-lived Branches
Release Branches Graph by Eli White
Pros: Easy to isolate features by version (parallel development) Possibility of keeping multiple active versions of a project Cons: Harder to merge patches between branches (files may differ widely) Release Branches
Merging
Moving changes between branches (including trunk) Merge single changes Merging as part of a branch lifecycle Merging
Check out the target branch From the target directory, run svn diff until the output illustrates the operation you wanted Replace "diff" with "merge" Review changes to working copy and/or test How to merge
Use ā€œsvn logā€ to identify discrete changesets you want to merge. Use the ā€œcherry-pickā€ flag of ā€œsvn mergeā€ (-c) to merge that single changeset. Works well if you're following the best practices outlined earlier! How to merge: the easy way
Administering Repositories
Backing up your Repository
Copying files directly can lead to corruption in the copy Use ā€œsvnadmin hotcopyā€ or  ā€œsvnadmin dumpā€ svnadmin hotcopy
Authentication
Dependent on how the OS does authentication: Local accounts ā€œ Virtualā€ accounts etc. SSH public keys are a common solution svnserve or svn+ssh
Typically HTTP basic or digest authentication Use htpasswd to generate user/pass pairs Can still allow anonymous access Configure your server to require it WebDAV (http/https)
Example HTTP Auth configuration
Authorization
Typically conf/authz in your repo, or ā€œaccess.confā€ accessible to web server INI-style file with [sections] [groups]  section to define users and groups [/path]  specifies path on repo [repo:/path]  specifies path on specific repo (if more than one repo defined) ACL File
ACLs: [user|group] = [r|rw] ā€œ *ā€ as group/user means any user Groups are prefixed with ā€œ@ā€ ACL File
ACL File: example
Svnserve, file access, or svn+ssh: conf/authz in your repository WebDAV: anywhere.  Tell your vhost where to find it Must setup authorization prior to authentication ACL File: placement
ACL File in WebDAV: vhost setup
Hooks
Allow extending SVN's capabilities via userland scripts ā€œ Hookā€ into specific processes: pre/post-commit, start-commit pre/post-revprop-change pre/post-lock pre/post-unlock What are hooks?
Running a linter REPOS = "$1" TXN = "$2" PHP = "/path/to/php" SVNLOOK = "/path/to/svnlook" AWK = "/path/to/awk" GREP = "/path/to/egrep" SED = "/path/to/sed" CHANGED = `$SVNLOOK changed -t "$TXN" "$REPOS" | \ $AWK '{print $2}' | \ $GREP   \\.php$` for   FILE   in   $CHANGED do MESSAGE = `$SVNLOOK cat -t "$TXN" "$REPOS" "$FILE" | $PHP -l` if   [   $?   - ne   0   ] then echo   1 >& 2 echo   "***********************************"   1 >& 2 echo   "PHP error in: $FILE:"   1 >& 2 echo   `echo "$MESSAGE" | $SED "s| -| $FILE|g"`   1 >& 2 echo   "***********************************"   1 >& 2 exit   1 fi done
*********************************** PHP error in: test.php echo $foobar *********************************** Sample linter output
Run post-commit – prevents blocking issues Send email notification when tests fail Two approaches: Run entire suite Grep committed files for classes, and test just those classes Typically best to do this from a Continuous Integration server, and not via subversion hooks Running unit tests
Email, Nabaztag, TwitterSVN Email notifications post-commit SVN::Notify: http://search.cpan.org/~dwheeler/SVN-Notify-2.79/lib/SVN/Notify.pm Can selectively determine which people/lists get notifications based on commit path Plain text and/or HTML emails Sending notifications
Example notification:
svn2feed.py: http://svn.collab.net/repos/svn/trunk/tools/hook-scripts/svn2feed.py Add svn2feed.py to your hooks/ directory Publishing RSS Feeds
Adding svn2feed.py to your  post-commit hook: path / to / python path / to / hooks / svn2feed.py \ -- svn - path   / usr / bin /   \ -- max - items = 100   \ -- format = atom \ -- revision   "$REV"   – item - url \   "http://localhost/svn/"  \ -- feed - url = "http://localhost/rss/svn.rss"  \ -- feed - file   "path/to/rss/svn.rss"  \ "$REPOS"   &
Trigger docbook build process, or PhpDocumentor Run post-commit, so as not to block Typically best done from a CI server, and not subversion hooks Generating documentation
PHP_CodeSniffer includes a script,   bin/scripts/phpcs-svn-pre-commit Edit the script to provide the path to svnlook: define('PHP_CODESNIFFER_SVNLOOK',  '/usr/bin/svnlook'); Edit the pre-commit hook script to invoke the   script: /path/to/bin/scripts/phpcs-svn-pre-commit "$REPOS" -t "$TXN" >&2 || exit 1 Running PHP_CodeSniffer
Transmitting file data .svn: Commit failed (details follow): svn: 'pre-commit' hook failed with error output: FILE: temp.php --------------------------------------------------------------- FOUND 1 ERROR(S) AND 0 WARNING(S) AFFECTING 1 LINE(S) --------------------------------------------------------------- 2 | ERROR | Missing file doc comment -------------------------------------------------------------- PHP_CodeSniffer hook output
http://pear.php.net/manual/en/package.php.php-codesniffer.svn-pre-commit.php For more info on PHP_CodeSniffer:
Deploying from SVN
What else needs to happen at deploy time? Preserve uploads Set permissions Database patches Deployment Considerations
Checkout retains link to repo Meta data present on server Inconsistent state during update Export is clean copy, no dependencies Other ways to keep track of version Checkout or Export
Tag and export from svn – include some tag info Use symlinks to enable seamless switching Wrap in a script Have a rollback plan/script Consider database strategies Best Practices
Thank you.

More Related Content

PPTX
SVN Information
RAHUL TRIPATHI
Ā 
PDF
How to use CVS applied to SOLab
Pablo Arriazu
Ā 
PPTX
Using svn
Shiva Somvanshi
Ā 
PDF
Svn tutorial
kalyansiri
Ā 
PDF
Digital Fabrication Studio 0.3 Information
Massimo Menichinelli
Ā 
PDF
Digital Fabrication Studio.02 _Information @ Aalto Media Factory
Massimo Menichinelli
Ā 
PDF
sed.pdf
MaenAlWedyan
Ā 
PDF
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy
Ā 
SVN Information
RAHUL TRIPATHI
Ā 
How to use CVS applied to SOLab
Pablo Arriazu
Ā 
Using svn
Shiva Somvanshi
Ā 
Svn tutorial
kalyansiri
Ā 
Digital Fabrication Studio 0.3 Information
Massimo Menichinelli
Ā 
Digital Fabrication Studio.02 _Information @ Aalto Media Factory
Massimo Menichinelli
Ā 
sed.pdf
MaenAlWedyan
Ā 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Ahmed El-Arabawy
Ā 

What's hot (20)

PDF
Jaringan, Linux, Docker
SatrioBudi10
Ā 
ODP
The Gory Details of Debian packages
Jeremiah Foster
Ā 
ODP
Packaging for the Maemo Platform
Jeremiah Foster
Ā 
PDF
Jenkins Pipelines
Steffen Gebert
Ā 
PDF
Docker & ci
Patxi GortƔzar
Ā 
PDF
Concourse Workshop
VMware Tanzu
Ā 
PPTX
ONOS System Test - ONS2016
Suibin Zhang
Ā 
PDF
PVS-Studio in the Clouds: Travis CI
Andrey Karpov
Ā 
PDF
Divorcing System
Shawn Sorichetti
Ā 
PDF
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the Web
Steffen Gebert
Ā 
PPTX
Subversion proper renaming and merging as if you’ve read the whole code of co...
Fazreil Amreen Abdul Jalil
Ā 
PDF
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Flink Forward
Ā 
PPT
Rational Robot (http://www.geektester.blogspot.com)
raj.kamal13
Ā 
PPTX
Introduce fuego
s60030
Ā 
PPT
Build service with_docker_in_90mins
Larry Cai
Ā 
PDF
Care and Feeding of Large Web Applications
Perrin Harkins
Ā 
PDF
Docker presentasjon java bin
Olve Hansen
Ā 
PPTX
Infrastructure testing with Molecule and TestInfra
Tomislav Plavcic
Ā 
PPTX
Drupal & Continous Integration - SF State Study Case
Emanuele Quinto
Ā 
Jaringan, Linux, Docker
SatrioBudi10
Ā 
The Gory Details of Debian packages
Jeremiah Foster
Ā 
Packaging for the Maemo Platform
Jeremiah Foster
Ā 
Jenkins Pipelines
Steffen Gebert
Ā 
Docker & ci
Patxi GortƔzar
Ā 
Concourse Workshop
VMware Tanzu
Ā 
ONOS System Test - ONS2016
Suibin Zhang
Ā 
PVS-Studio in the Clouds: Travis CI
Andrey Karpov
Ā 
Divorcing System
Shawn Sorichetti
Ā 
Cleaning Up the Dirt of the Nineties - How New Protocols are Modernizing the Web
Steffen Gebert
Ā 
Subversion proper renaming and merging as if you’ve read the whole code of co...
Fazreil Amreen Abdul Jalil
Ā 
Simon Laws – Apache Flink Cluster Deployment on Docker and Docker-Compose
Flink Forward
Ā 
Rational Robot (http://www.geektester.blogspot.com)
raj.kamal13
Ā 
Introduce fuego
s60030
Ā 
Build service with_docker_in_90mins
Larry Cai
Ā 
Care and Feeding of Large Web Applications
Perrin Harkins
Ā 
Docker presentasjon java bin
Olve Hansen
Ā 
Infrastructure testing with Molecule and TestInfra
Tomislav Plavcic
Ā 
Drupal & Continous Integration - SF State Study Case
Emanuele Quinto
Ā 
Ad

Similar to Practical SVN for PHP Developers (20)

ODP
Burlington, VT PHP Users Group Subversion Presentation
Bradley Holt
Ā 
PDF
Versioning for Developers
Michelangelo van Dam
Ā 
PPT
SVN Usage & Best Practices
Ashraf Fouad
Ā 
PPTX
Source version control using subversion
Mangesh Bhujbal
Ā 
PPTX
Getting Started With Subversion
Jordan Hatch
Ā 
ODP
Svn Basic Tutorial
Marco Pivetta
Ā 
PPT
Subversion
Tricode (part of Dept)
Ā 
PPTX
Subversion
Vaibhav Sakhalkar
Ā 
PPT
SVN Tool Information : Best Practices
Maidul Islam
Ā 
PPTX
SVN
enggHeads
Ā 
PDF
Version Control with SVN
PHPBelgium
Ā 
PDF
Git your life for fun & profit
Geeks Anonymes
Ā 
PPT
Totalsvn Usage And Administration By Gopi
gopinathkarangula
Ā 
KEY
Version control with subversion
xprayc
Ā 
PPT
Subversion (SVN)
manugoel2003
Ā 
PPT
How to setup Svn in system
Mohammed Nayeem
Ā 
PDF
Git your life for fun & profit
Interface ULg, LIEGE science park
Ā 
PPTX
Subversion
thebdot1
Ā 
PDF
Git vs Subversion: ĀæCuando elegir uno u otro?
Paradigma Digital
Ā 
ODP
Subversionn Introduction at SuperMondays 2009-09-01
Alex Kavanagh
Ā 
Burlington, VT PHP Users Group Subversion Presentation
Bradley Holt
Ā 
Versioning for Developers
Michelangelo van Dam
Ā 
SVN Usage & Best Practices
Ashraf Fouad
Ā 
Source version control using subversion
Mangesh Bhujbal
Ā 
Getting Started With Subversion
Jordan Hatch
Ā 
Svn Basic Tutorial
Marco Pivetta
Ā 
Subversion
Vaibhav Sakhalkar
Ā 
SVN Tool Information : Best Practices
Maidul Islam
Ā 
SVN
enggHeads
Ā 
Version Control with SVN
PHPBelgium
Ā 
Git your life for fun & profit
Geeks Anonymes
Ā 
Totalsvn Usage And Administration By Gopi
gopinathkarangula
Ā 
Version control with subversion
xprayc
Ā 
Subversion (SVN)
manugoel2003
Ā 
How to setup Svn in system
Mohammed Nayeem
Ā 
Git your life for fun & profit
Interface ULg, LIEGE science park
Ā 
Subversion
thebdot1
Ā 
Git vs Subversion: ĀæCuando elegir uno u otro?
Paradigma Digital
Ā 
Subversionn Introduction at SuperMondays 2009-09-01
Alex Kavanagh
Ā 
Ad

More from Lorna Mitchell (20)

PDF
OAuth: Trust Issues
Lorna Mitchell
Ā 
PDF
Web Services PHP Tutorial
Lorna Mitchell
Ā 
PDF
Best Practice in API Design
Lorna Mitchell
Ā 
PDF
Git, GitHub and Open Source
Lorna Mitchell
Ā 
PDF
Business 101 for Developers: Time and Money
Lorna Mitchell
Ā 
ODP
Things I wish web graduates knew
Lorna Mitchell
Ā 
PDF
Teach a Man To Fish (phpconpl edition)
Lorna Mitchell
Ā 
PDF
Web services tutorial
Lorna Mitchell
Ā 
ODP
Join In With Joind.In
Lorna Mitchell
Ā 
PDF
Tool Up Your LAMP Stack
Lorna Mitchell
Ā 
PDF
Going Freelance
Lorna Mitchell
Ā 
PDF
Understanding Distributed Source Control
Lorna Mitchell
Ā 
PDF
Best Practice in Web Service Design
Lorna Mitchell
Ā 
PDF
Coaching Development Teams: Teach A Man To Fish
Lorna Mitchell
Ā 
PDF
Zend Certification Preparation Tutorial
Lorna Mitchell
Ā 
PDF
Implementing OAuth with PHP
Lorna Mitchell
Ā 
PDF
Web Services Tutorial
Lorna Mitchell
Ā 
PDF
Object Oriented Programming in PHP
Lorna Mitchell
Ā 
PDF
Example Presentation
Lorna Mitchell
Ā 
PDF
Could You Telecommute?
Lorna Mitchell
Ā 
OAuth: Trust Issues
Lorna Mitchell
Ā 
Web Services PHP Tutorial
Lorna Mitchell
Ā 
Best Practice in API Design
Lorna Mitchell
Ā 
Git, GitHub and Open Source
Lorna Mitchell
Ā 
Business 101 for Developers: Time and Money
Lorna Mitchell
Ā 
Things I wish web graduates knew
Lorna Mitchell
Ā 
Teach a Man To Fish (phpconpl edition)
Lorna Mitchell
Ā 
Web services tutorial
Lorna Mitchell
Ā 
Join In With Joind.In
Lorna Mitchell
Ā 
Tool Up Your LAMP Stack
Lorna Mitchell
Ā 
Going Freelance
Lorna Mitchell
Ā 
Understanding Distributed Source Control
Lorna Mitchell
Ā 
Best Practice in Web Service Design
Lorna Mitchell
Ā 
Coaching Development Teams: Teach A Man To Fish
Lorna Mitchell
Ā 
Zend Certification Preparation Tutorial
Lorna Mitchell
Ā 
Implementing OAuth with PHP
Lorna Mitchell
Ā 
Web Services Tutorial
Lorna Mitchell
Ā 
Object Oriented Programming in PHP
Lorna Mitchell
Ā 
Example Presentation
Lorna Mitchell
Ā 
Could You Telecommute?
Lorna Mitchell
Ā 

Recently uploaded (20)

PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
Ā 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
Ā 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 
PDF
Software Development Methodologies in 2025
KodekX
Ā 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
Ā 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
Ā 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
Ā 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
Ā 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
Ā 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
Ā 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
Ā 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
Ā 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 
Software Development Methodologies in 2025
KodekX
Ā 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
Ā 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
Ā 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
Ā 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
Ā 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
Ā 
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
Ā 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
Ā 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
Ā 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
REPORT: Heating appliances market in Poland 2024
SPIUG
Ā 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
Ā 

Practical SVN for PHP Developers

  • 1. Practical SVN for PHP Developers Matthew Weier O'Phinney Project Lead Zend Framework Lorna Jane Mitchell Software Engineer Ibuildings
  • 2. What is Version Control?
  • 3. What did you change from the previous revision? What changes have others recorded since your last local update? Change Management
  • 4. Types of Version Control
  • 5. Each checkout is a fully functional repository Anybody may accept patches from anyone else Anybody may send patches to anyone else Ideal for projects with parallel feature developement Distributed
  • 6. One canonical repository All changes are submitted to the repository All changes are retrieved from the repository Ideal when: a canonical version is required, access to the repository should be controlled Non-Distributed
  • 8. Non-Distributed Version Control System Successor to CVS Stores and versions: source code documentation anything, really Subversion is...
  • 11. give repo access to local users give users and/or groups read/write on the repo to grant access file:///home/lorna/svn-repos/main/trunk/ Local filesystem
  • 12. give repo access to users with ssh credentials give users and/or groups read/write on the repo to grant access svn+ssh svn://rivendell/home/lorna/svn-repos/main/trunk svn+ssh
  • 13. make repo web-browseable and have apache handle credentials basic or digest HTTP authentication (e.g., .htpasswd) mod_authz_svn - an Apache module to give finer access control http://svn.example.com/main/trunk WebDAV via HTTP/S
  • 15. Debian/Ubuntu: aptitude install subversion Fedora/RedHat: yum install subversion Distribution packages
  • 16. download from http://subversion.tigris.org check dependencies (install apache, mod_dav, etc., first) compile From source
  • 17. Setting up a repository
  • 18. What is a repository ?
  • 19. The place all changesets are stored A black box; you may only interact with it using svn tools A repository is...
  • 24. Alternate way: import into the repo
  • 26. Trunk – the main code version Branches – copies of code which can be modified Tags – copies of code which are never changed All are ā€œcheapā€ copies Repository Structure
  • 31. ' ' no modifications 'A' Added 'C' Conflicted 'D' Deleted 'M' Modified '?' item is not under version control '!' item is missing (removed by non-svn command) or incomplete 'X' external resource managed by svn (svn:externals) Common status codes
  • 32. Add to repo: svn add
  • 33. Commit to repo: svn commit (ci)
  • 36. ā€œ !ā€ in the status listing Usually because something was moved or deleted without using the svn tools Always use svn rm and svn mv To fix: update (svn up) and try again Missing files - ! in the status
  • 37. What and When to commit
  • 38. hourly, semi-daily, daily checkins code only, tests only, docs only Bad practices
  • 39. Each commit should include all code, tests, and docs related to a discrete behavior or set of functionality. The Best Practice:
  • 40. Easy to ā€œcherry-pickā€ changesets between branches Trivial to identify changesets to rollback Why?
  • 43. PLAN your project; break it into distinct units of functionality Use an issue tracker; issues should include expectations, actual results, and reproduce code (these become your tests!) No unit of functionality should take more than 3-4 hours to implement; longer, and it likely should be broken into sub-tasks. How?
  • 45. svn blame / annotate / praise shows who last edited which line svn blame
  • 47. Two people change same line of same file svn will ask user to choose Conflicts
  • 48. index.php.r4 version from before either your changes or the commit that has conflicted index.php.r6 current repo version index.php.mine working copy before server showed conflict index.php whole file with some markup to show just the conflict(s) in place Example: conflict adds files
  • 49. edit index.php until correct may copy one of the "extra" files into place of this one let SVN know you're all sorted svn resolved
  • 50. Good team communication Update often Commit first! Avoiding Conflicts
  • 53. Feature Branches Graph by Eli White
  • 54. Pros: Features may be developed in isolation Trunk always contains ā€œfinishedā€ features Cons: Features may be developed in isolation Hard to cleanly merge at times if multiple features touch the same areas of code Harder to rollback (trunk doesn't always have discrete featuresets) Feature Branches
  • 56. Pros: Production is always stable Rollback by pointing to production tags Cons: Long-lived feature development often lags trunk features Difficult to determine what to merge Difficult to do parallel feature development More difficult to rollback specific features Long-lived Branches
  • 57. Release Branches Graph by Eli White
  • 58. Pros: Easy to isolate features by version (parallel development) Possibility of keeping multiple active versions of a project Cons: Harder to merge patches between branches (files may differ widely) Release Branches
  • 60. Moving changes between branches (including trunk) Merge single changes Merging as part of a branch lifecycle Merging
  • 61. Check out the target branch From the target directory, run svn diff until the output illustrates the operation you wanted Replace "diff" with "merge" Review changes to working copy and/or test How to merge
  • 62. Use ā€œsvn logā€ to identify discrete changesets you want to merge. Use the ā€œcherry-pickā€ flag of ā€œsvn mergeā€ (-c) to merge that single changeset. Works well if you're following the best practices outlined earlier! How to merge: the easy way
  • 64. Backing up your Repository
  • 65. Copying files directly can lead to corruption in the copy Use ā€œsvnadmin hotcopyā€ or ā€œsvnadmin dumpā€ svnadmin hotcopy
  • 67. Dependent on how the OS does authentication: Local accounts ā€œ Virtualā€ accounts etc. SSH public keys are a common solution svnserve or svn+ssh
  • 68. Typically HTTP basic or digest authentication Use htpasswd to generate user/pass pairs Can still allow anonymous access Configure your server to require it WebDAV (http/https)
  • 69. Example HTTP Auth configuration
  • 71. Typically conf/authz in your repo, or ā€œaccess.confā€ accessible to web server INI-style file with [sections] [groups] section to define users and groups [/path] specifies path on repo [repo:/path] specifies path on specific repo (if more than one repo defined) ACL File
  • 72. ACLs: [user|group] = [r|rw] ā€œ *ā€ as group/user means any user Groups are prefixed with ā€œ@ā€ ACL File
  • 74. Svnserve, file access, or svn+ssh: conf/authz in your repository WebDAV: anywhere. Tell your vhost where to find it Must setup authorization prior to authentication ACL File: placement
  • 75. ACL File in WebDAV: vhost setup
  • 76. Hooks
  • 77. Allow extending SVN's capabilities via userland scripts ā€œ Hookā€ into specific processes: pre/post-commit, start-commit pre/post-revprop-change pre/post-lock pre/post-unlock What are hooks?
  • 78. Running a linter REPOS = "$1" TXN = "$2" PHP = "/path/to/php" SVNLOOK = "/path/to/svnlook" AWK = "/path/to/awk" GREP = "/path/to/egrep" SED = "/path/to/sed" CHANGED = `$SVNLOOK changed -t "$TXN" "$REPOS" | \ $AWK '{print $2}' | \ $GREP \\.php$` for FILE in $CHANGED do MESSAGE = `$SVNLOOK cat -t "$TXN" "$REPOS" "$FILE" | $PHP -l` if [ $? - ne 0 ] then echo 1 >& 2 echo "***********************************" 1 >& 2 echo "PHP error in: $FILE:" 1 >& 2 echo `echo "$MESSAGE" | $SED "s| -| $FILE|g"` 1 >& 2 echo "***********************************" 1 >& 2 exit 1 fi done
  • 79. *********************************** PHP error in: test.php echo $foobar *********************************** Sample linter output
  • 80. Run post-commit – prevents blocking issues Send email notification when tests fail Two approaches: Run entire suite Grep committed files for classes, and test just those classes Typically best to do this from a Continuous Integration server, and not via subversion hooks Running unit tests
  • 81. Email, Nabaztag, TwitterSVN Email notifications post-commit SVN::Notify: http://search.cpan.org/~dwheeler/SVN-Notify-2.79/lib/SVN/Notify.pm Can selectively determine which people/lists get notifications based on commit path Plain text and/or HTML emails Sending notifications
  • 84. Adding svn2feed.py to your post-commit hook: path / to / python path / to / hooks / svn2feed.py \ -- svn - path / usr / bin / \ -- max - items = 100 \ -- format = atom \ -- revision "$REV" – item - url \ "http://localhost/svn/" \ -- feed - url = "http://localhost/rss/svn.rss" \ -- feed - file "path/to/rss/svn.rss" \ "$REPOS" &
  • 85. Trigger docbook build process, or PhpDocumentor Run post-commit, so as not to block Typically best done from a CI server, and not subversion hooks Generating documentation
  • 86. PHP_CodeSniffer includes a script, bin/scripts/phpcs-svn-pre-commit Edit the script to provide the path to svnlook: define('PHP_CODESNIFFER_SVNLOOK', '/usr/bin/svnlook'); Edit the pre-commit hook script to invoke the script: /path/to/bin/scripts/phpcs-svn-pre-commit "$REPOS" -t "$TXN" >&2 || exit 1 Running PHP_CodeSniffer
  • 87. Transmitting file data .svn: Commit failed (details follow): svn: 'pre-commit' hook failed with error output: FILE: temp.php --------------------------------------------------------------- FOUND 1 ERROR(S) AND 0 WARNING(S) AFFECTING 1 LINE(S) --------------------------------------------------------------- 2 | ERROR | Missing file doc comment -------------------------------------------------------------- PHP_CodeSniffer hook output
  • 90. What else needs to happen at deploy time? Preserve uploads Set permissions Database patches Deployment Considerations
  • 91. Checkout retains link to repo Meta data present on server Inconsistent state during update Export is clean copy, no dependencies Other ways to keep track of version Checkout or Export
  • 92. Tag and export from svn – include some tag info Use symlinks to enable seamless switching Wrap in a script Have a rollback plan/script Consider database strategies Best Practices