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

Commit

Permalink
Merge pull request #7 from RenderHeads/master
Browse files Browse the repository at this point in the history
Credentials, LFS, Full reimport, -7 error fix, misc fixes.
  • Loading branch information
rossborchers authored Mar 8, 2020
2 parents 69ba917 + a69da20 commit c8c4b06
Show file tree
Hide file tree
Showing 18 changed files with 522 additions and 72 deletions.
Binary file modified Assets/Package/Lib/GitRepositoryManager.dll
Binary file not shown.
52 changes: 2 additions & 50 deletions Assets/Package/Lib/GitRepositoryManager.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 30 additions & 14 deletions Assets/Package/RepoManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using UnityEditor;
using UnityEditor.AnimatedValues;
using UnityEditor.Callbacks;
using UnityEngine;

namespace GitRepositoryManager
Expand Down Expand Up @@ -37,6 +38,8 @@ private class DependencyInfo
private bool showWarningMessage;
private bool lastFrameWasWaitingToShowWarning;

private const string FULL_RE_IMPORT_KEY = "RepositoryManager.FullReImport";

private HashSet<RepoPanel> _reposWereBusy = new HashSet<RepoPanel>();
private HashSet<RepoPanel> _reposBusy = new HashSet<RepoPanel>();

Expand Down Expand Up @@ -106,7 +109,10 @@ private void UpdateDependencies(List<Dependency> updatedDependencies = null)
RepoPanel panel = new RepoPanel(_repoPath, dependency, GetPlatformAuthentication());
panel.OnRemovalRequested += OnPanelRemovalRequested;
panel.OnDeleteAssetsRequested += DeleteAssets;
panel.OnCopyFinished += UpdateAssetDatabaseForNewAssets;
panel.OnCopyFinished += (assets, updatedRepos) =>
{
UpdateAssetDatabaseForNewAssets(assets, EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true), updatedRepos);
};
_repoPanels.Add(panel);
}
}
Expand Down Expand Up @@ -153,26 +159,33 @@ private void DeleteAssets(List<string> toDelete)
//Debug.Log("Evaluating next directory " + parentDir.FullName);
}
}

}
}

private void UpdateAssetDatabaseForNewAssets(List<string> coppiedAssets, params RepoPanel[] updatedRepos)
private void UpdateAssetDatabaseForNewAssets(List<string> coppiedAssets, bool fullReImport, params RepoPanel[] updatedRepos)
{
//Update all assets individually to avoid a full editor re-import
for (int i = 0; i < coppiedAssets.Count; i++)
if (fullReImport)
{
string extension = Path.GetExtension(coppiedAssets[i]);
if (extension == ".meta")
EditorUtility.DisplayProgressBar("Importing Repositories", "Performing full re-import" + GUIUtility.GetLoadingDots(), (float)EditorApplication.timeSinceStartup % 1);
AssetDatabase.Refresh();
}
else
{
//Update all assets individually to avoid a full editor re-import
for (int i = 0; i < coppiedAssets.Count; i++)
{
//dont import meta files directly.
continue;
}
string extension = Path.GetExtension(coppiedAssets[i]);
if (extension == ".meta")
{
//dont import meta files directly.
continue;
}

string assetDBPath = GetAssetDatabasePathFromFullPath(coppiedAssets[i]);
string assetDBPath = GetAssetDatabasePathFromFullPath(coppiedAssets[i]);

EditorUtility.DisplayProgressBar("Importing Repositories", "Importing repositories into project. Please wait a moment" + GUIUtility.GetLoadingDots(), ((float)i) / coppiedAssets.Count);
AssetDatabase.ImportAsset(assetDBPath, ImportAssetOptions.ForceSynchronousImport);
EditorUtility.DisplayProgressBar("Importing Repositories", "Importing repositories into project. Please wait a moment" + GUIUtility.GetLoadingDots(), ((float)i) / coppiedAssets.Count);
AssetDatabase.ImportAsset(assetDBPath, ImportAssetOptions.ForceSynchronousImport);
}
}

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

if(coppiedAssets.Count > 0)
{
UpdateAssetDatabaseForNewAssets(coppiedAssets, updatedRepos.ToArray());
UpdateAssetDatabaseForNewAssets(coppiedAssets, EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true), updatedRepos.ToArray());
}

if (repaint)
Expand All @@ -308,6 +321,9 @@ private ICredentialManager GetPlatformAuthentication()

private void OnGUI()
{
bool reImport = EditorGUILayout.Toggle("Full Re-Import", EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true));
EditorPrefs.SetBool(FULL_RE_IMPORT_KEY, reImport);

Rect labelRect = EditorGUILayout.GetControlRect();
labelRect.y += labelRect.height / 2f;

Expand Down
8 changes: 8 additions & 0 deletions Assets/Repositories/ContentEngine.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

107 changes: 99 additions & 8 deletions Plugin/Src/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ List<string> DirectoryCopy(string sourceDirName, string destDirName, string[] fo
}
}


public void CopyBackChanges()
{
//Swapped from forward copy. Other logic can stay the same.
Expand Down Expand Up @@ -298,6 +297,7 @@ void DirectoryCopy(string sourceDirName, string destDirName)
}
}
}

public void CancelUpdate()
{
if(_inProgress) _cancellationPending = true;
Expand All @@ -324,7 +324,6 @@ public bool LastOperationSuccess
}
}


public bool CancellationPending
{
get
Expand Down Expand Up @@ -380,13 +379,13 @@ private void UpdateTask(object stateInfo)

FetchOptions fetchOptions = new FetchOptions()
{
TagFetchMode = TagFetchMode.All,
/*TagFetchMode = TagFetchMode.All,
OnTransferProgress = new LibGit2Sharp.Handlers.TransferProgressHandler((progress) =>
{
_progressQueue.Enqueue(new Progress(((float)progress.ReceivedObjects) / progress.TotalObjects, "Fetching " + progress.ReceivedObjects + "/" + progress.TotalObjects + "(" + progress.ReceivedBytes + " bytes )"));
return _cancellationPending;
}),
}),*/
CredentialsProvider = (credsUrl, user, supportedCredentials) =>
{
state.CredentialManager.GetCredentials(credsUrl, user, supportedCredentials, out var credentials, out string message);
Expand All @@ -401,10 +400,10 @@ private void UpdateTask(object stateInfo)
//Repo exists we are doing a pull
using (var repo = new LibGit2Sharp.Repository(state.LocalDestination))
{
_progressQueue.Enqueue(new Progress(0, "Nuking local changes. Checking out " + state.Branch));
//_progressQueue.Enqueue(new Progress(0, "Nuking local changes. Checking out " + state.Branch));

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

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

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

try
{
Expand All @@ -428,6 +427,37 @@ private void UpdateTask(object stateInfo)
_progressQueue.Enqueue(new Progress(0, "Pull failed: " + e.Message));
_lastOperationSuccess = false;
}

/*try
{
var remote = repo.Network.Remotes["origin"];
var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
_progressQueue.Enqueue(new Progress(0, "Fetching from " + remote.Name));
Commands.Fetch(repo, remote.Name, refSpecs, fetchOptions, "");
_progressQueue.Enqueue(new Progress(1, "Complete"));
try
{
Branch branch = repo.Branches["origin/" + state.Branch];
var signature = new Signature(new Identity("RepositoryManager", "[email protected]"), DateTimeOffset.Now);
repo.Merge(branch, signature);
_lastOperationSuccess = true;
}
catch (Exception e)
{
_progressQueue.Enqueue(new Progress(0, "Merge failed: " + e.Message));
_lastOperationSuccess = false;
}
}
catch (Exception e)
{
_progressQueue.Enqueue(new Progress(0, "Fetch failed: " + e.Message));
_lastOperationSuccess = false;
}*/
}
}
else
Expand Down Expand Up @@ -471,6 +501,20 @@ private void UpdateTask(object stateInfo)
}
}

if(LastOperationSuccess)
{
_progressQueue.Enqueue(new Progress(1, "Downloading LFS files"));
try
{
InstallAndPullLFS(state.LocalDestination);
}
catch(Exception e)
{
_progressQueue.Enqueue(new Progress(0, "LFS Pull failed: " + e.Message));
_lastOperationSuccess = false;
}
}

//Once completed
_inProgress = false;
_cancellationPending = false;
Expand All @@ -486,5 +530,52 @@ public void OpenRepositoryDestination()
});
//Leave the process running. User should close it manually.
}

public void InstallAndPullLFS(string path)
{
//Install lfs
ProcessStartInfo installStartInfo = new ProcessStartInfo
{
FileName = "git-lfs",
Arguments = "install",
WorkingDirectory = path,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

Process installProcess = new Process
{
StartInfo = installStartInfo
};

installProcess.Start();
installProcess.WaitForExit();

//Now pull lfs
ProcessStartInfo pullStartInfo = new ProcessStartInfo
{
FileName = "git-lfs",
Arguments = "pull",
WorkingDirectory = path,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};

Process pullProcess = new Process
{
StartInfo = pullStartInfo
};

pullProcess.Start();
pullProcess.WaitForExit();
}
}
}
Loading

0 comments on commit c8c4b06

Please sign in to comment.