Skip to content

Commit dd9315b

Browse files
committed
Enhance RemoveGitRepository cmdlet to support irreversible deletion with -Hard switch
1 parent 43fd654 commit dd9315b

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

CSharp/TfsCmdlets/Cmdlets/Git/RemoveGitRepository.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ partial class RemoveGitRepository
1919
[Alias("Name")]
2020
public object Repository { get; set; }
2121

22+
/// <summary>
23+
/// Permanently deletes the repository instead of moving it to the recycle bin.
24+
/// When omitted, the repository is moved to a recycle bin and can be recovered.
25+
/// When specified, the deletion is irreversible.
26+
/// </summary>
27+
[Parameter]
28+
public SwitchParameter Hard { get; set; }
29+
2230
/// <summary>
2331
/// HELP_PARAM_FORCE_REMOVE
2432
/// </summary>
@@ -37,7 +45,16 @@ protected override IEnumerable Run()
3745

3846
if (!(repo.DefaultBranch == null || Force) && !PowerShell.ShouldContinue($"Are you sure you want to delete Git repository '{repo.Name}'?")) continue;
3947

48+
if (Has_Hard && !(Force || PowerShell.ShouldContinue(
49+
"You are using the -Hard switch. The repository deletion is IRREVERSIBLE " +
50+
$"and may cause DATA LOSS. Are you sure you want to permanently delete Git repository '{repo.Name}'?"))) continue;
51+
4052
Client.DeleteRepositoryAsync(repo.Id).Wait();
53+
54+
if (Has_Hard)
55+
{
56+
Client.DeleteRepositoryFromRecycleBinAsync(repo.ProjectReference.Id.ToString(), repo.Id).Wait();
57+
}
4158
}
4259

4360
return null;

0 commit comments

Comments
 (0)