New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add listCommits to public API #1742
Comments
Here is the original implementation with nodegit: |
Sorry, I have no idea, maybe @mojavelinux will know. If not you will need to read the code and figure it out on your own. The problem is that the main author that knows everything about the project left, and we're maintaining it. I'm the most active maintainer but I don't write much code myself and I'm not super familiar with the code base. I only want the code to not die. |
I see. So thanks for your effort. I didn't know the original author left. |
For now I have this solution, if someone is interested. /** Get commit OID list between fromHash and toHash not including fromHash.
* Returns the list in historical order (oldest commit first).
*/
async function getHashListFromHashToHash(fromHash, toHash, dir) {
const logs = (await git.log({ fs, dir, ref: toHash })).map(
commit => commit.oid
)
return logs.splice(logList.indexOf(fromHash)).reverse()
} Problem is that it retrieves the whole commit history of the branch. |
I've asked chatGPT it show invalid code but this is interesting: const { listCommits } = require('isomorphic-git')
async function traverseHistory(repo, fromRef, toRef) {
let commits = await listCommits({
fs: repo,
ref: fromRef,
depth: null,
})
const toRefCommits = await listCommits({
fs: repo,
ref: toRef,
depth: null,
})
const toRefSet = new Set(toRefCommits.map((commit) => commit.oid))
// Traverse commits in reverse chronological order
commits = commits.reverse()
for (const commit of commits) {
// If this commit is not in the history of the toRef, skip it
if (!toRefSet.has(commit.oid)) {
continue
}
// Do something with each commit, such as printing its message
console.log(commit.message)
}
} If you want to modify the code of This code completely doesn't make sense. but It would be great to have: function listCommits(dir, gitdir, from, to) {
} If you want to contribute that would be great. |
the last chatGPT output shows this: const { log } = require('isomorphic-git')
async function traverseHistory(repo, fromRef, toRef) {
const commits = await log({
fs: repo,
depth: null,
ref: `${fromRef}..${toRef}`,
merges: false,
})
// Traverse commits in reverse chronological order
commits.reverse()
for (const commit of commits) {
// Do something with each commit, such as printing its message
console.log(commit.message)
}
}
// Example usage
traverseHistory('/path/to/repo', 'master', 'main') But I'm not able to test this right now. If this doesn't work I would love to have this implemented and documented. Since this is the syntax that is used by canonical git. |
This may be a very important feature to make parse ref as a range. BTW: I need to make issues as "work needed". |
I think the only thing to do in the code is adding the incoming OID only to the |
Isomorphic-git already supports the
This isn't perfect since we are getting commits since a timestamp and not a hash, so if two commits have the same timespamp they will both be returned. Ideally the solution would be an extra argument to |
@araknast this was actually the first thing I tried, but the result was not as expected. |
Hmm, if there is a bug with the |
@araknast It works actually. I just made the same mistake as you. The commit timestamp is not I made the same mistake in a different context, so it would be good to mention it in the docs. The correct function would be async function commitsSince(fromHash, toHash, dir) {
const fromCommit = await git.readCommit({ fs, dir, oid: fromHash })
const since = new Date(fromCommit.commit.committer.timestamp * 1000)
return git.log({ fs, dir, ref: toHash, since })
} |
The result doesn't include the |
@henri-hulski do you want to update the docs? you have a fresh knowledge about this. |
Problem with above workaround is that it assumes that all commits between |
I'm in the process of switching repo-cooker from nodegit to isomorphic-git .
I'm stuck now when trying to list all commits between two commit OIDs for example between two releases.
The signature is
and it should return a list of OIDs between
fromHash
andtoHash
not includingfromHash
in historical order (oldest first).The
listCommitsAndTags
command seems to be a good solution for this task beside that I need only commits not tags.Any reason why the command is not public? Would it be possible to make it public maybe with a switch to return only commit hashes.
BTW
listObjects
seems also to be a quite useful command.Or do you only want to expose commands which are equivalents to git commands. In this case would this task be possible to do with
walk
orlog
commands?Thank you for this great library!
The text was updated successfully, but these errors were encountered: