66
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

ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 1: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 2: ALM Revolutions - Non si vive di solo check-out e check-in

Technical details

It is not Visual Source Safe

Based on SQL Server

Accessed with Web Services

Page 3: ALM Revolutions - Non si vive di solo check-out e check-in

Benefit of TFS VCS

Advanced and scalable VCS

Check-in and WIT relation

Integrated build and analysis

server

Page 4: ALM Revolutions - Non si vive di solo check-out e check-in

WorkspacesHow TFS manages mapping between server and local copies

Microsoft Confidential4

Page 5: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 6: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 7: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 8: ALM Revolutions - Non si vive di solo check-out e check-in

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.)

Page 9: ALM Revolutions - Non si vive di solo check-out e check-in

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/)

Page 10: ALM Revolutions - Non si vive di solo check-out e check-in

Basic operationsCheck-in, Check-out, Lock…

Microsoft Confidential10

Page 11: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 12: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 13: ALM Revolutions - Non si vive di solo check-out e check-in

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)

Page 14: ALM Revolutions - Non si vive di solo check-out e check-in

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.

Page 15: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 16: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 17: ALM Revolutions - Non si vive di solo check-out e 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

Page 18: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 19: ALM Revolutions - Non si vive di solo check-out e 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

Page 20: ALM Revolutions - Non si vive di solo check-out e check-in

LabelIdentify a group of files each one at a certain changeset

Microsoft Confidential20

Page 21: ALM Revolutions - Non si vive di solo check-out e check-in

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)

Page 22: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 23: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 24: ALM Revolutions - Non si vive di solo check-out e check-in

BranchesBecause a complex project needs more than one line of code

Page 25: ALM Revolutions - Non si vive di solo check-out e check-in

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.

Page 26: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 27: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 28: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 29: ALM Revolutions - Non si vive di solo check-out e check-in

Branch strategies

− Branching are used to solve various problems related to source management

− Es. Release syndrome

Page 30: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 31: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 32: ALM Revolutions - Non si vive di solo check-out e check-in

Tfs 2010 branch++

− TFS 2010 introduces a new Branch Visualizer that gives us the idea of how branches are organized

Page 33: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 34: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 35: ALM Revolutions - Non si vive di solo check-out e check-in

Tracking changes

− Suppose latest checkin in release is 62

Page 36: ALM Revolutions - Non si vive di solo check-out e check-in

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)

Page 37: ALM Revolutions - Non si vive di solo check-out e check-in

Tips A bunch of suggestions to obtain maximum from your TFS

Microsoft Confidential37

Page 38: ALM Revolutions - Non si vive di solo check-out e check-in

Security− With TFS you can manage permission

for each folder or file − This is especially important for

Branches

Page 39: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 40: ALM Revolutions - Non si vive di solo check-out e check-in

Compare for changes− You can visualize all the differences

between the workspace and the server version

Page 41: ALM Revolutions - Non si vive di solo check-out e check-in

Compare for changesThis is what you got in response

Page 42: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 43: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 44: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 45: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 46: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 47: ALM Revolutions - Non si vive di solo check-out e check-in

Rollback (in the UI)− Even simpler from the History Window− A right-click on a changeset permits to

rollback the entire changeset

Page 48: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 49: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 50: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 51: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 52: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 53: ALM Revolutions - Non si vive di solo check-out e check-in

Notes and Comments− Notes are different from comments because

they are really more specific (Code reviewer, Security reviewer, etc)

− They can be enforced

Page 54: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 55: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 56: ALM Revolutions - Non si vive di solo check-out e check-in

Again, other tips/infoYou think this is enough, TFS has much more

Page 57: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 58: ALM Revolutions - Non si vive di solo check-out e check-in

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/

Page 59: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 60: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 61: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 62: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 63: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 64: ALM Revolutions - Non si vive di solo check-out e check-in

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

Page 65: ALM Revolutions - Non si vive di solo check-out e check-in

Microsoft Confidential80

QUESTIONS

Page 66: ALM Revolutions - Non si vive di solo check-out e check-in

© 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