Upload
domusdotnet
View
388
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Slides della sessione "Non si vive di solo check-out e check-in" tenuta da Gian Maria Ricci all'evento ALM Revolutions di DomusDotNet
Citation preview
Using only check-in and check-out will make your TFS Sad
Because there is a whole world beyond Check-in and Check-out
03/11/2011 - DomusDotNet
Ricci Gian Maria, @alkampfer,[email protected], http://www.codewrecks.com, http://blogs.ugidotnet.org/rgm, https://www.facebook.com/Alkampfer.ALM
Technical details
It is not Visual Source Safe
Based on SQL Server
Accessed with Web Services
Benefit of TFS VCS
Advanced and scalable VCS
Check-in and WIT relation
Integrated build and analysis
server
WorkspacesHow TFS manages mapping between server and local copies
Microsoft Confidential4
Workspace− TFS VCS is a centralized source
control system− Users create one or more local copy
synchronized with the server− Those copies are called workspaces
Identity of a workspace
− Each workspace is identified by: user, a computer and a folder (or series of folder)
− For each workspace a list of server folders are mapped on local folders
− Folders can be “cloaked” from a workspace, this means that those folder will not be downloaded from the server
− Avoid messing the workspace doing direct manipulation of files
How a Workspace works
− The server keeps track of the status of each workspace
− When you issue a command to the server, he checks this status to understand what to do
Workspace1Machine: ALK1User:alkampferFolders:……
Workspace2Machine: ALKLaptopUser:alkampferFolders:……
Workspace3Machine: JIMMY1User: JimmyFolders:……
Workspace1Status: xxxxx
Workspace2Status: xxxxx
Workspace3Status: xxxxx
Workspace types
− A workspace can be Private, Public (limited) or Public
− Private: the workspace can be used only by associated user
− Public (limited): every user can use the workspace, but only the owner can do check-in
− Public: every user can do everything with that workspace (useful for shared computer.)
New workspace for dev11− Next version of TFS (dev11) will
introduce a new workspace− This new type of workspace is called
“local”, and it used the Subversion style of mapping, all information are stored in the client. (http://www.codewrecks.com/blog/index.php/2011/09/29/local-workspaces/)
Basic operationsCheck-in, Check-out, Lock…
Microsoft Confidential10
Get data from server− To sync the workspace the most
common command is Get Latest− Get Latest queries the server and
perform this operation− Download file from the server if they are
changed− Delete local file if they were deleted from
server− Download new files that were added to
server.− Get Specific Version permits to
synchronize the workspace with a specific version
Basic operation Add, Delete, Modify− If you add/delete a folder or file from
your workspace this modification is kept local
− You can operate Delete directly on server, this does not creates a pending-delete but immediately deletes the file from the server
− Each deleted file is not really deleted but marked as deleted
− You never lose the history of the file
Check Out− Check-Out operation is performed when
you want to modify a file− This operation does not issue lock to the
file− It is possible to lock if needed, but the
ability to work concurrently on a file is crucial to productivity even for medium size team
− Check Out does not perform Get Latest (it is an option that you can use) so always remember to issue a Get Latest if this is what you want.
− NOTE: Checkout for MSSCCI provider always to a Get Latest (to preserve the same semantic of VSS)
If you need to lock − Lock policy can be created for the
entire project or for single file− There are three main lock type
− Exclusive Check-Out: The first person that Check-Out the file, prevent other to check out or modify the file
− Exclusive Check-In: Others can do check-out and modify file, but no one can do a check-in until the first user that did check-out (those who put the lock) has done the check-in
− No Lock: Everyone can check-out and check-in with no problem.
Microsoft Confidential15
Why locking
− Certain file type (Ex. *.edmx) cannot be merge by humans
− All binary files could not be merged− Files too long, you need to do heavy
modification to a file and you want to avoid a painful merge
Pending changes− Every artifact of the workspace that is
modified locally is called pending so you can have: − Pending Add− Pending Delete− Pending Modification
− Those modifications can be sent to the server with a check-in
Check-in− Check-In operation send modifications
of one or more Pending files to the server
− The operation is guaranteed to be atomic
− Each successful check-in receive a unique Integer number that identify it, this is called ChangesetId
Check-In additional data
− A Check-In does not contains only a set of Pending Changes
− They should include a Text Comment− They can include one or more Notes− They can include relation to one
or more WI (Associated/Closed)− These information are related to the
ChangesetId, some of them (like description) can be modified after the Check-In
What is really a Changeset Logical container of data related to check-in
File and branch information Links to work items Check-in notes Comment Policy compliance Metadata (date, time, user) Unit of atomic check-in
Uniquely identified Numeric identifier Incremental
Represents a point in time of source repository
LabelIdentify a group of files each one at a certain changeset
Microsoft Confidential20
Label− Sometimes you need to identify a
“snapshot” of solution files− A typical need is: identifying some special
occurrence such as “demo on lunch room”− A label can be modified, it is not immutable
in time− This means that a label is not really a
“Snapshot” of a point of time, but more generically a “group of file, each one taken at a certain time”
− Label are useful to mark operations that occurs automatically (ex. builds)
Label− They are not part of the history of a
file− You can use Third party tool (tfs
sidekick) to have better visualization− You can search for a label− You can use label in
− Get Specific Version− Branch (branch from label)− Merge
− A label can span multiple projects
More on labels− Label is simply a collection of files− Labels are not versioned, you do not
have history of a label− It is not a “point in time” view of the
files, because files can be changed− Could contain sparse files from
various folders− Can contain file of more than one
Team Project
BranchesBecause a complex project needs more than one line of code
Shelving− Shelvesets can be considered as
“temporary check-in”− A shelveset can be visible only to the
user that did it or to everyone− You can use when
− You want to work on some ideas, did modification, shelve it to review later
− We want to save our work but it is not ready to check-in
− You want to save your changes to have someone other to do a review of it.
Reason for branch− Suppose you need to do a heavy
modification that tooks several days and during that time the code will not be stable
Reason for branch− Solution 1: Avoid Check-in
− If you loose your machine (stolen, broken disk) modification are done
− You work outside VCS (no undo pending changes, history, etc)
− It could not be used for more than One Developer
− Solution 2: Create a copy of the folder in Source Control− It occupies a lot of space on the server − It is difficult to keep both folders
synchronized
Real solution - Branches
− A branch is a “Special Copy” of a folder
− This copy does not consume space, internally tfs records only that a certain folder was “branched” to another one
− When files in branch is changed, tfs record differences and use spaces
− Branches are marked with a different icon
Branch strategies
− Branching are used to solve various problems related to source management
− Es. Release syndrome
Branch strategies
− Use a different line for developing and releases
− Code is written to Development, then moved to main and stabilized, finally moved to Release
Merge− The act of moving changes between
branches is called Merge− Moving changes from source to
branch is called Forward Integration− Moving changes from Branch to
Source is called reverse Integration
BRANCH RI
FI
SOURCE
Tfs 2010 branch++
− TFS 2010 introduces a new Branch Visualizer that gives us the idea of how branches are organized
Tracking changes
− One of the risk in using branches is loosing track of what was merged and why
− Suppose you have a changeset 43 on the iteration1 branch and you want to know its merge history
Tracking changes
− You can also visualize Timeline− We can see that Changeset43 was
obtained by the merge of 41 and 42 from main to iteration 1
− And the same set of changeset (41-42) were also moved to iteration2 and production
Tracking changes
− Suppose latest checkin in release is 62
Merge and conflicts
− Install a third party tool to handle merge of files
− You can use Perforce (http://www.perforce.com/product/components/perforce_visual_merge_and_diff_tools)
− After you install a third party tool you can simply configure Visual Studio to use that external tool to merge files. (http://www.richard-banks.org/2009/09/using-p4merge-with-visual-studio-2008.html)
Tips A bunch of suggestions to obtain maximum from your TFS
Microsoft Confidential37
Security− With TFS you can manage permission
for each folder or file − This is especially important for
Branches
Avoid “messing the workspace”− The easiest way to mess the workspace is
doing manual move/delete/edit outside the control of TFS
− You can always recover with a tfpt.exe scorch command
Compare for changes− You can visualize all the differences
between the workspace and the server version
Compare for changesThis is what you got in response
Wanna see deleted file − Deleted files are never really deleted, they
are only marked as deleted− After all you can always get a specific
version requesting for a changeset where the file were still not deleted.
− It is an option of Visual Studio to visualize deleted files
Annotate or Blaming − This is not a tool to point your finger
to your colleague telling “HA HA, you wrote this buggy piece of code ”
− You can visualize for each file, line by line:− Changeset: last changeset where that
line was modified− Date: When that line is modified− Author: Who modified it (that is the
reason why in subversion is called blame)− You can navigate trough the
changeset
Microsoft Confidential44
Prevent file to be merged− http://blogs.ugidotnet.org/rgm/archive/2011/05/02/sapevatelo-tfs-he
llip-disabilitare-il-merge-per-tipi-specifici-di.aspx
History, recursive or not?− There is a big difference if you use the
“history” command from the Solution Explorer or the Source Control Explorer
− From solution explorer the history command is not recursive, it does not list what happened to the subfolders
− To have a recursive history command you should issue from the Source Control Explorer
Rollback (in the UI)− Latest TFS Power Tools introduced the
Rollback function in the UI− Previously you need to use the command
line tool to rollback a changeset
Rollback (in the UI)− Even simpler from the History Window− A right-click on a changeset permits to
rollback the entire changeset
Various way to find content− Changeset number: each changeset
number identify a point in time status of the entire source tree (all projects)
− Labels are set of files at different point in time.
− Workspace is the version that is actually in a workspace
− Tip is the Latest revision (the highest changeset)
− You can also identify with a date
Command line utility− Tf.exe or TFTP.exe or all others
command line utilities have a specific syntax to select specific source control files in merge, diff, or history commands− Specific changeset (es 123): C123~C123− Label: Labelname Es: LV1.1~LV1.2− Workspace:W es the difference from the
workspace version and a changeset W~C123
− Date: D2008-01-21T16:00
TFS is more than a standard CVS− Relation with WIT.
− This is optional but can be enforced by policy− This operation is key for traceability because it
permits to relate code modification with requisites like: bug, feature, risk etc.
− It is possible to mark the WIT as resolved
Check-in policies− You can setup rules for check-in− Rules prevent source code quality to fall
under a certain level.− All unit test should pass− Code coverage > %− No error in Code Analysis− Relate one or more WIT
Policy out of the box − TFS has out of the box
− Relate at least one WIT− Execute Code Analysis − Testing policies
− Others policies are in the power tools− Rules on path where you check-in− Request a comment− Request that associated WIT satisfy one
query− Custom Path (permits to apply a policy
only if the check-in is related to a certain path)
− You can write your own
Notes and Comments− Notes are different from comments because
they are really more specific (Code reviewer, Security reviewer, etc)
− They can be enforced
Notification− Tfs is able to send notification when
certain events occur− Check-in− Build Quality− Build successful− And many other.
− You can use the bissubscribe.exe command line tool to subscribe to EACH TFS EVENT implementing a web service
−Power Tools contains extension for alerting system to easy the operation
Email alerting on change− Just right-click on a folder and choose
“alert on change”− You need to specify a valid provider in
Tfs Administration Console− Useful for releases branches
Again, other tips/infoYou think this is enough, TFS has much more
How files are stored in DB− Storage is compressed to save space
(source code file are text file with high compression ratio)
− Delta storage (only differencies are stored)− The latest version (tip) is in clear form, for
the other delta are applied.− All files greater than 16 mb are stored
without compression and delta to avoid performance loss
− You can store file larger than 4 GB even if SQL server does not support columns with size greater than 4 GB…….. but why you should want to save such a big blog to source control
Manage different configurations− Typical problem: each developer use a
personalized app.config/web.config− Usually you have configuration files
with common settings, and per developer settings
− With branch and workspace good knowledge you can manage everything
− Full description here http://www.codewrecks.com/blog/index.php/2010/01/15/managing-different-config-file-with-tfs-branching/
Find by status− One typical request is looking for files
that are checked out.− Power tools introduces a Find By
status tool− Just right click on the folder you want
to check recursively
Workspace Template− Just right-click on Team Member –
Team Settings− You can create a new workspace or
import one workspace as default “template” for the team project
− Useful for big project where there is the need to create complex workspaces
Find by status− One typical request is looking for files
that are checked out.− Power tools introduces a Find By
status tool− Just right click on the folder you want
to check recursively− Team members can create a
workspace based on that template just specifying the local folder
Avoid ghost check-in− If you type a character in a file the file
is checked-out− This lead to check-in of file that are
different from spaces or CRLF− Evaluate changing the default
behavior
Unshelve with merge− If you unshelve a shelveset that
contains file modified after the shelveset operation they will be overwritten
− To do an unshelve with merge you should use power tools tfpt.ext unshelve command− 1) Unhelve as usual− 2) go to a command prompt and issue a
tfpt.exe unshelve− 3) if there are conflicts you will be
prompted for resolution
My get latest is not working− Sometimes if modification does not
pass through Team Explorer but are done directly on file, Team Explorer could erratically suppose that you already have the same version
− You can force a Get Specific Version of the trunk
Microsoft Confidential80
QUESTIONS
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after
the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Microsoft Confidential81