diff --git a/dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs b/dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs index 2b1d064f3..18959ff57 100644 --- a/dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs +++ b/dev/pyRevitLabs/pyRevitCLI/PyRevitCLI.cs @@ -278,7 +278,9 @@ private static void ProcessArguments() { else if (all("update")) PyRevitCLICloneCmds.UpdateClone( allClones: arguments["--all"].IsTrue, - cloneName: TryGetValue("") + cloneName: TryGetValue(""), + username: TryGetValue("--username"), + password: TryGetValue("--password") ); else @@ -432,7 +434,9 @@ private static void ProcessArguments() { else if (all("update")) PyRevitCLIExtensionCmds.UpdateExtension( all: arguments["--all"].IsTrue, - extName: TryGetValue("") + extName: TryGetValue(""), + username: TryGetValue("--username"), + password: TryGetValue("--password") ); else if (IsHelpMode) diff --git a/dev/pyRevitLabs/pyRevitCLI/PyRevitCLICloneCmds.cs b/dev/pyRevitLabs/pyRevitCLI/PyRevitCLICloneCmds.cs index 2da6b7fcc..4e9c7d928 100644 --- a/dev/pyRevitLabs/pyRevitCLI/PyRevitCLICloneCmds.cs +++ b/dev/pyRevitLabs/pyRevitCLI/PyRevitCLICloneCmds.cs @@ -229,7 +229,7 @@ internal static void } internal static void - UpdateClone(bool allClones, string cloneName) { + UpdateClone(bool allClones, string cloneName, string username, string password) { // TODO: ask for closing running Revits // prepare a list of clones to be updated @@ -260,7 +260,7 @@ internal static void // update clones that do not include this process foreach (var clone in targetClones) { logger.Debug("Updating clone \"{0}\"", clone.Name); - PyRevitClones.Update(clone); + PyRevitClones.Update(clone, username, password); } // now update myClone if any, as last step diff --git a/dev/pyRevitLabs/pyRevitCLI/PyRevitCLIExtensionCmds.cs b/dev/pyRevitLabs/pyRevitCLI/PyRevitCLIExtensionCmds.cs index 4f843250a..6f7aa7b07 100644 --- a/dev/pyRevitLabs/pyRevitCLI/PyRevitCLIExtensionCmds.cs +++ b/dev/pyRevitLabs/pyRevitCLI/PyRevitCLIExtensionCmds.cs @@ -209,11 +209,11 @@ internal static void } internal static void - UpdateExtension(bool all, string extName) { + UpdateExtension(bool all, string extName, string username, string password) { if (all) - PyRevitExtensions.UpdateAllInstalledExtensions(); + PyRevitExtensions.UpdateAllInstalledExtensions(username, password); else if (extName != null) - PyRevitExtensions.UpdateExtension(extName); + PyRevitExtensions.UpdateExtension(extName, username, password); } } } diff --git a/dev/pyRevitLabs/pyRevitCLI/Resources/UsagePatterns.txt b/dev/pyRevitLabs/pyRevitCLI/Resources/UsagePatterns.txt index e27f4c2e0..6d500c34e 100644 --- a/dev/pyRevitLabs/pyRevitCLI/Resources/UsagePatterns.txt +++ b/dev/pyRevitLabs/pyRevitCLI/Resources/UsagePatterns.txt @@ -20,7 +20,7 @@ Usage: pyrevit clones commit [] [--log=] pyrevit clones origin --reset [--log=] pyrevit clones origin [] [--log=] - pyrevit clones update (--all | ) [--log=] + pyrevit clones update (--all | ) [--log=] [--username=] [--password=] pyrevit clones deployments pyrevit clones engines pyrevit attach --help @@ -49,7 +49,7 @@ Usage: pyrevit extensions sources [--help] pyrevit extensions sources forget --all [--log=] pyrevit extensions sources (add | forget) [--log=] - pyrevit extensions update (--all | ) [--log=] + pyrevit extensions update (--all | ) [--log=] [--username=] [--password=] pyrevit releases --help pyrevit releases [--pre] [--notes] pyrevit releases latest [--pre] [--notes] diff --git a/dev/pyRevitLabs/pyRevitLabs.Common/GitInstaller.cs b/dev/pyRevitLabs/pyRevitLabs.Common/GitInstaller.cs index 036d9058d..3c3e3939a 100644 --- a/dev/pyRevitLabs/pyRevitLabs.Common/GitInstaller.cs +++ b/dev/pyRevitLabs/pyRevitLabs.Common/GitInstaller.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - +using System.Web.UI.WebControls.Adapters; using LibGit2Sharp; using pyRevitLabs.NLog; @@ -106,12 +106,19 @@ public static void CheckoutBranch(string repoPath, string branchName) { // rebase current branch and pull from master // @handled @logs - public static UpdateStatus ForcedUpdate(string repoPath) { + public static UpdateStatus ForcedUpdate(string repoPath, string username, string password) { logger.Debug("Force updating repo \"{0}\"...", repoPath); try { var repo = new Repository(repoPath); var options = new PullOptions(); - options.FetchOptions = new FetchOptions(); + var fetchOpts = new FetchOptions(); + + // add username and password to clone options, if provided by user + if (username != null && password != null) + fetchOpts.CredentialsProvider = + (_url, _usernameFromUrl, _credTypes) => new UsernamePasswordCredentials { Username = username, Password = password }; + + options.FetchOptions = fetchOpts; // before updating, let's first // forced checkout to overwrite possible local changes @@ -233,10 +240,12 @@ public static string GetCheckedoutBranch(string repoPath) { // get the checkedout branch from repopath // @handled @logs public static string GetHeadCommit(string repoPath) { + string head = null; if (IsValidRepo(repoPath)) - return new Repository(repoPath).Head.Tip.Id.ToString(); - logger.Debug("Can not determine head commit hash for \"{0}\"", repoPath); - return null; + head = new Repository(repoPath).Head?.Tip?.Id.ToString(); + if (head is null) + logger.Debug("Can not determine head commit hash for \"{0}\"", repoPath); + return head; } // get the checkedout branch from repopath diff --git a/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClone.cs b/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClone.cs index a2d3c74bf..58d2de2b4 100644 --- a/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClone.cs +++ b/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClone.cs @@ -17,6 +17,10 @@ public struct PyRevitCloneFromImageArgs { public string Url; public string BranchName; public string DeploymentName; + + public override string ToString() { + return string.Format("Url: \"{0}\" | Branch: \"{1}\" | Deployment: \"{2}\"", Url, BranchName, DeploymentName); + } } public class PyRevitClone { @@ -111,7 +115,7 @@ public string Branch { public string Commit => GetCommit(ClonePath); - public string ShortCommit => Commit.GetHashShort(); + public string ShortCommit => Commit?.GetHashShort(); public string Origin => GetOrigin(ClonePath); @@ -459,7 +463,8 @@ private static PyRevitCloneFromImageArgs ReadDeploymentArgs(string clonePath) { BranchName = contents[1] == string.Empty ? PyRevitLabsConsts.TragetBranch : contents[1], DeploymentName = contents[2] == string.Empty ? null : contents[2] }; - + logger.Debug(args); + return args; } catch (Exception ex) { diff --git a/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClones.cs b/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClones.cs index 68b136c3d..4fec1705a 100644 --- a/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClones.cs +++ b/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitClones.cs @@ -360,7 +360,7 @@ public static void DeployFromImage(string cloneName, // record image deployment settings try { - RecordDeploymentArgs(cloneName, deploymentName, branchName, imagePath, destPath); + RecordDeploymentArgs(cloneName, deploymentName, branchName, imageSource, destPath); } catch (Exception ex) { logger.Debug(string.Format("Exception occured after clone from image complete. " + @@ -484,14 +484,16 @@ private static void RecordDeploymentArgs(string cloneName, } } - private static void ReDeployClone(PyRevitClone clone) { + private static void ReDeployClone(PyRevitClone clone, string username = null, string password = null) { // grab clone arguments from inside of clone var cloneName = clone.Name; var clonePath = clone.ClonePath; var cloneDeployArgs = clone.DeploymentArgs; + logger.Debug("Clone Name=\"{0}\", Path=\"{1}\" Args=> {2}", cloneName, clonePath, cloneDeployArgs); + // delete existing clone Delete(clone); - + // re-deploy DeployFromImage( cloneName: cloneName, @@ -527,26 +529,26 @@ public static void DeleteAllClones(bool clearConfigs = false) { // force update given or all registered clones // @handled @logs - public static void Update(PyRevitClone clone) { + public static void Update(PyRevitClone clone, string username = null, string password = null) { // current user config logger.Debug("Updating pyRevit clone \"{0}\"", clone.Name); if (clone.IsRepoDeploy) { - var res = GitInstaller.ForcedUpdate(clone.ClonePath); + var res = GitInstaller.ForcedUpdate(clone.ClonePath, username, password); if (res <= UpdateStatus.Conflicts) throw new PyRevitException(string.Format("Error updating clone \"{0}\"", clone.Name)); } else { // re-deploying is how the no-git clones get updated - ReDeployClone(clone); + ReDeployClone(clone, username, password); } } // force update given or all registered clones // @handled @logs - public static void UpdateAllClones() { + public static void UpdateAllClones(string username = null, string password = null) { logger.Debug("Updating all pyRevit clones"); foreach (var clone in GetRegisteredClones()) - Update(clone); + Update(clone, username, password); } // updates the config value for registered clones diff --git a/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitExtensions.cs b/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitExtensions.cs index fe19df972..806e306a5 100644 --- a/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitExtensions.cs +++ b/dev/pyRevitLabs/pyRevitLabs.PyRevit/PyRevitExtensions.cs @@ -252,28 +252,28 @@ public static void UninstallExtension(string extensionName, bool removeSearchPat // force update extension // @handled @logs - public static void UpdateExtension(PyRevitExtension ext) { + public static void UpdateExtension(PyRevitExtension ext, string username = null, string password = null) { logger.Debug("Updating extension \"{0}\"", ext.Name); logger.Debug("Updating extension repo at \"{0}\"", ext.InstallPath); - var res = GitInstaller.ForcedUpdate(ext.InstallPath); + var res = GitInstaller.ForcedUpdate(ext.InstallPath, username, password); if (res <= UpdateStatus.Conflicts) throw new PyRevitException( string.Format("Error updating extension \"{0}\" installed at \"{1}\"", ext.Name, ext.InstallPath) ); } - public static void UpdateExtension(string extName) { + public static void UpdateExtension(string extName, string username = null, string password = null) { var ext = GetInstalledExtension(extName); - UpdateExtension(ext); + UpdateExtension(ext, username, password); } // force update all extensions // @handled @logs - public static void UpdateAllInstalledExtensions() { + public static void UpdateAllInstalledExtensions(string username = null, string password = null) { logger.Debug("Updating all installed extensions."); // update all installed extensions foreach (var ext in GetInstalledExtensions()) - UpdateExtension(ext); + UpdateExtension(ext, username, password); } // enable extension in config diff --git a/release/.pyrevitargs b/release/.pyrevitargs index 2bcfa0add..ef1392d9f 100644 --- a/release/.pyrevitargs +++ b/release/.pyrevitargs @@ -1,3 +1,3 @@ - +https://github.com/eirannejad/pyRevit/archive/master.zip master basepublic \ No newline at end of file