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
Option to display version history from a Git repository, in addition to File Recovery and Obsidian Sync? #3
Comments
The obsidian git plugin has an option to list all changes, but I've never looked at what exactly it does. I suppose it doesn't work with the active file, but commits in general. Anything I could do would need to work with the obsidian git plugin alone, because any reliance on node would stop the plugin from working on mobile. It doesn't work properly on mobile right now because of CSS issues, but that's something that can be fixed. I feel that the obsidian git plugin is the right place to implement it. It already has everything it needs to work with git and could build on its own Diff view (which uses the same library for generating the html). |
cc @Vinzent03 |
@kometenstaub Thanks for the mention @00dani There is already a diff view. Just open the Source Control View via the command palette and double-click an unstaged file. |
Hmm, Obsidian Git does have a diff view, akin to However what this plugin does is different! It's actually closer to It's also kinda like |
What I need is an API that gets me all commit hashes for the chosen file, plus info like commit time. Then I can pass them to another api and let it return the diff. Getting just diffs isn't useful, because they only diff the former commit, but with my UI the user can choose the commits. If these APIs are made available by the git plugin, then I could add git compatibility. Before that, I'd need to do more refactoring though. |
@00dani Ah interesting. I didn't know this plugin before. @kometenstaub So you pass the file path to my method, and it returns you a list of all commits hashes with their commit time? How do you get the diff from the commit hash? You would need node modules, don't you? |
How you get the diffthis.plugin.gitManager.getDiffString(TFile.path)
async getDiffString(filePath: string): Promise<string> {
return (await this.git.diff([filePath]));
}
This is accessible already and will be useful for getting a comparison to the current state of the file compared to the latest commit, just like the recovery view does. simple-git APIhttps://github.com/steveukx/git-js#api
https://github.com/steveukx/git-js#git-log I'd need an API for
It accepts the path. I couldn't tell which data this method returns, but it would be great if it could return as much data as possible. If it could return an array with objects, that should work. interface commits { logReturn[] }
interface logReturn {
hash: string,
commitMessage: string,
time: string | Date | number/*, whatever works*/,
author: string
} I'd also need an API to access Show can be used like this to display the content at a certain commit: git show HASH:path/to/file.md As parameters it needs the path and the commit hash. I'd also need access to You use it already here https://github.com/denolehov/obsidian-git/blob/7cbff742b30d7a77cdc0e20c8b2fc385974d81fb/src/simpleGit.ts#L183 const diff = await this.git.diff([`${localCommit}..${upstreamCommit}`, '--name-only']); Instead of |
If you can provide these three APIs, then I should be able to integrate it into my plugin without breaking mobile compatibility for the other two views. |
Update: The refactoring is done. |
LogThere is now a method interface DefaultLogFields {
hash: string;
date: string;
message: string;
refs: string;
body: string;
author_name: string;
author_email: string;
} Simple git's api returns the count of commits and the latest commit too, but you can get these information by the list itself. Index 0 is the newest. An example for Showasync show(commitHash: string, file: string) {
return this.git.show([commitHash + ":" + file], (err) => this.onError(err));
} Diffasync diff(filePath: string, commit1: string, commit2: string): Promise<string> {
return (await this.git.diff([`${commit1}..${commit2}`, "--", filePath]));
} Example output:
Is that everything you need? It's not published/pushed yet. If you agree, I can release a new version. |
@Vinzent03 Yes, this should be everything I need. Thank you ❤️ |
Released a new version 🚀 |
Thank you, it is shipped! :) |
I don't see the command "Show Git diff history view for active file" on the iOS device. Is it normale? Reading this issue also on mobile, it should be available. P.S. I've the Git plugin enabled. |
As you mention in the README.md, the diffs produced from the File Recovery snapshots are often more helpful than the diffs produced from Obsidian Sync versions since they're less frequent. The same is true of Git commits to a larger extent, since a Git commit is only produced when the user intentionally makes one - the revision history is deliberately curated and annotated with descriptive messages, rather than automatically generated at set intervals.
Hence it'd be really nice to see diffs and history produced by asking Git how the active file has changed! This oddly enough isn't a feature of the existing Obsidian Git plugin, despite being a common operation that you can perform using Git integration in various text editors and IDEs.
I don't know how well it'll work on mobile, nor whether you'd need to rely on Obsidian Git being present, but it'd still be a really nice feature to have on desktop. 🐱
The text was updated successfully, but these errors were encountered: