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

Commit 2959457

Browse files
authored
Merge pull request #738 from github-for-unity/fixes/git-setup
Validate git installations by version and fix setting up custom gits
2 parents 3b212d6 + f221040 commit 2959457

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+691
-819
lines changed

generate-package.sh

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
11
#!/bin/sh -eu
22
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33
if [ $# -lt 3 ]; then
4-
echo "Usage: generate-package.sh [git|lfs|ghu] [version] [path to file] [host url (optional)] [release notes file (optional)] [message file (optional)]"
4+
echo "Usage: generate-package.sh [git|lfs|ghu] [windows|mac|linux] [version] [path to file] [host url (optional)] [release notes file (optional)] [message file (optional)]"
55
exit 1
66
fi
77

8-
LFS_MD5="d0d59164a4b7b35685502d7c5f747f2f"
9-
GIT_MD5="50570ed932559f294d1a1361801740b9"
10-
MD5=""
11-
128
URL="http://ghfvs-installer.github.com"
13-
if [ $# -ge 4 ]; then
14-
URL=$4
9+
if [ $# -ge 5 ]; then
10+
URL=$5
1511
fi
1612

1713
if [ "$1" == "git" ]; then
18-
MD5=$GIT_MD5
19-
URL="$URL/unity/git"
14+
URL="$URL/unity/git/$2"
2015
fi
2116
if [ "$1" == "lfs" ]; then
22-
MD5=$LFS_MD5
23-
URL="$URL/unity/git"
17+
URL="$URL/unity/git/$2"
2418
fi
2519
if [ "$1" == "ghu" ]; then
26-
MD5=
2720
URL="$URL/unity/releases"
2821
fi
2922

3023
RN=""
3124
MSG=""
32-
if [ $# -ge 5 ]; then
33-
RN="$5"
25+
if [ $# -ge 6 ]; then
26+
RN="$6"
3427
fi
3528

36-
if [ $# -ge 6 ]; then
37-
MSG="$6"
29+
if [ $# -ge 7 ]; then
30+
MSG="$7"
3831
fi
3932

4033
EXEC="mono"
@@ -46,4 +39,4 @@ if [ ! -e "$DIR/build/CommandLine/CommandLine.exe" ]; then
4639
>&2 xbuild /target:CommandLine "$DIR/GitHub.Unity.sln" /verbosity:minimal
4740
fi
4841

49-
"$EXEC""$DIR/build/CommandLine/CommandLine.exe" --gen-package --version "$2" --path "$3" --url "$URL" --md5 "$MD5" --rn "$RN" --msg "$MSG"
42+
"$EXEC""$DIR/build/CommandLine/CommandLine.exe" --gen-package --version "$3" --path "$4" --url "$URL" --rn "$RN" --msg "$MSG"

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 127 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ abstract class ApplicationManagerBase : IApplicationManager
1414
private RepositoryManager repositoryManager;
1515
private Progress progressReporter;
1616
protected bool isBusy;
17-
protected bool firstRun;
18-
protected Guid instanceId;
17+
private bool firstRun;
18+
protected bool FirstRun { get { return firstRun; } set { firstRun = value; } }
19+
private Guid instanceId;
20+
protected Guid InstanceId { get { return instanceId; } set { instanceId = value; } }
1921

2022
public event Action<IProgress> OnProgress
2123
{
@@ -49,52 +51,76 @@ public void Run()
4951
{
5052
isBusy = true;
5153

52-
var thread = new Thread(obj =>
54+
var thread = new Thread(() =>
5355
{
54-
CancellationToken token = (CancellationToken)obj;
55-
SetupMetrics(Environment.UnityVersion, firstRun, instanceId);
56-
57-
if (Environment.IsMac)
56+
GitInstallationState state = new GitInstallationState();
57+
try
5858
{
59-
var getEnvPath = new SimpleProcessTask(token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
60-
.Configure(ProcessManager, dontSetupGit: true)
61-
.Catch(e => true); // make sure this doesn't throw if the task fails
62-
var path = getEnvPath.RunWithReturn(true);
63-
if (getEnvPath.Successful)
59+
SetupMetrics(Environment.UnityVersion, instanceId);
60+
61+
if (Environment.IsMac)
6462
{
65-
Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
66-
Environment.Path = path?.Split(new[] { "\"" }, StringSplitOptions.None)[1];
63+
var getEnvPath = new SimpleProcessTask(CancellationToken, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
64+
.Configure(ProcessManager, dontSetupGit: true)
65+
.Catch(e => true); // make sure this doesn't throw if the task fails
66+
var path = getEnvPath.RunWithReturn(true);
67+
if (getEnvPath.Successful)
68+
{
69+
Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
70+
Environment.Path = path?.Split(new[] { "\"" }, StringSplitOptions.None)[1];
71+
}
6772
}
68-
}
6973

70-
GitInstallationState state = new GitInstallationState();
71-
var runInstallers = firstRun;
74+
var installer = new GitInstaller(Environment, ProcessManager, CancellationToken)
75+
{ Progress = progressReporter };
76+
state = Environment.GitInstallationState;
77+
if (!state.GitIsValid && !state.GitLfsIsValid && FirstRun)
78+
{
79+
// importing old settings
80+
NPath gitExecutablePath = Environment.SystemSettings.Get(Constants.GitInstallPathKey, NPath.Default);
81+
if (gitExecutablePath.IsInitialized)
82+
{
83+
Environment.SystemSettings.Unset(Constants.GitInstallPathKey);
84+
state.GitExecutablePath = gitExecutablePath;
85+
state.GitInstallationPath = gitExecutablePath.Parent.Parent;
86+
Environment.GitInstallationState = state;
87+
}
88+
}
7289

73-
if (!runInstallers)
74-
{
75-
state = SystemSettings.Get<GitInstallationState>(Constants.GitInstallationState) ?? state;
76-
var now = DateTimeOffset.Now;
77-
runInstallers = now.Date != state.GitLastCheckTime.Date || (!(state.GitIsValid && state.GitLfsIsValid));
78-
}
90+
if (state.GitIsValid && state.GitLfsIsValid)
91+
{
92+
if (firstRun)
93+
{
94+
installer.ValidateGitVersion(state);
95+
if (state.GitIsValid)
96+
{
97+
installer.ValidateGitLfsVersion(state);
98+
}
99+
}
100+
}
79101

80-
if (runInstallers)
81-
{
82102
Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
83103
.SetupOctorunIfNeeded();
84104

85-
state = new GitInstaller(Environment, ProcessManager, TaskManager, SystemSettings)
86-
{ Progress = progressReporter }
87-
.SetupGitIfNeeded();
88-
}
105+
if (!state.GitIsValid || !state.GitLfsIsValid)
106+
{
107+
state = installer.SetupGitIfNeeded();
108+
}
109+
110+
SetupGit(state);
89111

90-
SetupGit(state);
112+
if (state.GitIsValid && state.GitLfsIsValid)
113+
{
114+
RestartRepository();
115+
}
91116

92-
if (state.GitIsValid && state.GitLfsIsValid)
117+
}
118+
catch (Exception ex)
93119
{
94-
RestartRepository();
120+
Logger.Error(ex, "A problem ocurred setting up Git");
95121
}
96122

97-
new ActionTask<bool>(token, (s, gitIsValid) =>
123+
new ActionTask<bool>(CancellationToken, (s, gitIsValid) =>
98124
{
99125
InitializationComplete();
100126
if (gitIsValid)
@@ -106,17 +132,33 @@ public void Run()
106132
{ Affinity = TaskAffinity.UI }
107133
.Start();
108134
});
109-
thread.Start(CancellationToken);
135+
thread.Start();
110136
}
111137

112-
private void SetupGit(GitInstaller.GitInstallationState state)
138+
public void SetupGit(GitInstaller.GitInstallationState state)
113139
{
114-
if (!(state.GitIsValid && state.GitLfsIsValid))
140+
if (!state.GitIsValid || !state.GitLfsIsValid)
141+
{
142+
if (!state.GitExecutablePath.IsInitialized)
143+
{
144+
Logger.Warning(Localization.GitNotFound);
145+
}
146+
else if (!state.GitLfsExecutablePath.IsInitialized)
147+
{
148+
Logger.Warning(Localization.GitLFSNotFound);
149+
}
150+
else if (state.GitVersion < Constants.MinimumGitVersion)
151+
{
152+
Logger.Warning(String.Format(Localization.GitVersionTooLow, state.GitExecutablePath, state.GitVersion, Constants.MinimumGitVersion));
153+
}
154+
else if (state.GitLfsVersion < Constants.MinimumGitLfsVersion)
155+
{
156+
Logger.Warning(String.Format(Localization.GitLfsVersionTooLow, state.GitLfsExecutablePath, state.GitLfsVersion, Constants.MinimumGitLfsVersion));
157+
}
115158
return;
159+
}
116160

117-
Environment.GitExecutablePath = state.GitExecutablePath;
118-
Environment.GitLfsExecutablePath = state.GitLfsExecutablePath;
119-
Environment.IsCustomGitExecutable = state.IsCustomGitPath;
161+
Environment.GitInstallationState = state;
120162
Environment.User.Initialize(GitClient);
121163

122164
if (firstRun)
@@ -142,7 +184,13 @@ private void SetupGit(GitInstaller.GitInstallationState state)
142184
})
143185
.RunWithReturn(true);
144186

145-
GitClient.LfsInstall().RunWithReturn(true);
187+
GitClient.LfsInstall()
188+
.Catch(e =>
189+
{
190+
Logger.Error(e, "Error running lfs install");
191+
return true;
192+
})
193+
.RunWithReturn(true);
146194

147195
if (Environment.IsWindows)
148196
{
@@ -170,37 +218,53 @@ private void SetupGit(GitInstaller.GitInstallationState state)
170218

171219
public void InitializeRepository()
172220
{
173-
var thread = new Thread(obj =>
221+
isBusy = true;
222+
var thread = new Thread(() =>
174223
{
175-
CancellationToken token = (CancellationToken)obj;
176-
var targetPath = NPath.CurrentDirectory;
177-
178-
var gitignore = targetPath.Combine(".gitignore");
179-
var gitAttrs = targetPath.Combine(".gitattributes");
180-
var assetsGitignore = targetPath.Combine("Assets", ".gitignore");
181-
182-
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
183-
184-
GitClient.Init().RunWithReturn(true);
185-
GitClient.LfsInstall().RunWithReturn(true);
186-
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
187-
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
188-
assetsGitignore.CreateFile();
189-
GitClient.Add(filesForInitialCommit).RunWithReturn(true);
190-
GitClient.Commit("Initial commit", null).RunWithReturn(true);
191-
Environment.InitializeRepository();
192-
RestartRepository();
193-
UsageTracker.IncrementProjectsInitialized();
194-
TaskManager.RunInUI(InitializeUI);
224+
var success = true;
225+
try
226+
{
227+
var targetPath = NPath.CurrentDirectory;
228+
229+
var gitignore = targetPath.Combine(".gitignore");
230+
var gitAttrs = targetPath.Combine(".gitattributes");
231+
var assetsGitignore = targetPath.Combine("Assets", ".gitignore");
232+
233+
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
234+
235+
GitClient.Init().RunWithReturn(true);
236+
GitClient.LfsInstall().RunWithReturn(true);
237+
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
238+
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
239+
assetsGitignore.CreateFile();
240+
GitClient.Add(filesForInitialCommit).RunWithReturn(true);
241+
GitClient.Commit("Initial commit", null).RunWithReturn(true);
242+
Environment.InitializeRepository();
243+
UsageTracker.IncrementProjectsInitialized();
244+
}
245+
catch (Exception ex)
246+
{
247+
Logger.Error(ex, "A problem ocurred initializing the repository");
248+
success = false;
249+
}
250+
251+
if (success)
252+
{
253+
RestartRepository();
254+
TaskManager.RunInUI(InitializeUI);
255+
}
256+
isBusy = false;
195257
});
196-
thread.Start(CancellationToken);
258+
thread.Start();
197259
}
198260

199261
public void RestartRepository()
200262
{
201263
if (!Environment.RepositoryPath.IsInitialized)
202264
return;
203265

266+
repositoryManager?.Dispose();
267+
204268
repositoryManager = Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, Environment.FileSystem, Environment.RepositoryPath);
205269
repositoryManager.Initialize();
206270
Environment.Repository.Initialize(repositoryManager, TaskManager);
@@ -209,7 +273,7 @@ public void RestartRepository()
209273
Logger.Trace($"Got a repository? {(Environment.Repository != null ? Environment.Repository.LocalPath : "null")}");
210274
}
211275

212-
protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
276+
protected void SetupMetrics(string unityVersion, Guid instanceId)
213277
{
214278
string userId = null;
215279
if (UserSettings.Exists(Constants.GuidKey))

src/GitHub.Api/Application/IApplicationManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ public interface IApplicationManager : IDisposable
1919
IUsageTracker UsageTracker { get; }
2020
bool IsBusy { get; }
2121
void Run();
22-
void RestartRepository();
2322
void InitializeRepository();
2423
event Action<IProgress> OnProgress;
24+
void SetupGit(GitInstaller.GitInstallationState state);
25+
void RestartRepository();
2526
}
2627
}

0 commit comments

Comments
 (0)