Git.SemVersioning.Gradle icon indicating copy to clipboard operation
Git.SemVersioning.Gradle copied to clipboard

Proposal: Support monorepos

Open clintonpowell opened this issue 1 year ago • 1 comments

Maybe I'm missing something, but currently it seems there's no way to specify the subdirectory in a repository to determine changes from.

Something like a property that lets me pass parameters to the underlying git log => git log -- subdirectory/to/my-project.

Without this I'm unable to use it, as it picks up all conventional commits from the entire repo.

clintonpowell avatar Nov 21 '24 15:11 clintonpowell

Hi, I looked in to this a bit. There is some path filtering functionality in the JGit library that I use to access git commit. However when I apply this I don't get the expected result.

I experimented with modifying this method in GitProvider:

    private fun getCommit(commit: RevCommit, revWalk: RevWalk, filter: TreeRevFilter): Commit {
        return Commit(commit.fullMessage, commit.name, commit.commitTime, sequence {

            for (parent in commit.parents) {
                revWalk.parseHeaders(parent)
                yield(getCommit(parent, revWalk, filter))
            }
        }, commit.authorIdent.name, commit.authorIdent.emailAddress, commit.authorIdent.`when`, !filter.include(revWalk, commit))
    }

changing it like this:

revWalk.treeFilter = PathFilter.create(subdirectory)

...

    private fun getCommit(commit: RevCommit, revWalk: RevWalk): Commit {
    return Commit(
        message = commit.fullMessage,
        id = commit.name,
        timestamp = commit.commitTime,
        parents = sequence {
            for (parent in commit.parents) {
                // Use a separate RevWalk to check if the parent matches the filter
                RevWalk(revWalk.objectReader).use { parentWalk ->
                    parentWalk.markStart(parent)
                    parentWalk.treeFilter = revWalk.treeFilter

                    // Check if the parent matches the filter
                    if (parentWalk.iterator().hasNext()) {
                        parentWalk.parseHeaders(parent)
                        yield(getCommit(parent, parentWalk))
                    }
                }
            }
        },
        authorName = commit.authorIdent.name,
        authorEmail = commit.authorIdent.emailAddress,
        authorDate = commit.authorIdent.`when`
    )
}

Would you like to investigate this further?

jmongard avatar Nov 27 '24 09:11 jmongard

Just chiming in here to say that IMO this feature should not be limited to "monorepos" strictly. Actually, in pretty much any Gradle multi-project that publishes per-project artifacts, I believe it makes sense to have separate versioning per Git history of the directory that belongs to the respective subproject.

sschuberth avatar Sep 19 '25 13:09 sschuberth