34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
|
|
using System;
|
|
using System.IO;
|
|
using ln.build.commands;
|
|
using ln.http;
|
|
|
|
namespace ln.build.repositories
|
|
{
|
|
public abstract class GitRepository : Repository
|
|
{
|
|
public string CloneURL { get; }
|
|
public GitRepository(string cloneUrl)
|
|
{
|
|
CloneURL = cloneUrl;
|
|
}
|
|
|
|
public override void CloneSources(CIJob job)
|
|
{
|
|
job.Logger.Log("{0}: cloning repository to {1}", GetType().Name, job.WorkingDirectory);
|
|
job.Environment.WorkingDirectory = Path.GetTempPath();
|
|
|
|
bool success = new CommandRunner("git", "clone", CloneURL, job.WorkingDirectory).Run(job.Environment) == 0;
|
|
job.Environment.WorkingDirectory = job.WorkingDirectory;
|
|
|
|
if (success && job.ContainsVariable("COMMIT_ID"))
|
|
{
|
|
success = new CommandRunner("git", "checkout", job.GetVariable("COMMIT_ID")).Run(job.Environment) == 0;
|
|
}
|
|
if (!success)
|
|
throw new Exception("clone failed");
|
|
}
|
|
|
|
}
|
|
} |