Skip to content

Commit

Permalink
added info about branches in --logcommit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Duda committed Jul 15, 2024
1 parent 4e4f1dc commit c1b9e43
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/Commands/runLogCommitCommand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RelevancyManager } from "../Relevancy/RelevancyManager";
import { GitRepository } from "../Git/GitRepository";
import { Utils } from "../Scope/Utils";
import { GitDeltaType } from "../Git/Types";
import { RelevancyManager } from "../Relevancy/RelevancyManager";
import { FileTagsDatabase } from "../Scope/FileTagsDatabase";
import { Utils } from "../Scope/Utils";

export function runLogCommitCommand(args: Array<string>, root: string) {
// Logs files associated with a commit
Expand All @@ -22,9 +22,11 @@ export function runLogCommitCommand(args: Array<string>, root: string) {

const commitHasRelevancy = relevancyTagger.doesCommitMessageHaveRelevancyData(commit.message());

console.log(`Commit summary: '${commit.summary()}`);
console.log(`Relevancy info?: '${commitHasRelevancy ? "yes" : "no"}`);
const branches = await repository.branchesContainingCommit(commit);

console.log(`Commit summary: ${commit.summary()}`);
console.log(`Relevancy info?: '${commitHasRelevancy ? "yes" : "no"}`);
console.log(`Branches: ${branches.join(', ')}`);

if (commitHasRelevancy) {
const relevancyMap = relevancyTagger.loadRelevancyMapFromCommits([commit]);
Expand Down Expand Up @@ -57,7 +59,7 @@ export function runLogCommitCommand(args: Array<string>, root: string) {
console.log("File is IGNORED by scope database.");
}
else {
console.log("Not in NOT in scope database.");
console.log("Not found in scope database.");
}
}
printLineBreak();
Expand Down
35 changes: 34 additions & 1 deletion src/Git/GitRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execSync } from "child_process";
import { Commit, Note, Oid, Repository, Revwalk, Signature } from "nodegit";
import { Commit, Graph, Note, Oid, Repository, Revwalk, Signature } from "nodegit";
import path from "path";
import { RelevancyMap } from "../Relevancy/Relevancy";
import { RelevancyManager } from "../Relevancy/RelevancyManager";
Expand Down Expand Up @@ -418,6 +418,39 @@ export class GitRepository {
return false;
}

public async branchesContainingCommit(commit: Commit): Promise<string[]> {

// Open the repository
const repo = await this._getRepository();

// Get all references (branches)
const references = await repo.getReferences();

const branchesContainingCommit = [];

for (const ref of references) {
const branchCommit = await repo.getBranchCommit(ref);

// Check if the commit is in the branch history


// for branch_name in self._repository.listall_branches(self._flag):
// if self._commit is None or self.get(branch_name) is not None:
// yield branch_name
if(branchCommit.sha() === commit.sha()) {
branchesContainingCommit.push(ref.shorthand());
continue;
}

const isDescendant = await Graph.descendantOf(repo, branchCommit.id(), commit.id());
if (isDescendant) {
branchesContainingCommit.push(ref.shorthand());
}
}

return branchesContainingCommit;
}

private async _getRepository(): Promise<Repository> {
if (this._repository === null) {
try {
Expand Down
18 changes: 9 additions & 9 deletions src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env node
import { runCommitCommand } from "./Commands/runCommitCommand";
import { runAddCommand } from "./Commands/runAddCommand";
import { runVerifyCommand } from "./Commands/runVerifyCommand";
import { runVerifyUnpushedCommitsCommand } from "./Commands/runVerifyUnpushedCommitsCommand";
import { runReportForCommitCommand } from "./Commands/runReportForCommitCommand";
import { runReportForCommitListCommand } from "./Commands/runReportForCommitListCommand";
import { runCommitCommand } from "./Commands/runCommitCommand";
import { runFindReferencesCommand } from "./Commands/runFindReferencesCommand";
import { runHelpCommand } from "./Commands/runHelpCommand";
import { runStartCommandLineInterfaceCommand } from "./Commands/runStartCommandLineInterfaceCommand";
import { runTagCommitCommand } from "./Commands/runTagCommand";
import { getGitProjectRoot } from "./Git/Project";
import { runSkipVerificationForCommits } from "./Commands/runSkipVerificationAndPushCommand";
import { runLogCommitCommand } from "./Commands/runLogCommitCommand";
import { runReportForCommitCommand } from "./Commands/runReportForCommitCommand";
import { runReportForCommitListCommand } from "./Commands/runReportForCommitListCommand";
import { runSeeCommand } from "./Commands/runSeeCommand";
import { runSkipVerificationForCommits } from "./Commands/runSkipVerificationAndPushCommand";
import { runStartCommandLineInterfaceCommand } from "./Commands/runStartCommandLineInterfaceCommand";
import { runTagCommitCommand } from "./Commands/runTagCommand";
import { runUntagCommand } from "./Commands/runUntagCommand";
import { runVerifyCommand } from "./Commands/runVerifyCommand";
import { runVerifyUnpushedCommitsCommand } from "./Commands/runVerifyUnpushedCommitsCommand";
import { getGitProjectRoot } from "./Git/Project";

// Will be needed to get output from script
const [, , ...args] = process.argv;
Expand Down

0 comments on commit c1b9e43

Please sign in to comment.