Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Baseline Export now includes decomposed production items when production decomposition is enabled (#680)
- Take Ownership option in source control menu allows you to take ownership of an item edited by another user (#926)

## Fixed
- Fixed issue where Generated Files Read-only option didn't entirely work for files not in source control (#712)
Expand Down
12 changes: 11 additions & 1 deletion cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ XData Menu
<MenuItem Name="ExportForce" Save="101" />
<MenuItem Name="Import" />
<MenuItem Name="ImportForce" />
<MenuItem Name="TakeOwnership" />
</Menu>
<Menu Name="%SourceContext" Type="1">
<MenuItem Name="AddToSC" Save="100" />
<MenuItem Name="RemoveFromSC"/>
<MenuItem Name="Revert" Save="100" />
<MenuItem Name="Commit" Save="100" />
<MenuItem Name="TakeOwnership" />
</Menu>
</MenuBase>
}
Expand Down Expand Up @@ -150,6 +152,7 @@ Method LocalizeName(name As %String) As %String
"SwitchBranch":$$$Text("@SwitchBranch@Check out an existing branch"),
"Revert":$$$Text("@Revert@Discard changes to file"),
"Commit":$$$Text("@Commit@Commit changes to file"),
"TakeOwnership":$$$Text("@TakeOwnership@Take ownership of changes to file"),
"Sync":$$$Text("@Sync@Sync"),
"Push":$$$Text("@Push@Push to remote branch"),
"PushForce":$$$Text("@PushForce@Push to remote branch (Force)"),
Expand All @@ -172,7 +175,7 @@ Method OnSourceMenuItem(name As %String, ByRef Enabled As %String, ByRef Display
}
if ##class(SourceControl.Git.Utils).IsNamespaceInGit() {

if $listfind($listbuild("AddToSC", "RemoveFromSC", "Revert", "Commit", "ExportProduction"), name) {
if $listfind($listbuild("AddToSC", "RemoveFromSC", "Revert", "Commit", "ExportProduction", "TakeOwnership"), name) {
quit ..OnSourceMenuContextItem(InternalName,name,.Enabled,.DisplayName)
}

Expand Down Expand Up @@ -260,6 +263,13 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
if '(##class(SourceControl.Git.Change).IsUncommitted(##class(SourceControl.Git.Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
set Enabled = 0
}
} elseif menuItemName = "TakeOwnership" {
set Enabled = -1 // Hide by default
do ..GetStatus(.itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
// Show only if file is checked out by a different user
if isCheckedOut && (userCheckedOut '= $username) {
set Enabled = 1
}
} elseif menuItemName = "ExportProduction" {
set itemNameNoExt = $piece(itemName,".",1,*-1)
set Enabled = (##class(SourceControl.Git.Production).IsProductionClass(itemNameNoExt,"FullExternalName"))
Expand Down
27 changes: 27 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
set ec = ..AddToSourceControl(InternalName)
} elseif (menuItemName = "RemoveFromSC") {
set ec = ..RemoveFromSourceControl(InternalName)
} elseif (menuItemName = "TakeOwnership") {
set filename = ..FullExternalName(InternalName)
set sc = ##class(SourceControl.Git.Change).GetUncommitted(filename, .tAction, .tInternalName, .UncommittedUser, .tSource, .UncommittedLastUpdated)
$$$QuitOnError(sc)
if $get(UncommittedUser) = "" set UncomittedUser = "unknown user"
set Target = "File '"_InternalName_"' has uncommitted changes by '"_UncommittedUser_"'. Do you want to take ownership of these changes?"
set Action = 1 // Show Yes/No confirmation dialog
quit $$$OK
} elseif (menuItemName = "Status") {
do ..RunGitCommand("status", .errStream, .outStream)
write !, !, "Git Status: "
Expand Down Expand Up @@ -382,6 +390,11 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
do ..Push(,1)
set Reload = 1
}
} elseif (menuItemName = "TakeOwnership") {
if (Answer = 1) {
set status = ..TakeOwnership(InternalName)
set Reload = 1
}
} elseif (menuItemName = "GitWebUI") {
// Always force reload as many things could have possibly changed.
set Reload = 1
Expand Down Expand Up @@ -424,6 +437,20 @@ ClassMethod Commit(InternalName As %String, Message As %String = "example commit
quit $$$OK
}

ClassMethod TakeOwnership(InternalName As %String) As %Status
{
set sc = $$$OK
try {
&sql(update SourceControl_Git.Change set ChangedBy = $username where InternalName = :InternalName)
$$$ThrowSQLIfError(SQLCODE,.%msg)
write !, "Ownership of '"_InternalName_"' transferred to '"_$username_"'"
} catch ex {
set sc = ex.AsStatus()
do $System.OBJ.DisplayError(sc)
}
quit sc
}

/// <p>This function performs <code>git checkout -b [newBranchName]</code> from the current commit.</p>
/// <p>If the user is in "Basic Mode" AND there is a Default Merge Branch defined,
/// then this method first checks out and pulls that default merge branch before creating the new branch. This is
Expand Down
3 changes: 3 additions & 0 deletions docs/menu-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ This option imports the versions of the files that are found in the configured d

## Import All (Force)
This menu option behaves similarly to the regular import but forces the files to be imported regardless of whether the on-disk version is the same or older.

## Take Ownership of Changes to File
This option is enabled if the current item has uncommitted changes owned by a different user. Take Ownership will transfer ownership of those uncommitted changes to the current user, allowing the current user to make their own edits.
28 changes: 28 additions & 0 deletions test/UnitTest/SourceControl/Git/Utils/TakeOwnership.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Class UnitTest.SourceControl.Git.Utils.TakeOwnership Extends UnitTest.SourceControl.Git.AbstractTest
{

Method TestTakeOwnership()
{
set internalName = "Test.Package.TestClass.cls"

&sql(INSERT INTO SourceControl_Git.Change (InternalName, ChangedBy, ItemFile, Action, Committed)
VALUES (:internalName, 'OtherUser', 'cls/Test/Package/TestClass.cls', 'edit', 0))
$$$ThrowSQLIfError(SQLCODE,.%msg)

try {
// Call TakeOwnership and verify it succeeds
do $$$AssertStatusOK(##class(SourceControl.Git.Utils).TakeOwnership(internalName))

// Verify ChangedBy was updated
&sql(SELECT ChangedBy INTO :changedBy FROM SourceControl_Git.Change WHERE InternalName = :internalName)
$$$ThrowSQLIfError(SQLCODE,.%msg)
do $$$AssertEquals(changedBy, $username)
} catch ex {
do $$$AssertStatusOK(ex.AsStatus())
}

// Clean up
&sql(DELETE FROM SourceControl_Git.Change WHERE InternalName = :internalName)
}

}
Loading