Reputation: 329
I am trying to programattically edit a checked in file, then check it out and save the changes made while it was check in. And then check it back in with the saved changes: Edit -> CheckOut -> Save -> CheckIn
When attempting to save, I am running into a problem that the file does not recognize itself in the folder and thinks its attempting to overwrite another file.
void checkOut(string sourcefile)
{
ClearCase.CCElement element = m_CC.get_Element(sourcefile);
if (element != null)
{
ClearCase.CCVersion latestVersion = null;
FileInfo fi = new FileInfo(sourcefile);
latestVersion = element.get_Version();
if (latestVersion != null)
{
ClearCase.CCBranch branch = latestVersion.Branch;
ClearCase.CCCheckedOutFile file = latestVersion.CheckOut(ClearCase.CCReservedState.ccReserved, "", false, ClearCase.CCVersionToCheckOut.ccVersion_SpecificVersion, true, false);
string path = file.ExtendedPath;
}
}
}
void checkIn(string sourcefile)
{
ClearCase.CCElement element = m_CC.get_Element(sourcefile);
element.CheckedOutFile.CheckIn("", true, sourcefile, ClearCase.CCKeepState.ccRemove);
}
void excelEdit()
{
string fileName = Globals.ThisAddIn.Application.ActiveWorkbook.Name;
//EDIT EXCEL FILE from (fileName)
checkOut(fileName);
Globals.ThisAddIn.Application.ActiveWorkbook.SaveAs(fileName);
checkIn(fileName);
}
Upvotes: 4
Views: 1423
Reputation: 1323573
Note: you could do what you want with a snapshot view, where you can:
–use/hijack
Instructs checkout to use the hijacked file as the checked-out version.
If the file being checked out does not have a hijacked counterpart, this option is silently ignored.
That process can make sense when you want to test modification right away, without having to tell everyone that you are modifying said file: if the modification works, then you try to checkout, and then checkin.
But with dynamic views, that wouldn't be possible (or it would be much harder).
So, unless you have a very specific reason to try modifications before a checkout, the official process described by Steve is preferable.
Upvotes: 2
Reputation: 18218
I'm under the impression that ClearCase checks out files by replacing the current read-only copy with a fresh writable one. This would explain the behavior you are seeing.
I would suggest that you copy your file to a temporary location, modify the copy, check out the original file, copy back your modified temporary one and check it in.
Upvotes: 2
Reputation: 13091
That's not the process you would use if you were doing it manually and not the way I'd recommend to do it programmatically.
You should CHECK OUT the file first (which will make it writeable on disk), EDIT it, SAVE it, then CHECK it back IN (which will make it read-only on disk).
You may think that in Visual Studio you start editing before you check out, but in reality, Visual Studio will check the file out when you start to edit.
Upvotes: 3
Reputation: 25513
If ClearCase is anything like TFS, you probably have your file set to being ReadOnly until you do your checkout...
So your process actually has to be Set File to not Read Only -> Edit -> Check Out -> Save -> Check In
Upvotes: 0