Skip to content

Commit

Permalink
feat: support path query parameter (sub-directory) even Unity 2019.2 …
Browse files Browse the repository at this point in the history
…or earlier

Detail information: https://forum.unity.com/threads/some-feedback-on-package-manager-git-support.743345/
  * path must be a relative path to the root of the repository.
  * path query parameter **must** be placed **before** the revision anchor. The reverse order will fail.
  * A package manifest (package.json) is expected in the specified path.
  * e.g. With Path query parameter: `https://github.com/user/repo.git?path=/example/folder`
  * e.g. With revision anchor and path query parameter: `https://github.com/user/repo.git?path=/example/folder#v1.2.3`
  • Loading branch information
mob-sakai committed Aug 28, 2020
1 parent b057892 commit fa365cc
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions Packages/com.coffee.git-dependency-resolver/Editor/PackageMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class PackageMeta
new Regex(
@"^(git\+)?" +
@"(?<url>[^#?]*)" +
@"(\?(?<query>[^#]*))?" +
@"(#(?<rev>.*))?",
k_RegOption);

Expand All @@ -29,13 +30,15 @@ internal class PackageMeta
internal SemVersion version { get; private set; }
public string rev { get; private set; }
public string url { get; private set; }
public string path { get; private set; }
public PackageMeta[] dependencies { get; private set; }

private PackageMeta()
{
name = "";
url = "";
rev = "";
path = "";
version = new SemVersion(0);
dependencies = new PackageMeta [0];
}
Expand Down Expand Up @@ -114,12 +117,15 @@ public static PackageMeta FromNameAndUrl(string name, string url)
// Get version from revision/branch/tag
package.SetVersion(package.rev);

package.ProcessUrlQuery(m.Groups["query"].Value);
return package;
}

public string GetPackagePath(string clonePath)
{
return clonePath;
return string.IsNullOrEmpty(path)
? clonePath
: (clonePath + "/" + path).Replace("//", "/");
}

private void SetVersion(string ver)
Expand All @@ -129,6 +135,28 @@ private void SetVersion(string ver)
version = v;
}

private void ProcessUrlQuery(string urlQuery)
{
// Process url query.
var queries = urlQuery.Split('&')
.Select(q => q.Split('='))
.Where(q => q.Length == 2)
.ToDictionary(q => q[0], q => q[1]);

// path query.
string value;
if (queries.TryGetValue("path", out value))
path = value.Trim('/');

// version query.
if (queries.TryGetValue("version", out value))
{
SemVersion v;
SemVersion.TryParse(value, out v);
version = v;
}
}

public IEnumerable<PackageMeta> GetAllDependencies()
{
return dependencies;
Expand All @@ -141,7 +169,7 @@ public string GetDirectoryName()

public override string ToString()
{
return string.Format("{0}@{1} ({2})", name, version, rev);
return string.Format("{0}@{1} ({2}) [{3}]", name, version, rev, path);
}
}
}

0 comments on commit fa365cc

Please sign in to comment.