CVS silently brings back deleted code during update - merge

Our team has noticed that CVS brings back deleted code if you have changes in your working file within the block of code that has been deleted. CVS does this silently without presenting the merge conflict markings.
Does anyone have a work around for this?
Is there a clever way to detect that this is about to happen?

From your description, it's unclear what is happening.
If one developer deletes a chunk of code from file X, and another developer makes changes in the middle of that deleted code, and that's all that happens, then I'd be very surprised if CVS was silent -- not that it couldn't happen, but I've never seen it happen in 10+ years of using CVS.
It is possible, because of the way that CVS tracks edits, that major changes could make it think that developer #2 added the code into a completely different location. Particularly if developer #1 makes several commits before developer #2 does an update.
The best work-around is probably to check the status of files before taking an update. You can do this with the "-n" switch:
cvs -nq update -P 2> /dev/null
If you see that a file you've changed is going to be updated, then you can take a closer look at it.

Related

Unexpected overwriting CVS/SVN repository files in Mac Eclipse

I worked with Windows Eclipse CVS and CVS did not allow me to overwrite the latest revisions – I needed to update first. At the same time one developer working on Mac constantly overwrote my files. We looked at this problem and found that his CVS Eclipse plugin allows overwriting the latest revisions without any warning.
Now I work with Mac myself using SVN Eclipse plugin and I accidentally overwrote the latest revisions from my co developer. How to prevent this overwriting? If this overwriting happens what is the graceful way of reverting to the previous revisions and committing them back to the repository?
Wait? Something is not right here...
CVS and Subversion will never let you overwrite someone else's changes. The whole purpose of version control is to allow multiple people to work on the same files at the same time.
There are two ways version control systems do this:
Checkout and Lock: The oldest systems used a checkout and lock system. That is, you checkout the code for changes, and no one else was allowed to checkout and make changes until you checked in your changes. The problem is that someone could checkout files for a week and forget to check them back in, or go on vacation. Then, everyone else is stuck unable to work.
Checkout, and first person who commits wins: In this system, two people can checkout the same file and do their work. However, the first person who finishes their changes and commits wins. The other person must do an update which will incorporate the first person's changes into their working copy before they can commit their changes. This is what Subversion and CVS do.
So, how in the world are you losing your changes? Or, how are you overwriting the other person's changes?
Sometimes this happens if you are sharing your checked out working copy with other people. This is wrong and should never be done. Instead, each user should have their own separate independent copy of the project (Heck, you can even have multiple version if you want). When your partner checks in their changes, it shouldn't affect your files.
What will happen is that when you try to commit your changes, you will be told that your working copy is out of date. You'll have to update your working copy and that will incorporate your partner's changes into your working copy. You should then verify that everything is okay, and then commit your working copy which will now include both your and your partner changes.
Does this answer your question? Are you sharing all sharing the same directory, or do you have your own working copy? Is there something else going on?

(Mercurial/tortoisehg) Lost commits - how to troubleshoot

A colleague of mine was working on a VS project this morning, which he claims was in a folder clone of our central repository. He built a release version of the application which is still there with the correct date/time stamp on it.
He then said he committed several times during this time, but at some point, he tried pulling down changes from the central repository and merge them in with his changes. He can't really remember what steps he took, but the end result is that all the changes he did to the source were lost. now, i'm trying to help him to see if we can recover any of those changes.
He told me after he committed his changes (several commits), He went into the tortoisehg workbench, pulled, and saw that there were many changes in the central repository. He decided to either "Merge with local" or "Update" to the tip pulled down - he can't remember which. I showed him the two dialogs, and asked him if he discarded changes, shelved or anything else. He couldn't remember, really, but he did remember he had to back out because tortoisehg didn't like what he was doing. Eventually, he did seem to be able to update to the repository tip.
I'm thinking that unless he physically deleted the folder in which he was working, and then got the latest, those commits he claimed to have done would have been recorded somewhere? What are common errors people do when pulling the remote repo? Are there any log files or history i can check to see if i can salvage or at least tell where he was working on this stuff?
any hints to troubleshoot this would be greatly appreciated.
First of all backup the tree somewhere including .hg and everything under it. Then...
hg heads
...to see if he's just lost track of his commits. If it's there, it's just a case of updating back to it and doing a proper merge.
hg log -u 'His Username'
...to see if the commits are anywhere in the repo. If they're are there you can then work forward from them.
hg shelve --list
...to see if he's managed to shelve things somewhere
Take a look in .hg/strip-backups, to see if he's managed to strip his changes somehow. Anything else destructive should have left backups in .hg too.
That should be a good start. If none of those give any clues then others may be able to suggest some things.
I don’t know about TortoiseHG, but usually the first thing would be to check hg out.

ClearCase automatic merge deletes team members' code

We are using ClearCase using a single Dev stream for our team, without 'locking' (Unreserved check outs).
ClearCase client version: 7.1.1
ClearCase server version: 7.0.1.2
We have performed the same test, without using the "Graphic merge". This option worked as expected! Maybe this can shed some light on past defects on ClearCase or workarounds.
This means that 2 or more people can make edits to the same file at once, without having to wait for for the file to be checked in.
We have seen a few cases of weird behaviour and experimented a bit today to find the following scenario that takes place:
File.txt is checked out by 2 team members.
Each members makes a change in the file (in other regions of the file).
First developer checks in the code to ClearCase, no problems here.
Second developer checks in, gets a merge popup notification.
When selecting "graphic merge", ClearCase in this case informs that all merges were done automatically and no additional input is needed from the developer.
Looking a little further, the first check in was removed (deleted), keeping only the later check in changes.
Why is this happening? This is causing our team to lose code on several occasions already. Are we doing something unsafe/wrong ?
Edit: Illustrating the problem with images of the issue:
The file Manager.cs is at version 27.
Two developers are checking it out.
One made a change, checked in.
The other checks in, gets the merge notification.
This is what i see in the graphical merge:
Note that on the left is version 27, in the middle version 28 (the latest checked in version), and on the right is the result which is dropping version 28's code change !
Why is this happening automatically??
Image can also be seen here: Image
Note: if you are using ClearCase without 'locking', that means you are doing unreserved checkouts (and not reserved checkout).
If you select "graphic merge", you should see a Windows helping you to reconcile the merge, even if there is no conflict.
Such a merge should not delete any previous checkins: it might cancel the previous modifications, only if all the new changes are selected, but if you have the graphical merge window open, you can control how the merge is applied.
For your past problematic merges, you can easily from the version tree re-apply the merge from the previous version of dev1 to the LATEST version, in order to reapply those canceled changes.
Since my initial answer 4 days ago, 2 new information came about:
ClearCase client version: 7.1.1 ClearCase server version: 7.0.1.2.
That is never good to have a client with a version more recent than the server.
We have performed the same test, without using the "Graphic merge". This option worked as expected!
That would be consistent with some discrepancies already seen between the GUI for merging and the pure command line (as in this other scenario).
When the GUI fails, always try to fall back on the pure CLI (Command Line Interface).

Procedures before checking in to source control?

I am starting to get a reputation at work as the "guy who breaks the builds".
The problem is not that I am writing dodgy code, but when it comes to checking my fixes back into source control, it all goes wrong.
I am regularly doing stupid things like :
forgetting to add new files
accidentally checking in code for a half fixed bug along with another bug fix
forgetting to save the files in VS before checking them in
I need to develop some habits / tools to stop this.
What do you regularly do to ensure the code you check in is correct and is what needs to go in?
Edit
I forgot to mention that things can get pretty chaotic in this place. I quite often have two or three things that Im working on in the same code base at any one time. When I check in I will only really want to check in one of those things.
A few suggestions:
try work on one issue at a time. It's easy to make unrelated changes to the codebase that then end up being committed as one big chunk with a poor log message. Git is excels here since you can so easily move switch branches, and stash and cherry pick changes.
run the status command before a commit to see which files you've touched and if you've created new files that need to be added to version control.
run the diff command to see what you've actually changed. Often times you find that you've left in some debug logging that should be taken out or made some unnecessary change that is just cluttering up the diff. Try to make your diffs as small and clean as possible.
make sure your working copy builds with your changes in it
update before checking in and make sure that your working copy builds with other peoples changes in it
run what ever smoke test suite you might have to make sure that your changes work correctly
make small and frequent commits. It's a lot easier to figure out what has broken the build when the breaking commit is small.
Other things that the team can do is setup a continuous integration server like David M suggested so that the broken build is discovered as soon as possibly and automatically.
I usually always do a Get Latest before, then build. If build is good then I check in my code.
Here is what I have been doing. I have used ClearCase and CVS in the past for source control, and most recently I have been using Subversion and Visual Studio 2008 as my IDE.
Make my code changes and build on the local machine.
Make sure they do, in fact, fix the bug in question.
Run an SVN update on the local machine and repeat steps 1 and 2.
Run through the automated unit tests to verify that they pass.
If an automated smoke test is available, which automatically tests a lot of the system's capabilities, run it. Verify that the results are correct.
Then go to the build machine and run the build script.
If the project's configuration has changed, this could definitely break a build. Perform an SVN update on the build machine, whether the build script does that or not. Open the build machine's copy of the IDE, and do a complete rebuild. This will show you whether the build box has any problems that you have taken care of on your machine but not on the build box.
The suggestions to keep separate branches for each issue are also very good, if you can keep track of all of the issues you are working on.
First, use multiple working copies (a.k.a sandboxes) - one per issue. So, if you've been working on some complex feature for a while, and you need to deal with a quick bug fix on the same project, check out a new clean working copy and do the bug fix there. With independent working copies for each issue there is no confusion about which changes to commit from the working copy to the reposistory.
Second, before committing changes, always perform the following three steps:
Buld the software.
Run a smoke test (does it start and run without crashing).
Inspect the changes you're checking in by diffing your changes against the baseline.
These should be repeated after any merge operations (e.g. after an SVN update).
At my workplace, the safety net for this is peer review. That is, get someone else to build, run, and reproduce your solution on their machine, on their view.
I cannot recommend this enough. It has caught so many omissions, would-be problems, and other accidental pieces of junk to make it a valuable part of the process. Not to mention that the mere knowledge that you have to place your work in front of someone else before having it go on to the main branch means that you raise your own quality standards.
In the past I have used branching in Clear Case to help with this issue. The process I used is below. I've never used SorceDepot so I do not know how this can be adapted to work with it.
Create a branch for the bug fix
Code all changes on the branch
Code Review
Merge to stable branch in a different view (the different view is important)
BEFORE checking in: compile, test, and run
Check in code to stable branch
By creating the branch and then merging the changes to a different view (I use Merge Manager to do the merge) any files that were not included or checked in immediately cause issues. This way everything gets tested as it will be when checked in on the stable branch.
The best thing to avoid your problems, is to use hooks, that are provided in most SCMs (they are for sure in SVN and Mercurial, and I believe they must be in other advanced SCMs). Attach unit tests to the hook and make it run every time someone checks code in - exactly before it is checked in. This way you will achieve two things:
code in SCM repo will always pass the tests,
you won't make most simple mistakes, because they should be easily detectable, if you have decent test suite.
I like having Tortoise plugins for Windows Explorer. The file icons are all badged with committed, modified or not added icons making it very easy to see what status the files are in. I also enable the meta data for Modified so I can sort changed files in the list (Details) view, where they bubble to the top so I can see them.
I bet there is a Tortoise* plugin for your SCM, I saw one for Mercurial and SVN (and CVS, ugh). I really wish Mac OS X's Finder would accept plugins like Tortoise, its so much easier than having to pop open a dedicated app most of the time.
Get someone else to go through "every" change "before" you check in the code.

What is the difference between shelve and check in in TFS?

What is the concept of each?
When is it ok to shelve your changes instead of checking in?
Shelved means the changes are set aside for you to work on later.
Checked in means that the changes are made available to the rest of the team, will be in the build and will eventually ship.
Very different. Think of shelving as a tool for context switching when you're not done with a task. Checking in means you're done (at least a part of it).
Shelve your changes when you want to save the changes that you have made, but need to go back to the previous version to make other changes (perhaps, bug fixes) that you want to deploy without the updates you are currently working on. Since you're usually checking in pretty regularly, I find this to be a rare occurence -- like I just deployed to the QA box and an error was immediately found. I'll shelve that day's changes bringing me back to the QA deployed version, make the update, then unshelve my changes -- merging the two as necessary. Any longer than that and you'll probably be looking to check out a previous version and branch instead. I'd be happy to hear of other experiences where shelving has proved more useful, though.
Other users can download your shelvesets by searching for them, so it is a good way to pass code around for reviews. however you will get an error if you try to unshelve code files that you already have checked out, so you need a clean environment ready.
I often shelve my changes at the end of the day if I'm working on something big that I can't check in. That way, if my PC dies overnight, I've got a backup on the server.
Darcy gets it spot on. You can also think of shelving as a private branch that is not publicly visible for the most part. Shelvesets can also be deleted completely, not like deleting checked in code. If you delete a shelfset it is gone forever.
Everyone above has said so much true and I learned allot from it.
Just to add my experience, correct me if I am wrong. In a project, we have a configuration file mypc.json specific to each PC of the developer. We usually override it when running server locally. Other team members have the same file name with different configurations in it. No one wants their file to be pushed with the same name to the development branch. So I use shelve to save these type of changes. Whenever I need these configurations I can easily apply changes from shelve and my environment configurations are back in my project.