Skip to content
This repository was archived by the owner on Mar 15, 2021. It is now read-only.

Commit c8c4b06

Browse files
authored
Merge pull request #7 from RenderHeads/master
Credentials, LFS, Full reimport, -7 error fix, misc fixes.
2 parents 69ba917 + a69da20 commit c8c4b06

18 files changed

+522
-72
lines changed
0 Bytes
Binary file not shown.

Assets/Package/Lib/GitRepositoryManager.dll.meta

Lines changed: 2 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Package/RepoManagerWindow.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using UnityEditor;
77
using UnityEditor.AnimatedValues;
8+
using UnityEditor.Callbacks;
89
using UnityEngine;
910

1011
namespace GitRepositoryManager
@@ -37,6 +38,8 @@ private class DependencyInfo
3738
private bool showWarningMessage;
3839
private bool lastFrameWasWaitingToShowWarning;
3940

41+
private const string FULL_RE_IMPORT_KEY = "RepositoryManager.FullReImport";
42+
4043
private HashSet<RepoPanel> _reposWereBusy = new HashSet<RepoPanel>();
4144
private HashSet<RepoPanel> _reposBusy = new HashSet<RepoPanel>();
4245

@@ -106,7 +109,10 @@ private void UpdateDependencies(List<Dependency> updatedDependencies = null)
106109
RepoPanel panel = new RepoPanel(_repoPath, dependency, GetPlatformAuthentication());
107110
panel.OnRemovalRequested += OnPanelRemovalRequested;
108111
panel.OnDeleteAssetsRequested += DeleteAssets;
109-
panel.OnCopyFinished += UpdateAssetDatabaseForNewAssets;
112+
panel.OnCopyFinished += (assets, updatedRepos) =>
113+
{
114+
UpdateAssetDatabaseForNewAssets(assets, EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true), updatedRepos);
115+
};
110116
_repoPanels.Add(panel);
111117
}
112118
}
@@ -153,26 +159,33 @@ private void DeleteAssets(List<string> toDelete)
153159
//Debug.Log("Evaluating next directory " + parentDir.FullName);
154160
}
155161
}
156-
157162
}
158163
}
159164

160-
private void UpdateAssetDatabaseForNewAssets(List<string> coppiedAssets, params RepoPanel[] updatedRepos)
165+
private void UpdateAssetDatabaseForNewAssets(List<string> coppiedAssets, bool fullReImport, params RepoPanel[] updatedRepos)
161166
{
162-
//Update all assets individually to avoid a full editor re-import
163-
for (int i = 0; i < coppiedAssets.Count; i++)
167+
if (fullReImport)
164168
{
165-
string extension = Path.GetExtension(coppiedAssets[i]);
166-
if (extension == ".meta")
169+
EditorUtility.DisplayProgressBar("Importing Repositories", "Performing full re-import" + GUIUtility.GetLoadingDots(), (float)EditorApplication.timeSinceStartup % 1);
170+
AssetDatabase.Refresh();
171+
}
172+
else
173+
{
174+
//Update all assets individually to avoid a full editor re-import
175+
for (int i = 0; i < coppiedAssets.Count; i++)
167176
{
168-
//dont import meta files directly.
169-
continue;
170-
}
177+
string extension = Path.GetExtension(coppiedAssets[i]);
178+
if (extension == ".meta")
179+
{
180+
//dont import meta files directly.
181+
continue;
182+
}
171183

172-
string assetDBPath = GetAssetDatabasePathFromFullPath(coppiedAssets[i]);
184+
string assetDBPath = GetAssetDatabasePathFromFullPath(coppiedAssets[i]);
173185

174-
EditorUtility.DisplayProgressBar("Importing Repositories", "Importing repositories into project. Please wait a moment" + GUIUtility.GetLoadingDots(), ((float)i) / coppiedAssets.Count);
175-
AssetDatabase.ImportAsset(assetDBPath, ImportAssetOptions.ForceSynchronousImport);
186+
EditorUtility.DisplayProgressBar("Importing Repositories", "Importing repositories into project. Please wait a moment" + GUIUtility.GetLoadingDots(), ((float)i) / coppiedAssets.Count);
187+
AssetDatabase.ImportAsset(assetDBPath, ImportAssetOptions.ForceSynchronousImport);
188+
}
176189
}
177190

178191
//snapshot folder and file state to compare against later!
@@ -290,7 +303,7 @@ private void UpdateEditor()
290303

291304
if(coppiedAssets.Count > 0)
292305
{
293-
UpdateAssetDatabaseForNewAssets(coppiedAssets, updatedRepos.ToArray());
306+
UpdateAssetDatabaseForNewAssets(coppiedAssets, EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true), updatedRepos.ToArray());
294307
}
295308

296309
if (repaint)
@@ -308,6 +321,9 @@ private ICredentialManager GetPlatformAuthentication()
308321

309322
private void OnGUI()
310323
{
324+
bool reImport = EditorGUILayout.Toggle("Full Re-Import", EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true));
325+
EditorPrefs.SetBool(FULL_RE_IMPORT_KEY, reImport);
326+
311327
Rect labelRect = EditorGUILayout.GetControlRect();
312328
labelRect.y += labelRect.height / 2f;
313329

Assets/Repositories/ContentEngine.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugin/Src/Repository.cs

Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ List<string> DirectoryCopy(string sourceDirName, string destDirName, string[] fo
239239
}
240240
}
241241

242-
243242
public void CopyBackChanges()
244243
{
245244
//Swapped from forward copy. Other logic can stay the same.
@@ -298,6 +297,7 @@ void DirectoryCopy(string sourceDirName, string destDirName)
298297
}
299298
}
300299
}
300+
301301
public void CancelUpdate()
302302
{
303303
if(_inProgress) _cancellationPending = true;
@@ -324,7 +324,6 @@ public bool LastOperationSuccess
324324
}
325325
}
326326

327-
328327
public bool CancellationPending
329328
{
330329
get
@@ -380,13 +379,13 @@ private void UpdateTask(object stateInfo)
380379

381380
FetchOptions fetchOptions = new FetchOptions()
382381
{
383-
TagFetchMode = TagFetchMode.All,
382+
/*TagFetchMode = TagFetchMode.All,
384383
OnTransferProgress = new LibGit2Sharp.Handlers.TransferProgressHandler((progress) =>
385384
{
386385
_progressQueue.Enqueue(new Progress(((float)progress.ReceivedObjects) / progress.TotalObjects, "Fetching " + progress.ReceivedObjects + "/" + progress.TotalObjects + "(" + progress.ReceivedBytes + " bytes )"));
387386
388387
return _cancellationPending;
389-
}),
388+
}),*/
390389
CredentialsProvider = (credsUrl, user, supportedCredentials) =>
391390
{
392391
state.CredentialManager.GetCredentials(credsUrl, user, supportedCredentials, out var credentials, out string message);
@@ -401,10 +400,10 @@ private void UpdateTask(object stateInfo)
401400
//Repo exists we are doing a pull
402401
using (var repo = new LibGit2Sharp.Repository(state.LocalDestination))
403402
{
404-
_progressQueue.Enqueue(new Progress(0, "Nuking local changes. Checking out " + state.Branch));
403+
//_progressQueue.Enqueue(new Progress(0, "Nuking local changes. Checking out " + state.Branch));
405404

406-
Branch branch = repo.Branches[state.Branch];
407-
Commands.Checkout(repo, branch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force, CheckoutNotifyFlags = CheckoutNotifyFlags.None});
405+
//Branch branch = repo.Branches[state.Branch];
406+
//Commands.Checkout(repo, branch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force, CheckoutNotifyFlags = CheckoutNotifyFlags.None});
408407

409408
// Credential information to fetch
410409
PullOptions options = new PullOptions
@@ -414,7 +413,7 @@ private void UpdateTask(object stateInfo)
414413

415414
// User information to create a merge commit. Should not happen as we force checkout before pulling.
416415
var signature = new LibGit2Sharp.Signature(
417-
new Identity("MergeNotAllowed", "MergeNotAllowed@MergeMail.com"), DateTimeOffset.Now);
416+
new Identity("RepositoryManager", "repositorymanager@mergemail.com"), DateTimeOffset.Now);
418417

419418
try
420419
{
@@ -428,6 +427,37 @@ private void UpdateTask(object stateInfo)
428427
_progressQueue.Enqueue(new Progress(0, "Pull failed: " + e.Message));
429428
_lastOperationSuccess = false;
430429
}
430+
431+
/*try
432+
{
433+
var remote = repo.Network.Remotes["origin"];
434+
var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
435+
436+
_progressQueue.Enqueue(new Progress(0, "Fetching from " + remote.Name));
437+
438+
Commands.Fetch(repo, remote.Name, refSpecs, fetchOptions, "");
439+
440+
_progressQueue.Enqueue(new Progress(1, "Complete"));
441+
442+
try
443+
{
444+
Branch branch = repo.Branches["origin/" + state.Branch];
445+
var signature = new Signature(new Identity("RepositoryManager", "Repositorymanager@Mergemail.com"), DateTimeOffset.Now);
446+
repo.Merge(branch, signature);
447+
448+
_lastOperationSuccess = true;
449+
}
450+
catch (Exception e)
451+
{
452+
_progressQueue.Enqueue(new Progress(0, "Merge failed: " + e.Message));
453+
_lastOperationSuccess = false;
454+
}
455+
}
456+
catch (Exception e)
457+
{
458+
_progressQueue.Enqueue(new Progress(0, "Fetch failed: " + e.Message));
459+
_lastOperationSuccess = false;
460+
}*/
431461
}
432462
}
433463
else
@@ -471,6 +501,20 @@ private void UpdateTask(object stateInfo)
471501
}
472502
}
473503

504+
if(LastOperationSuccess)
505+
{
506+
_progressQueue.Enqueue(new Progress(1, "Downloading LFS files"));
507+
try
508+
{
509+
InstallAndPullLFS(state.LocalDestination);
510+
}
511+
catch(Exception e)
512+
{
513+
_progressQueue.Enqueue(new Progress(0, "LFS Pull failed: " + e.Message));
514+
_lastOperationSuccess = false;
515+
}
516+
}
517+
474518
//Once completed
475519
_inProgress = false;
476520
_cancellationPending = false;
@@ -486,5 +530,52 @@ public void OpenRepositoryDestination()
486530
});
487531
//Leave the process running. User should close it manually.
488532
}
533+
534+
public void InstallAndPullLFS(string path)
535+
{
536+
//Install lfs
537+
ProcessStartInfo installStartInfo = new ProcessStartInfo
538+
{
539+
FileName = "git-lfs",
540+
Arguments = "install",
541+
WorkingDirectory = path,
542+
UseShellExecute = false,
543+
WindowStyle = ProcessWindowStyle.Hidden,
544+
CreateNoWindow = true,
545+
RedirectStandardInput = true,
546+
RedirectStandardOutput = true,
547+
RedirectStandardError = true
548+
};
549+
550+
Process installProcess = new Process
551+
{
552+
StartInfo = installStartInfo
553+
};
554+
555+
installProcess.Start();
556+
installProcess.WaitForExit();
557+
558+
//Now pull lfs
559+
ProcessStartInfo pullStartInfo = new ProcessStartInfo
560+
{
561+
FileName = "git-lfs",
562+
Arguments = "pull",
563+
WorkingDirectory = path,
564+
UseShellExecute = false,
565+
WindowStyle = ProcessWindowStyle.Hidden,
566+
CreateNoWindow = true,
567+
RedirectStandardInput = true,
568+
RedirectStandardOutput = true,
569+
RedirectStandardError = true
570+
};
571+
572+
Process pullProcess = new Process
573+
{
574+
StartInfo = pullStartInfo
575+
};
576+
577+
pullProcess.Start();
578+
pullProcess.WaitForExit();
579+
}
489580
}
490581
}

0 commit comments

Comments
 (0)