Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to override branch names #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 0 additions & 1 deletion src/AutoMerge.Tests/AutoMerge.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="JsonParserTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
20 changes: 0 additions & 20 deletions src/AutoMerge.Tests/JsonParserTests.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/AutoMerge/AutoMerge.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<HintPath>..\..\lib\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\Microsoft.Expression.Interactions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.OLE.Interop" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0" />
Expand Down Expand Up @@ -215,10 +216,8 @@
<Compile Include="Branches\Notification.cs" />
<Compile Include="Branches\TrackMergeInfo.cs" />
<Compile Include="CommentFormater.cs" />
<Compile Include="Configuration\BranchNameMatch.cs" />
<Compile Include="Configuration\CommentFormat.cs" />
<Compile Include="Configuration\ISettingProvider.cs" />
<Compile Include="Configuration\JsonParser.cs" />
<Compile Include="Configuration\FileSettingProvider.cs" />
<Compile Include="Configuration\Settings.cs" />
<Compile Include="Controls\SplitButton.xaml.cs">
<DependentUpon>SplitButton.xaml</DependentUpon>
Expand Down
4 changes: 2 additions & 2 deletions src/AutoMerge/AutoMergePackage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;
Expand Down Expand Up @@ -38,7 +39,6 @@ public AutoMergePackage()
}



/////////////////////////////////////////////////////////////////////////////
// Overridden Package Implementation
#region Package Members
Expand Down
2 changes: 2 additions & 0 deletions src/AutoMerge/AutoMergePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public AutoMergePage()
{
Title = Resources.AutoMergePageName;
}


}
}
8 changes: 6 additions & 2 deletions src/AutoMerge/Branches/BranchFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ public class BranchFactory
private readonly ChangesetVersionSpec _changesetVersion;
private readonly BranchValidator _branchValidator;
private readonly IEventAggregator _eventAggregator;
private readonly Settings _settings;

public BranchFactory(string sourceBranch,
string sourceFolder,
ChangesetVersionSpec changesetVersion,
BranchValidator branchValidator,
IEventAggregator eventAggregator)
IEventAggregator eventAggregator,
Settings settings)
{
_sourceBranch = sourceBranch;
_sourceFolder = sourceFolder;
_changesetVersion = changesetVersion;
_branchValidator = branchValidator;
_eventAggregator = eventAggregator;
_settings = settings;
}

public MergeInfoViewModel CreateTargetBranchInfo(ItemIdentifier targetBranch, ItemIdentifier targetPath)
Expand All @@ -37,14 +40,15 @@ public MergeInfoViewModel CreateSourceBranch()

private MergeInfoViewModel CreateBranch(string targetBranch, string targetPath)
{
var mergeInfo = new MergeInfoViewModel(_eventAggregator)
var mergeInfo = new MergeInfoViewModel(_eventAggregator, _settings.BranchNameMatches)
{
SourceBranch = _sourceBranch,
TargetBranch = targetBranch,
SourcePath = _sourceFolder,
TargetPath = targetPath,
ChangesetVersionSpec = _changesetVersion,
ValidationResult = BranchValidationResult.Success,
Aliases = _settings.BranchNameMatches
};

if (_sourceBranch != targetBranch)
Expand Down
9 changes: 7 additions & 2 deletions src/AutoMerge/Branches/BranchesSection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using AutoMerge.Base;
using System.ComponentModel.Composition;
using AutoMerge.Base;
using Microsoft.TeamFoundation.Controls;
using Microsoft.VisualStudio.ComponentModelHost;

namespace AutoMerge
{
Expand All @@ -11,9 +13,12 @@ protected override object CreateView(SectionInitializeEventArgs e)
return new BranchesView();
}

[Import]
public Settings Settings { get; set; }

protected override ITeamExplorerSection CreateViewModel(SectionInitializeEventArgs e)
{
var viewModel = base.CreateViewModel(e) ?? new BranchesViewModel(new VsLogger(ServiceProvider));
var viewModel = base.CreateViewModel(e) ?? new BranchesViewModel(Settings, new VsLogger(ServiceProvider));

return viewModel;
}
Expand Down
20 changes: 13 additions & 7 deletions src/AutoMerge/Branches/BranchesViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Globalization;
using System.Linq;
using System.Reflection;
Expand All @@ -16,6 +17,7 @@
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.VersionControl.Common;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell.Interop;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error upon loading system.

using TeamExplorerSectionViewModelBase = AutoMerge.Base.TeamExplorerSectionViewModelBase;

Expand All @@ -24,13 +26,14 @@ namespace AutoMerge
public sealed class BranchesViewModel : TeamExplorerSectionViewModelBase
{
private readonly IEventAggregator _eventAggregator;
private readonly Settings _settings;
private ChangesetService _changesetService;
private Workspace _workspace;

private ChangesetViewModel _changeset;
private bool _merging;

public BranchesViewModel(ILogger logger)
public BranchesViewModel(Settings settings, ILogger logger)
: base(logger)
{
Title = Resources.BrancheSectionName;
Expand All @@ -42,6 +45,7 @@ public BranchesViewModel(ILogger logger)
SelectWorkspaceCommand = new DelegateCommand<Workspace>(SelectWorkspaceExecute);
OpenSourceControlExplorerCommand = new DelegateCommand(OpenSourceControlExplorerExecute, OpenSourceControlExplorerCanExecute);

_settings = settings;
_eventAggregator = EventAggregatorFactory.Get();
_merging = false;
}
Expand Down Expand Up @@ -212,7 +216,7 @@ protected async override Task InitializeAsync(object sender, SectionInitializeEv
MergeMode.Merge,
MergeMode.MergeAndCheckIn
};
MergeMode = Settings.Instance.LastMergeOperation;
MergeMode = _settings.LastMergeOperation;

await RefreshAsync();
}
Expand Down Expand Up @@ -307,6 +311,8 @@ private ObservableCollection<MergeInfoViewModel> GetBranches(ITeamFoundationCont
var sourceTopFolder = CalculateTopFolder(changes);
var mergesRelationships = GetMergesRelationships(sourceTopFolder, versionControl);



if (mergesRelationships.Count > 0)
{
var sourceBranchIdentifier = changesetViewModel.Branches.Select(b => new ItemIdentifier(b)).First();
Expand All @@ -323,7 +329,7 @@ private ObservableCollection<MergeInfoViewModel> GetBranches(ITeamFoundationCont
var branchValidator = new BranchValidator(workspace, trackMerges);
var branchFactory = new BranchFactory(sourceBranch, sourceTopFolder,
changesetVersionSpec, branchValidator,
_eventAggregator);
_eventAggregator, _settings);

var sourceBranchInfo = versionControl.QueryBranchObjects(sourceBranchIdentifier, RecursionType.None)[0];
if (sourceBranchInfo.Properties != null && sourceBranchInfo.Properties.ParentBranch != null
Expand Down Expand Up @@ -581,7 +587,7 @@ private async void MergeExecute(MergeMode? mergeMode)
if (!mergeMode.HasValue)
return;
MergeMode = mergeMode.Value;
Settings.Instance.LastMergeOperation = mergeMode.Value;
_settings.LastMergeOperation = mergeMode.Value;
switch (mergeMode)
{
case MergeMode.Merge:
Expand Down Expand Up @@ -615,8 +621,8 @@ private async Task MergeAndCheckInExecute(bool checkInIfSuccess)
Message = string.Empty
};
var mergePath = string.Format("MERGE {0} -> {1}",
BranchHelper.GetShortBranchName(resultModel.BranchInfo.SourceBranch),
BranchHelper.GetShortBranchName(resultModel.BranchInfo.TargetBranch));
BranchHelper.GetShortBranchName(resultModel.BranchInfo.SourceBranch, _settings.BranchNameMatches),
BranchHelper.GetShortBranchName(resultModel.BranchInfo.TargetBranch, _settings.BranchNameMatches));
switch (resultModel.MergeResult)
{
case MergeResult.CheckInEvaluateFail:
Expand Down Expand Up @@ -769,7 +775,7 @@ private List<MergeResultModel> MergeExecuteInternal(bool checkInIfSuccess)
var pendingChanges = GetChangesetPendingChanges(changeset.Changes);
var mergeRelationships = GetMergeRelationships(pendingChanges, targetBranches, versionControl);

var commentFormater = new CommentFormater(Settings.Instance.CommentFormat);
var commentFormater = new CommentFormater(_settings.CommentFormat, _settings.BranchNameMatches);
foreach (var mergeInfo in mergeInfos.Where(b => b.Checked))
{
var mergeResultModel = new MergeResultModel
Expand Down
11 changes: 8 additions & 3 deletions src/AutoMerge/Branches/MergeInfoViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using AutoMerge.Configuration;
using AutoMerge.Events;
using AutoMerge.Prism.Events;
using Microsoft.TeamFoundation.VersionControl.Client;
Expand All @@ -8,11 +9,13 @@ namespace AutoMerge
public class MergeInfoViewModel
{
private readonly IEventAggregator _eventAggregator;
private readonly BranchNameMatch[] _aliases;
internal bool _checked;

public MergeInfoViewModel(IEventAggregator eventAggregator)
public MergeInfoViewModel(IEventAggregator eventAggregator, BranchNameMatch[] aliases)
{
_eventAggregator = eventAggregator;
_aliases = aliases;
}

public bool Checked
Expand Down Expand Up @@ -43,7 +46,7 @@ public string DisplayBranchName
{
get
{
return BranchHelper.GetShortBranchName(TargetBranch);
return BranchHelper.GetShortBranchName(TargetBranch, _aliases);
}
}

Expand All @@ -58,5 +61,7 @@ public bool IsSourceBranch
return string.Equals(SourceBranch, TargetBranch, StringComparison.OrdinalIgnoreCase);
}
}
}

public Configuration.BranchNameMatch[] Aliases { get; set; }
}
}
13 changes: 8 additions & 5 deletions src/AutoMerge/CommentFormater.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using AutoMerge.Configuration;

namespace AutoMerge
{
public class CommentFormater
{
private readonly CommentFormat _format;
private readonly BranchNameMatch[] _aliases;

public CommentFormater(CommentFormat format)
public CommentFormater(CommentFormat format, BranchNameMatch[] aliases)
{
_format = format;
_aliases = aliases;
}

public string Format(TrackMergeInfo trackMergeInfo, string targetBranch, MergeOption mergeOption)
{
var comment = mergeOption == MergeOption.KeepTarget ? _format.DiscardFormat : _format.Format;
comment = comment
.Replace("{OriginalBranch}", BranchHelper.GetShortBranchName(trackMergeInfo.OriginaBranch))
.Replace("{OriginalBranch}", BranchHelper.GetShortBranchName(trackMergeInfo.OriginaBranch, _aliases))
.Replace("{OriginalBranchFull}", trackMergeInfo.OriginaBranch)
.Replace("{SourceBranch}", BranchHelper.GetShortBranchName(trackMergeInfo.SourceBranch))
.Replace("{SourceBranch}", BranchHelper.GetShortBranchName(trackMergeInfo.SourceBranch, _aliases))
.Replace("{SourceBranchFull}", trackMergeInfo.SourceBranch)
.Replace("{TargetBranch}", BranchHelper.GetShortBranchName(targetBranch))
.Replace("{TargetBranch}", BranchHelper.GetShortBranchName(targetBranch, _aliases))
.Replace("{TargetBranchFull}", targetBranch)
.Replace("{FromOriginalToTarget}", FromOriginalToTarget(trackMergeInfo, targetBranch))
.Replace("{FromOriginalToTargetFull}", FromOriginalToTargetFull(trackMergeInfo, targetBranch))
Expand All @@ -41,7 +44,7 @@ private string GetWorkItemIds(List<long> sourceWorkItemIds)
private string FromOriginalToTarget(TrackMergeInfo trackMergeInfo, string targetBranch)
{
var mergePath = trackMergeInfo.FromOriginalToSourceBranches.Concat(new[] { trackMergeInfo.SourceBranch, targetBranch })
.Select(fullBranchName => BranchHelper.GetShortBranchName(fullBranchName));
.Select(fullBranchName => BranchHelper.GetShortBranchName(fullBranchName, _aliases));
var mergePathString = string.Join(_format.BranchDelimiter, mergePath);
return mergePathString;
}
Expand Down
14 changes: 14 additions & 0 deletions src/AutoMerge/Configuration/BranchNameMatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoMerge.Configuration
{
public class BranchNameMatch
{
public string match { get; set; }
public string alias { get; set; }
}
}
Loading