Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Fixing UnityYamlMerge to use merge driver #978

Merged
merged 1 commit into from
Dec 6, 2018
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
51 changes: 42 additions & 9 deletions src/GitHub.Api/Application/ApplicationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
{
if (Environment.RepositoryPath.IsInitialized)
{
ConfigureMergeSettings();
UpdateMergeSettings();

GitClient.LfsInstall()
.Catch(e =>
Expand Down Expand Up @@ -280,25 +280,58 @@ public void InitializeRepository()
thread.Start();
}

private void ConfigureMergeSettings()
private void ConfigureMergeSettings(string keyName = null)
{
var unityYamlMergeExec =
Environment.UnityApplicationContents.Combine("Tools", "UnityYAMLMerge" + Environment.ExecutableExtension);
var yamlMergeCommand = Environment.IsWindows
? $@"'{unityYamlMergeExec}' merge -p ""$BASE"" ""$REMOTE"" ""$LOCAL"" ""$MERGED"""
: $@"'{unityYamlMergeExec}' merge -p '$BASE' '$REMOTE' '$LOCAL' '$MERGED'";

GitClient.SetConfig("merge.unityyamlmerge.cmd", yamlMergeCommand, GitConfigSource.Local).Catch(e => {
Logger.Error(e, "Error setting merge.unityyamlmerge.cmd");
var yamlMergeCommand = $"'{unityYamlMergeExec}' merge -h -p --force %O %B %A %A";

keyName = keyName ?? "unityyamlmerge";

GitClient.SetConfig($"merge.{keyName}.name", "Unity SmartMerge (UnityYamlMerge)", GitConfigSource.Local).Catch(e => {
Logger.Error(e, "Error setting merge." + keyName + ".name");
return true;
}).RunSynchronously();

GitClient.SetConfig($"merge.{keyName}.driver", yamlMergeCommand, GitConfigSource.Local).Catch(e => {
Logger.Error(e, "Error setting merge." + keyName + ".driver");
return true;
}).RunSynchronously();

GitClient.SetConfig("merge.unityyamlmerge.trustExitCode", "false", GitConfigSource.Local).Catch(e => {
Logger.Error(e, "Error setting merge.unityyamlmerge.trustExitCode");
GitClient.SetConfig($"merge.{keyName}.recursive", "binary", GitConfigSource.Local).Catch(e => {
Logger.Error(e, "Error setting merge." + keyName + ".recursive");
return true;
}).RunSynchronously();
}

private void UpdateMergeSettings()
{
var gitAttributesPath = Environment.RepositoryPath.Combine(".gitattributes");
if (gitAttributesPath.FileExists())
{
var readAllText = gitAttributesPath.ReadAllText();
var containsLegacyUnityYamlMergeError = readAllText.Contains("unityamlmerge");

if (containsLegacyUnityYamlMergeError)
{
ConfigureMergeSettings("unityamlmerge");
}
}

GitClient.UnSetConfig("merge.unityyamlmerge.cmd", GitConfigSource.Local).Catch(e => {
Logger.Error(e, "Error removing merge.unityyamlmerge.cmd");
return true;
}).RunSynchronously();

GitClient.UnSetConfig("merge.unityyamlmerge.trustExitCode", GitConfigSource.Local).Catch(e => {
Logger.Error(e, "Error removing merge.unityyamlmerge.trustExitCode");
return true;
}).RunSynchronously();

ConfigureMergeSettings();
}

public void RestartRepository()
{
if (!Environment.RepositoryPath.IsInitialized)
Expand Down
16 changes: 16 additions & 0 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public interface IGitClient
/// <returns>String output of git command</returns>
ITask<string> SetConfig(string key, string value, GitConfigSource configSource, IOutputProcessor<string> processor = null);

/// <summary>
/// Executes `git config --unset` to remove a configuration value.
/// </summary>
/// <param name="key">The configuration key to remove</param>
/// <param name="configSource">The config source (unspecified, local,user,global) to use</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> UnSetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null);

/// <summary>
/// Executes two `git config get` commands to get the git user and email.
/// </summary>
Expand Down Expand Up @@ -367,6 +376,13 @@ public ITask<string> SetConfig(string key, string value, GitConfigSource configS
.Configure(processManager);
}

///<inheritdoc/>
public ITask<string> UnSetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null)
{
return new GitConfigUnSetTask(key, configSource, cancellationToken, processor)
.Configure(processManager);
}

///<inheritdoc/>
public ITask<GitUser> GetConfigUserAndEmail()
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Api/Git/Tasks/GitConfigSetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public GitConfigSetTask(string key, string value, GitConfigSource configSource,
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
public override string Message { get; set; } = "Writing configuration...";
}
}
}
28 changes: 28 additions & 0 deletions src/GitHub.Api/Git/Tasks/GitConfigUnSetTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Threading;

namespace GitHub.Unity
{
class GitConfigUnSetTask : ProcessTask<string>
{
private readonly string arguments;

public GitConfigUnSetTask(string key, GitConfigSource configSource,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
{
var source = "";
source +=
configSource == GitConfigSource.NonSpecified ? "--unset" :
configSource == GitConfigSource.Local ? "--local --unset" :
configSource == GitConfigSource.User ? "--global --unset" :
"--system --unset";
arguments = String.Format("config {0} {1}", source, key);
Name = String.Format("config {0} {1}", source, key);
}

public override string ProcessArguments { get { return arguments; } }
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
public override string Message { get; set; } = "Writing configuration...";
}
}
1 change: 1 addition & 0 deletions src/GitHub.Api/GitHub.Api.45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="Git\Tasks\GitCheckoutTask.cs" />
<Compile Include="Git\GitAheadBehindStatus.cs" />
<Compile Include="Git\Tasks\GitAheadBehindStatusTask.cs" />
<Compile Include="Git\Tasks\GitConfigUnSetTask.cs" />
<Compile Include="Git\Tasks\GitCountObjectsTask.cs" />
<Compile Include="Git\Tasks\GitLfsVersionTask.cs" />
<Compile Include="Git\Tasks\GitVersionTask.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Api/GitHub.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Git\Tasks\GitCheckoutTask.cs" />
<Compile Include="Git\GitAheadBehindStatus.cs" />
<Compile Include="Git\Tasks\GitAheadBehindStatusTask.cs" />
<Compile Include="Git\Tasks\GitConfigUnSetTask.cs" />
<Compile Include="Git\Tasks\GitCountObjectsTask.cs" />
<Compile Include="Git\Tasks\GitLfsVersionTask.cs" />
<Compile Include="Git\Tasks\GitVersionTask.cs" />
Expand Down