Closed AlexFicachi closed 2 years ago
Thanks very much for the bug report and sorry for the issue!
tldr; This is a simple git issue that CrowdAnki can't deal with atm, but that can be dealt with command-line git (or, if you prefer, any decent git GUI).
As (probably unnecessary) background: CrowdAnki (logically) uses* the same local git repo for import and for snapshotting (it's placed at the "Snapshot Path" (see Tools > Addons > CrowdAnki > Config > Snapshot Path
)) — i.e. when you do a git import, CrowdAnki pulls to that local git repo and when you do a snapshot, CrowdAnki commits to that local git repo.
* depending on configuration — I assume you have knowledge
as one of your snapshot root decks?
The issue (AFAICT) is that this local git repo now contains commits (on its main branch) that aren't in the remote. Embarrassingly, it seems that CrowdAnki doesn't even deal with a situation where the local git repo is simply ahead of the remote (i.e. remote/main
is an ancestor of local/main
), where it shouldn't do anything. (It also doesn't cope with a situation where remote/main
and local/main
are actually diverged — i.e. neither is an ancestor of the other — and the backtrace won't distinguish between the two situations.)
Navigate to the snapshot path (SNAPSHOT_PATH/PROFILE_NAME/knowledge
(where the SNAPSHOT_PATH
is as described above) in a terminal and check what precisely is the issue (whether local/main
is just ahead of remote/main
or whether they've diverged):
git log --graph main origin/main
If main
is simply ahead of origin/main
then just push the local changes to the remote (https://github.com/devaccelerator/knowledge).
If the two branches have diverged, then merge them (or rebase origin/main
on top of the local main
— depending on your personal git preferences), push that to the remote and then do a CrowdAnki git import.
(You could also use a git GUI.)
I hope that this works and helps! If it doesn't or something is unclear, please ask!
As mentioned above, there are two possible (related issues):
A. The local and remote branches have genuinely diverged (neither is an ancestor of the other). B. The local branch is ahead of the remote branch (remote is a direct ancestor of local).
Dealing with A properly will require turning CrowdAnki into a proper(-ish) git porcelain/front-end. However, dealing with B should be straightforward (do nothing — possibly just inform the user).
In other words, when CrowdAnki pulls from a git remote into an existing local/snapshot git repo, there are three possibilities:
remote
is ahead of local
.
In this case, CrowdAnki correctly updates local
to remote
.
local
is ahead of remote
Currently, CrowdAnki crashes.
IMO the "right thing" would be to leave local
alone (do nothing), and inform the user that local
is ahead of remote
.
For comparison git pull
in this situation just says "Already up-to-date". IMO we, unlike git
, should inform the user, in greater detail, since CrowdAnki does commits on the user's behalf when snapshotting, so they might not be aware what's happening.
Would a message like:
"Note that your local deck {deck} contains changes that aren't present in the remote git repository. Consider contributing them upstream (see https://github.com/Stvad/CrowdAnki/blob/master/README.md#how-to-collaborate-via-github for suggestions how)."
be sufficiently end-user friendly (for users who might not be familiar with git)?
local
and remote
have diverged
Currently, CrowdAnki crashes.
Ideally, we'd like to carry out some sort of automated merging, but doing this correctly will be tricky, so dealing with this is more of a long-term goal.
However, in the short term we could at least avoid crashes and provide a pointer to somewhere (a wiki page?) that would describe how the user could manually resolve the issue.
Thanks for the info! To provide more details about my specific situation, Anki was crashing on an Anki profile that did not have access to the remote repo I was importing from. So the git log --graph main origin/main
command didn't work for my situation. I ended up deleting the folder that contained the git branch for the deck I was trying to update and then I imported from the git repository again. It seemed to work after that since there was no branch it had to merge with, it just created a new one.
I'm unable to import the following git repo in more than one of my profiles: https://github.com/devaccelerator/knowledge.
I made a new profile and I was able to import it in that new profile without it crashing though.
Here is the error output from Anki:
Let me know if you need any more details or help from my end? Thanks! :)