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

Commit 779a336

Browse files
Merge pull request #743 from github-for-unity/fixes/init-repo-fixes
We can only run local git commands if there's a git repo
2 parents 2e7f044 + a6c4016 commit 779a336

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -163,34 +163,18 @@ public void SetupGit(GitInstaller.GitInstallationState state)
163163

164164
if (firstRun)
165165
{
166-
var unityYamlMergeExec = Environment.UnityApplicationContents.Combine("Tools", "UnityYAMLMerge" + Environment.ExecutableExtension);
167-
168-
var yamlMergeCommand = Environment.IsWindows
169-
? $@"'{unityYamlMergeExec}' merge -p ""$BASE"" ""$REMOTE"" ""$LOCAL"" ""$MERGED"""
170-
: $@"'{unityYamlMergeExec}' merge -p '$BASE' '$REMOTE' '$LOCAL' '$MERGED'";
171-
172-
GitClient.SetConfig("merge.unityyamlmerge.cmd", yamlMergeCommand, GitConfigSource.Local)
173-
.Catch(e =>
174-
{
175-
Logger.Error(e, "Error setting merge.unityyamlmerge.cmd");
176-
return true;
177-
})
178-
.RunWithReturn(true);
179-
GitClient.SetConfig("merge.unityyamlmerge.trustExitCode", "false", GitConfigSource.Local)
180-
.Catch(e =>
181-
{
182-
Logger.Error(e, "Error setting merge.unityyamlmerge.trustExitCode");
183-
return true;
184-
})
185-
.RunWithReturn(true);
166+
if (Environment.RepositoryPath.IsInitialized)
167+
{
168+
ConfigureMergeSettings();
186169

187-
GitClient.LfsInstall()
188-
.Catch(e =>
189-
{
190-
Logger.Error(e, "Error running lfs install");
191-
return true;
192-
})
193-
.RunWithReturn(true);
170+
GitClient.LfsInstall()
171+
.Catch(e =>
172+
{
173+
Logger.Error(e, "Error running lfs install");
174+
return true;
175+
})
176+
.RunWithReturn(true);
177+
}
194178

195179
if (Environment.IsWindows)
196180
{
@@ -233,6 +217,8 @@ public void InitializeRepository()
233217
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
234218

235219
GitClient.Init().RunWithReturn(true);
220+
221+
ConfigureMergeSettings();
236222
GitClient.LfsInstall().RunWithReturn(true);
237223
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
238224
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
@@ -258,6 +244,25 @@ public void InitializeRepository()
258244
thread.Start();
259245
}
260246

247+
private void ConfigureMergeSettings()
248+
{
249+
var unityYamlMergeExec =
250+
Environment.UnityApplicationContents.Combine("Tools", "UnityYAMLMerge" + Environment.ExecutableExtension);
251+
var yamlMergeCommand = Environment.IsWindows
252+
? $@"'{unityYamlMergeExec}' merge -p ""$BASE"" ""$REMOTE"" ""$LOCAL"" ""$MERGED"""
253+
: $@"'{unityYamlMergeExec}' merge -p '$BASE' '$REMOTE' '$LOCAL' '$MERGED'";
254+
255+
GitClient.SetConfig("merge.unityyamlmerge.cmd", yamlMergeCommand, GitConfigSource.Local).Catch(e => {
256+
Logger.Error(e, "Error setting merge.unityyamlmerge.cmd");
257+
return true;
258+
}).RunWithReturn(true);
259+
260+
GitClient.SetConfig("merge.unityyamlmerge.trustExitCode", "false", GitConfigSource.Local).Catch(e => {
261+
Logger.Error(e, "Error setting merge.unityyamlmerge.trustExitCode");
262+
return true;
263+
}).RunWithReturn(true);
264+
}
265+
261266
public void RestartRepository()
262267
{
263268
if (!Environment.RepositoryPath.IsInitialized)

0 commit comments

Comments
 (0)