36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
|
|
using System;
|
|
using System.IO;
|
|
using ln.build.commands;
|
|
using ln.http;
|
|
|
|
namespace ln.build.repositories
|
|
{
|
|
public abstract class GitRepositoryInterface : RepositoryInterface
|
|
{
|
|
string webHookName;
|
|
public override string WebHookName => webHookName;
|
|
|
|
public GitRepositoryInterface(string webHookName)
|
|
{
|
|
this.webHookName = webHookName;
|
|
}
|
|
|
|
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", job.RepositoryURL, 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");
|
|
}
|
|
|
|
}
|
|
} |