@maiden stone thank you for your answer.
I currently have this:
@func()
async gitCurrentCommit(@argument({ defaultPath: "/.git" }) gitRoot: Directory): Promise<string> {
const cleanContainer = dag.container()
.from("alpine:latest")
.withRun("apk update")
.withRun("apk add --no-cache zsh curl git bash")
.withDirectory("/mnt/.git", gitRoot)
.withWorkdir("/mnt")
.withRun("git config --global --add safe.directory /mnt")
.withRun("git checkout -f");
return cleanContainer.withExec(["git", "rev-parse", "HEAD"]).stdout();
}
I do not like this solution at all.
Can you show me how I can use nodegit from withing a dagger function like this but without cloning the repo from within dagger: the git repo is given as an argument to the function.
In the following example from nodegit, how would I get the "tmp" folder ?
// Open the repository directory.
Git.Repository.open("tmp")
// Open the master branch.
.then(function(repo) {
return repo.getMasterCommit();
})
// Display information about commits on master.
.then(function(firstCommitOnMaster) {
// Create a new history event emitter.
var history = firstCommitOnMaster.history();
// Create a counter to only show up to 9 entries.
var count = 0;
// Listen for commit events from the history.
history.on("commit", function(commit) {
// Disregard commits past 9.
if (++count >= 9) {
return;
}
// Show the commit sha.
console.log("commit " + commit.sha());
// Store the author object.
var author = commit.author();
// Display author information.
console.log("Author:\t" + author.name() + " <" + author.email() + ">");
// Show the commit date.
console.log("Date:\t" + commit.date());
// Give some space and show the message.
console.log("\n " + commit.message());
});
// Start emitting events.
history.start();
});