test

Page 1

10/02/2012

Bazaar • What it does and why What it does and why Genesys Genesys chose it

Version Control Version Control and Bazaar Howard Cox, Genesys Howard Cox, Genesys Graduate Modified by Kirill Modified by Kirill

• Guide to: – Branching – Commits – Merging – Revision rollbacks

Genesys Solutions 2011‐ Solutions 2011‐2012

What is Bazaar? • Distributed version control system – This allows changes to be committed locally without the need to contact a central server without the need to contact a central server.

• Reliable, well supported, extensible

Distributed?

• Can be used in almost the same way as SVN but can be a lot more flexible. • Most actions Most actions do not require communication with the server, do not require communication with the server, unlike SVN. unlike SVN. • Every Every working copy working copy is local (on your computer) but it is is local (on your computer) but it is version controlled with its own revision history and version controlled with its own revision history and logs. logs. – It is as if you have your own “repository” but able to grab new revisions from other members of your team. – You You can commit, branch, revert and merge locally without can commit, branch, revert and merge locally without needing to access the to access the server server

• Every team has its own shared copy into which all changes are added (“pushed” in Bazaar terms). It is located at – /share/student/hutXX /share/student/hutXX where XX is your team number. (access via (access via sftp sftp using Putty ssh using Putty ssh client from a PC) – \\stustore.dcs.shef.ac.uk\ stustore.dcs.shef.ac.uk\student\ student\hutXX

Core concepts

Core concepts

• Terminology

• “bzr bzr” is the working name for “bazaar”. ” is the working name for “bazaar”. • Working Working Tree: A directory (folder) containing Tree: A directory (folder) containing bzr version‐ version‐controlled files • Revision Revision: A snapshot of the files after a i i : A snapshot of the files after a h f h fil f commit is made (the version number) • Branch Branch: An ordered series of revisions : An ordered series of revisions • Repository Repository: A collection of branches and : A collection of branches and revisions.

• Trunk and branching • Committing • Pushing, Pulling and Updating • Merging

1


10/02/2012

Core concepts

Core concepts

Trunk: The “master” branch

• Adding files bzr add

• Trunk is the initial working copy of a project, all all other branches come from trunk other branches come from trunk • This is where the “working” code will finally be merged once features are completed • In an ideal In an ideal‐‐world, there will be a testing branch where merged code will be tried before adding to trunk

Core concepts • Moving Files bzr mv [file] [new-name]

• Removing files: rm file-name

• Ignoring files bzr ignore “logs/*”

• Is the same as adding “logs/*” to .bzrignore

Core concepts Committing:

• Detect renamed files: mv old-name new-file bzr mv -auto

• If you did not tell Bazaar that you moved a file, it will try to figure it out (and usually do well). This process is called “auto”. Where it fails, do this:

• Commits log changes in the current working copy • Finer granularity is better • On the whole, only commit working code • Commit messages should be descriptive

bzr mv –after [old] [new]

Core concepts

Branches

Branches: • Every new feature will have its own branch for d l i i developing in • Branching creates a new working copy of an existing repository, so that code can be added • Branches can be merged to combine their features

Trunk

Branch: Testing

Branch: Feature 1

Branch: Feature 2

Branch: Feature 3

Branch: Minor Feature

2


10/02/2012

Branches • Seriously on EVERY feature??? – Not each time you add a new form or view – But for each core MVC feature B f But for each core MVC feature eg h MVC f eg:: • Users • Meetings • Visitors

Making a Branch bzr branch YOURREPOSITORY/trunk branch-name

• This creates a new branch locally • YOURREPOSITORY is something like sftp://share/student/hutXX f // h / d /h XX • Note: If you have already checked out trunk locally then: bzr branch trunk branch-name

• Will branch from the local copy of trunk

Committing

Pushing

• Commits make a snap‐ Commits make a snap‐shot of the current working tree

• Commits you make need to be pushed Commits you make need to be pushed to the server’s copy of the repository bzr push YOURREPOSITORY/branchX

• When / How often to commit? h / f i? – The same granularity as a scenario from cucumber – A bug fix

• After the first push, bzr After the first push, bzr will remember the branch and you only need to bzr push • You can You can push to other branches, we will cover that later in merging

Pushing

Pulling

• If you push and the directories you push to do not exist, then not exist, then bzr bzr will say:

• Commits made by others need to be pulled from the Genesys the Genesys repository bzr pull YOURREPOSITORY/branchX

bzr: : ERROR: Parent directory of “bzr YOURREPOSITORY/branches/ /branches/newbran newbran ch does not exist.”

• It is easier to pull changes and check for conflicts before you commit

• This can be fixed by adding – This can be fixed by adding –create create‐‐prefixes to the end of the bzr the end of the bzr command you ran

• Rather than commit a revision that may conflict with someone else’s work

3


10/02/2012

Update

Checkout

• bzr update updates a working tree to have the latest code committed to its branch

bzr checkout YOURREPOSITORY/branch-name

• This can cause conflicts just like pulling

• Creates a local working tree copy of a branch • This copy is also automatically bound to the branch it was checked out from • So push and pull operations automatically go to the repository

Core concepts

Binding a Branch

• Because BZR is distributed, you Because BZR is distributed, you can can commit locally without needing to push to server

• When you create a new branch:

• It is equivalent to running: i i l i bzr merge YOURREPOSITORY/branch

HOWEVER We want We want ALL your work We want ALL your work to be backed up on their server So…

Conflicts • Sometimes there will be conflicts • Two people change a file in different ways and commit to the repository • Bzr can handle some conflicts smartly on its h dl fli l i own, but sometimes it does not know what to do • When you pull changes from the repository, bzr will report back what has been changed

bzr branch YOURREPOSITORY

• You can force bzr You can force bzr to automatically pull and then push when you commit by: h h h i b bzr bind :push

• This keeps the server up to date, ensuring no work is lost

$ bzr pull $ bzr Using saved parent location: project/branch +N features/feature_files +N features/ feature_files/meeting/ /meeting/ … M app/controllers/guests_controller.rb M app/controllers/ guests_controller.rb … ‐D app/views/ D app/views/user_logs / i /user_logs/_ l /_form.html.haml / fform.html.haml h lh l … Text conflict in app/models/user_log.rb Text conflict in app/models/ user_log.rb …

New File Added

File Modified

File Deleted

Conflict in File

5 conflicts encountered. Now on revision 55.

4


10/02/2012

Conflicts • To check for outstanding conflicts run: bzr conflicts

• Bzr creates three versions of conflicting files: – THIS: The version you had before – OTHER: The version you are merging – BASE: An older version for reference

<<<<<<< TREE

Shows the START of a conflict block

The version you had before ======

Marks the divide between versions

Version being pulled from the repository >>>>>> MERGE‐‐SOURCE >>>>>> MERGE

Marks the END of a conflict block

Conflicts

Avoiding conflicts

• You need to choose which version to keep or merge the two yourself if they both added lines • Then Then remove the start and end tags and save remove the start and end tags and save the file • Then run

• See a summary of the changes that would occur

bzr resolve <file-name>

bzr merge g --preview p

• See a summary of the changes in a GUI bzr qdiff

which will automatically resolve the conflict

Merging

Merging

• Merge changes made in the parent‐ Merge changes made in the parent‐branch into your branch • Running

• You can update another branch (eg You can update another branch (eg: : trunk) with your changes safely by: – Merging that branch into yours:

bzr merge

On a branch will pull changes from the branch it was branched from (eg branch it was branched from (eg: trunk) : trunk) • You can then check these changes have not broken anything and commit them to your branch

bzr merge YOURREPOSITORY/trunk

– Resolve conflicts, commit fixes, and then push your working code to trunk bzr push YOURREPOSITORY/trunk

5


10/02/2012

View changes

View changes cont.

• You can view changes to the entire repository, or for a single file

• See the log for a repository, branch, file, or directory in a GUI window

bzr log <file-name>

• This will bring up a list of revisions and their commit messages bzr log –r 3

bzr qlog

• Show the author of each line in a file bzr qblame <file-name>

• This will show revision 3’s commit message

Reverting

Help

• Sometimes we need to undo committed changes • Bzr makes this very easy, for both an entire branch and for a single file branch and for a single file

• Bzr has excellent documentation at:

bzr revert <file-name>

• Will revert to the previous revision • Adding Adding – –r 0..9 will revert to a specific revision

http://doc.bazaar.canonical.com bzr help <command> • Discuss in your teams how to do things • If you are really stuck, ask your mentor

6


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.