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

Commit c5e809c

Browse files
authored
Merge pull request #287 from github/fixes/unity-yaml-merge
Fix to configure Yaml merging with Unity
2 parents c484a85 + e4c74ba commit c5e809c

File tree

9 files changed

+40
-16
lines changed

9 files changed

+40
-16
lines changed

src/GitHub.Api/DefaultEnvironment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public string GetEnvironmentVariable(string variable)
2222
return Environment.GetEnvironmentVariable(variable);
2323
}
2424

25+
public string UnityApplication { get; set; }
2526
public string UnityAssetsPath { get; set; }
2627
public string UnityProjectPath { get; set; }
2728
public string ExtensionInstallPath { get; set; }

src/GitHub.Api/IEnvironment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface IEnvironment
1515
bool IsWindows { get; }
1616
bool IsLinux { get; }
1717
bool IsMac { get; }
18+
string UnityApplication { get; set; }
1819
string UnityAssetsPath { get; set; }
1920
string UnityProjectPath { get; set; }
2021
string ExtensionInstallPath { get; set; }

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class GitInstaller : IGitInstaller
1313
private const string TempPathPrefix = "github-unity-portable";
1414
private const string GitZipFile = "git.zip";
1515
private const string GitLfsZipFile = "git-lfs.zip";
16-
private NPath gitConfigDestinationPath;
1716

1817
private readonly CancellationToken cancellationToken;
1918
private readonly IEnvironment environment;
@@ -68,15 +67,13 @@ public GitInstaller(IEnvironment environment, IZipHelper sharpZipLibHelper, IFil
6867
GitDestinationPath = GitDestinationPath.Combine(GitExecutable);
6968

7069
GitLfsDestinationPath = PackageDestinationDirectory;
71-
gitConfigDestinationPath = PackageDestinationDirectory;
70+
7271
if (DefaultEnvironment.OnWindows)
7372
{
7473
GitLfsDestinationPath = GitLfsDestinationPath.Combine("mingw32");
75-
gitConfigDestinationPath = gitConfigDestinationPath.Combine("mingw32");
7674
}
77-
GitLfsDestinationPath = GitLfsDestinationPath.Combine("libexec", "git-core", GitLfsExecutable);
78-
gitConfigDestinationPath = gitConfigDestinationPath.Combine("etc", "gitconfig");
7975

76+
GitLfsDestinationPath = GitLfsDestinationPath.Combine("libexec", "git-core", GitLfsExecutable);
8077
}
8178

8279
public bool IsExtracted()
@@ -138,12 +135,6 @@ public async Task<bool> SetupIfNeeded(IProgress<float> zipFileProgress = null, I
138135

139136
ret &= await SetupGitLfsIfNeeded(tempPath, zipFileProgress, estimatedDurationProgress);
140137

141-
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, "gitconfig", tempPath);
142-
if (archiveFilePath.FileExists())
143-
{
144-
archiveFilePath.Copy(gitConfigDestinationPath);
145-
}
146-
147138
tempPath.Delete();
148139
return ret;
149140
}

src/GitHub.Api/RepositoryLocator.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ public void Run()
4040

4141
var initTask = new GitInitTask(environment, processManager, null);
4242
return initTask.RunAsync(token)
43+
.ContinueWith(_ => {
44+
var unityYamlMergeExec = environment.UnityApplication.ToNPath().Parent.Combine("Tools", "UnityYAMLMerge");
45+
var yamlMergeCommand = string.Format(@"'{0}' merge -p ""$BASE"" ""$REMOTE"" ""$LOCAL"" ""$MERGED""", unityYamlMergeExec);
46+
var t = new GitConfigSetTask(environment, processManager, null, "merge.unityyamlmerge.cmd", yamlMergeCommand, GitConfigSource.Local);
47+
return t.RunAsync(token);
48+
}, token, TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted, ThreadingHelper.TaskScheduler)
49+
.ContinueWith(_ =>
50+
{
51+
var t = new GitConfigSetTask(environment, processManager, null, "merge.unityyamlmerge.trustExitCode", "false", GitConfigSource.Local);
52+
return t.RunAsync(token);
53+
}, token, TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted, ThreadingHelper.TaskScheduler)
54+
.ContinueWith(_ =>
55+
{
56+
Logger.Trace("LFS install");
57+
58+
var t = new GitLfsInstallTask(environment, processManager, null);
59+
return t.RunAsync(token);
60+
}, token, TaskContinuationOptions.NotOnCanceled | TaskContinuationOptions.NotOnFaulted, ThreadingHelper.TaskScheduler)
4361
.ContinueWith(_ =>
4462
{
4563
Logger.Trace("LFS install");

src/GitHub.Api/RepositoryProcessRunner.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface IRepositoryProcessRunner
88
{
99
ITask<GitStatus?> PrepareGitStatus(ITaskResultDispatcher<GitStatus> resultDispatcher);
1010
Task<bool> RunGitConfigGet(ITaskResultDispatcher<string> resultDispatcher, string key, GitConfigSource configSource);
11+
Task<bool> RunGitConfigSet(ITaskResultDispatcher<string> resultDispatcher, string key, string value, GitConfigSource configSource);
1112
ITask<IEnumerable<GitLock>> PrepareGitListLocks(ITaskResultDispatcher<IEnumerable<GitLock>> resultDispatcher, bool local);
1213
ITask PrepareGitPull(ITaskResultDispatcher<string> resultDispatcher, string remote, string branch);
1314
ITask PrepareGitPush(ITaskResultDispatcher<string> resultDispatcher, string remote, string branch);
@@ -55,6 +56,12 @@ public Task<bool> RunGitConfigGet(ITaskResultDispatcher<string> resultDispatcher
5556
return task.RunAsync(cancellationToken);
5657
}
5758

59+
public Task<bool> RunGitConfigSet(ITaskResultDispatcher<string> resultDispatcher, string key, string value, GitConfigSource configSource)
60+
{
61+
var task = new GitConfigSetTask(environment, processManager, resultDispatcher, key, value, configSource);
62+
return task.RunAsync(cancellationToken);
63+
}
64+
5865
public ITask<IEnumerable<GitLock>> PrepareGitListLocks(ITaskResultDispatcher<IEnumerable<GitLock>> resultDispatcher,
5966
bool local)
6067
{

src/GitHub.Api/Resources/.gitattributes

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
* text=auto
22

33
# Unity files
4-
*.meta -text
5-
*.unity -text
6-
*.asset -text
7-
*.prefab -text
4+
*.meta -text -merge=unityamlmerge
5+
*.unity -text -merge=unityamlmerge
6+
*.asset -text -merge=unityamlmerge
7+
*.prefab -text -merge=unityamlmerge
88

99
# Image formats
1010
*.psd filter=lfs diff=lfs merge=lfs -text

src/GitHub.Api/Tasks/GitConfigSetTask.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class GitConfigSetTask : GitTask
88
private readonly string value;
99
private readonly string arguments;
1010
private bool done = false;
11+
private string label;
1112

1213
public GitConfigSetTask(IEnvironment environment, IProcessManager processManager,
1314
ITaskResultDispatcher<string> resultDispatcher,
@@ -23,6 +24,7 @@ public GitConfigSetTask(IEnvironment environment, IProcessManager processManager
2324
configSource == GitConfigSource.User ? "--replace-all --global" :
2425
"--replace-all --system";
2526
arguments = String.Format("config {0} {1} \"{2}\"", source, key, value);
27+
label = String.Format("config {0} {1} \"{2}\"", source, key, new String('*', value.Length));
2628
}
2729

2830
protected override ProcessOutputManager HookupOutput(IProcess process)
@@ -43,7 +45,7 @@ protected override ProcessOutputManager HookupOutput(IProcess process)
4345
public override bool Blocking { get { return false; } }
4446
public override bool Critical { get { return false; } }
4547
public override bool Cached { get { return false; } }
46-
public override string Label { get { return "git config"; } }
48+
public override string Label { get { return label;} }
4749
protected override string ProcessArguments { get { return arguments; } }
4850
}
4951
}

src/IntegrationTests/Git/IntegrationTestEnvironment.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public string GitExecutablePath
8585
public bool IsLinux => defaultEnvironment.IsLinux;
8686
public bool IsMac => defaultEnvironment.IsMac;
8787

88+
public string UnityApplication { get; set; }
89+
8890
public string UnityAssetsPath { get; set; }
8991

9092
public string UnityProjectPath

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ protected override void InitializeEnvironment()
7979
var assetsPath = Application.dataPath.ToNPath();
8080
var projectPath = assetsPath.Parent;
8181

82+
Environment.UnityApplication = EditorApplication.applicationPath;
83+
8284
Environment.UnityAssetsPath = assetsPath.ToString(SlashMode.Forward);
8385
Environment.UnityProjectPath = projectPath.ToString(SlashMode.Forward);
8486

0 commit comments

Comments
 (0)