Skip to content
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

How to publish a deck into anki? #173

Open
mshafer1 opened this issue Jul 14, 2024 · 23 comments
Open

How to publish a deck into anki? #173

mshafer1 opened this issue Jul 14, 2024 · 23 comments

Comments

@mshafer1
Copy link

Situation I'm trying to do:
Alice creates a collection and wants to share it (ki clone, then publish to GitHub)

Bob wants to pull in Alice's collection.

From what I've gathered so far...

Bob could need to :

  • do ki clone on existing collection
  • cd down into the cloned folder (e.g. ./anki_decks)
  • Add Alice's collection as a submodule git sugmodule add https://github.com/mshafer1/anki__ccna.git (or wherever Alice published)
  • ???

How does Bob then use ki to push this into Anki?

@mshafer1
Copy link
Author

(would this be better as a discussion? it looks like that GitHub feature is not turned on for this repo)

@langfield
Copy link
Owner

langfield commented Jul 14, 2024

Thanks for commenting :) No this is quite fine as an issue!

Okay so first things first: you should use the simplest workflow that will work for your use case. If all you want to do is use Alice's shared collection/deck, then just export it within Anki and then have Bob import it. Done.

You should only need to use Ki if both users plan to continuously push and pull from the collection and it is infeasible for them to use the same AnkiWeb account.

As for what Bob needs to do to track some kind of remote deck within his collection, perhaps this example is best to look at:

ki/tests/test_subdeck.sh

Lines 25 to 55 in eb32fbd

# Convert `aa` to a subdeck with remote `/tmp/subtree/github`
# and clone subdeck repo to `tmp/ki/aa`.
echo ""
cd /tmp/subtree/multideck
subdeck aa /tmp/subtree/github
git clone -b main /tmp/subtree/github /tmp/subtree/aa
# Check that cloned subdeck repo has a remote pointing to `/tmp/subtree/github` as well.
echo ""
cd /tmp/subtree/aa
git remote -v
# Commit in the root and push to subdeck.
echo ""
cd /tmp/subtree/multideck/aa
echo 'b' > b
git add b
git commit -m "Add b"
cd /tmp/subtree/multideck
git subtree push --prefix aa --annotate="(aa) " /tmp/subtree/github main
# Commit in the subdeck repo, push to remote, and pull into root.
cd /tmp/subtree/aa
echo 'c' > c
git add c
git commit -m "Add c"
git config pull.rebase false
git pull --no-edit
git push origin main
cd /tmp/subtree/multideck
git subtree pull -m "Merge branch 'main' of /tmp/subtree/github" --prefix aa /tmp/subtree/github main

This is a workflow to create a new remote subdeck on github or some other remote. If you already have one set up, then I believe instead of running subdeck, you want to instead just git subtree add the remote with some prefix. You can see an example of the usage of this command at the end of the subdeck script in the repo.

Then you can follow the example above for merging and pushing.

Apologies the docs are quite outdated and don't reflect this 😅

If you're using this seriously for a while I'll go in and update them at some point, but at the moment I don't have any users, so it's not a big priority.

@mshafer1
Copy link
Author

Ugh, GitHub didn't let me know there was a response.

Since we're in active study, I expect the deck(s) to grow, so Alice would be continuing to add more definitions/terms in, and Bob would want to have the updates synced in (running a manual command to do this is fine).

I had contemplated running an instance of https://hub.docker.com/r/matb/docker-anki-sync-server but I started getting the impression that ankiweb and anski-sync-server are intended for single use and not so much "Alice is publishing, Bob is pulling, anyone else can pull if they want"....

(very new to anki, just decided it was time for my study tools to be FOSS, so still figuring it all out)

So....,
with regular updates, and wanting to "publicize" the decks on GitHub (instead of sharing ankiweb credentials), I think the subtree makes the most sense.
I'll give that a test tonight and report back.

@langfield
Copy link
Owner

langfield commented Jul 31, 2024 via email

@mshafer1
Copy link
Author

mshafer1 commented Aug 1, 2024

I'm apparently very confused on how git subtrees is supposed to work...

I think I've deduced that I can't really work at a "sub-collection" level, and it needs to be individual decks. Ok.

After adding a bunch of quotes into params in the copy of subdeck I got through my pipx install (because I'm on Windows, and I have spaces in my deck names), I did

# setup a local repo to push into
mkdir /tmp/osi_model
pushd /tmp/osi_model/
git init --bare
popd

subdeck "Achronyms/" /tmp/osi_model -f

And tha seemed to work (or at least didn't error)
So then I ran:

subdeck "Achronyms/" https://github.com/mshafer1/anki__ccna__osi_model.git

Which pushed all the decks...
https://github.com/mshafer1/anki__ccna__osi_model.git

...

Looking at it, I see that "achronyms" is a subtree....

So then I made a new repo and manually copied/commited just the relevant files into it:
https://github.com/mshafer1/anki__ccna__achronyms

then in my "second profile" test repo
git subtree add -P ccna_achronyms https://github.com/mshafer1/anki__ccna__achronyms.git main

I wound up whiping the deck and running that from my first-profile as well to force it to be a subtree.

I then went into Anki and added a term, ...,
did a ki pull, saw the new term come into files, ...

... and... ccna_achronyms is no longer a subtree to push to the new file to GitHub :(

What exactly is subdeck tyring to accomplish? it looks like it takes the passed deck, sets it up as a repo, then pulls into original "collections" repo as a subtree?

@langfield
Copy link
Owner

langfield commented Aug 4, 2024

@mshafer1 Apologies for the late reply! You've picked up the workflow pretty well given the lamentable lack of documentation, I'm impressed 😄

I'm unsure what you mean by "sub-collection", but yes, you need to specify a deck. Of course it can be a top-level deck that includes your entire collection or any subset, so this should be sufficiently flexible for anyone's needs.

because I'm on Windows

Ah, that is a problem. I have quite explicitly dropped compatibility with Windows. However if you're using mkdir and popd, I assume perhaps you're using WSL? If so you may be good :) See #150

As for the deck not getting filtered properly, try running each command in the subdeck script individually. In particular the following line:

ki/subdeck

Line 12 in eb32fbd

git subtree split --prefix $subdeck --annotate="($subdeck) " --rejoin

Let me know what the output looks like, because it appears you've done most everything else correctly.


The subdeck script does the following:

  1. Clones your collection repository in a temporary location
  2. Splits the specified subdeck into a subtree (i.e. gets rid of everything but that deck)
  3. Pushes this subtree to the specified remote
  4. Removes the subdeck from the original repository
  5. Re-adds that deck as a subtree that tracks the remote

@mshafer1
Copy link
Author

mshafer1 commented Aug 6, 2024

Well, mkdir and pushd/popd are also available in cmd. I'm not certain whether I opened wsl when I saw it was a Bash script or Git Bash (I'm thinking the latter).

I didn't get a chance to test this last night, and tonight will be busy as well, but I'll plan to try it out tomorrow and report back.

@langfield
Copy link
Owner

Well, mkdir and pushd/popd are also available in cmd. I'm not certain whether I opened wsl when I saw it was a Bash script or Git Bash (I'm thinking the latter).

Ah my bad! Yes please let me know, @mshafer1! 🙂

@langfield
Copy link
Owner

langfield commented Aug 17, 2024

@mshafer1 Any luck?

@mshafer1
Copy link
Author

Been hectic here this last week. Hoping to work on this by Monday evening at the latest.

@mshafer1
Copy link
Author

doing a ki clone for a fresh look

>C:\Users\Admin\AppData\Roaming\Anki2\User 1\collection.anki2
>ki clone "C:\Users\Admin\AppData\Roaming\Anki2\User 1\collection.anki2"
Cloning into 'C:\Users\Admin\Documents\GitHub\ki_working_dir_2\collection_clone\collection'...
Notes: 100%|██████████████████████████████████| 25/25 [00:00<00:00, 1438.73it/s]
Media: 100%|██████████████████████████████████| 25/25 [00:00<00:00, 1060.17it/s]
Notes: 100%|███████████████████████████████████| 25/25 [00:00<00:00, 274.81it/s]
Notetypes: 100%|█████████████████████████████████| 6/6 [00:00<00:00, 333.37it/s]

>dir
 Volume in drive C has no label.
 Volume Serial Number is DA25-1622

 Directory of C:\Users\Admin\Documents\GitHub\ki_working_dir_2\collection_clone

08/19/2024  09:12 PM    <DIR>          .
08/19/2024  09:12 PM    <DIR>          ..
08/19/2024  09:12 PM    <DIR>          collection
               0 File(s)              0 bytes
               3 Dir(s)  49,741,271,040 bytes free

>cd collection

>dir
 Volume in drive C has no label.
 Volume Serial Number is DA25-1622

 Directory of C:\Users\Admin\Documents\GitHub\ki_working_dir_2\collection_clone\collection

08/19/2024  09:12 PM    <DIR>          .
08/19/2024  09:12 PM    <DIR>          ..
08/19/2024  09:12 PM                26 .gitattributes
08/19/2024  09:12 PM    <DIR>          .github
08/19/2024  09:12 PM                13 .gitignore
08/19/2024  09:12 PM    <DIR>          .ki
08/19/2024  09:12 PM    <DIR>          Achronyms
08/19/2024  09:12 PM    <DIR>          ccna_achronyms
08/19/2024  09:12 PM    <DIR>          Definitions
08/19/2024  09:12 PM            13,880 models.json
08/19/2024  09:12 PM    <DIR>          Network Topologies
08/19/2024  09:12 PM    <DIR>          Subnet Classes
08/19/2024  09:12 PM    <DIR>          WAN types
08/19/2024  09:12 PM    <DIR>          _media
               3 File(s)         13,919 bytes
              11 Dir(s)  49,740,804,096 bytes free

switch to Git Bash to run subdeck

# note, since I messed with the installed copy, I grabbed a source copy of subdeck 
# and only added a "set -o verbose" for echoing commands out

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_2/collection_clone/collection (main)
$ ls
 Achronyms/   Definitions/  'Network Topologies'/  'Subnet Classes'/  'WAN types'/   _media/   ccna_achronyms/   models.json


Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_2/collection_clone/collection (main)
$  subdeck-verbose Achronyms https://github.com/mshafer1/test-ki-achronyms2.git
set -e

subdeck=$(echo "$1" | sed 's,/*$,,')

remote=$2

root=$(git rev-parse --show-toplevel)


rm -rf /tmp/ki

mkdir -p /tmp/ki

cd /tmp/ki

git clone $root $subdeck
Cloning into 'Achronyms'...
done.

cd $subdeck

git subtree split --prefix $subdeck --annotate="($subdeck) " --rejoin
Added dir 'Achronyms'
4471d69c3f127900c4f6bb965b3f8a93290a7d2e

cd $(git rev-parse --show-toplevel)

git remote rm origin

git remote add origin $remote

mkdir -p .github/workflows

cp $root/.github/workflows/jekyll-gh-pages.yml.example .github/workflows/jekyll-gh-pages.yml

git add .github

git commit -m "Add github pages CI workflow"
[main e6a2b8f] Add github pages CI workflow
 1 file changed, 53 insertions(+)
 create mode 100644 .github/workflows/jekyll-gh-pages.yml

git push -u origin main
Enumerating objects: 49, done.
Counting objects: 100% (49/49), done.
Delta compression using up to 4 threads
Compressing objects: 100% (43/43), done.
Writing objects: 100% (49/49), 8.62 KiB | 551.00 KiB/s, done.
Total 49 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), done.
To https://github.com/mshafer1/test-ki-achronyms2.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

cd $root

git rm -r $subdeck

rm 'Achronyms/models.json'

git commit -m "Remove \`$subdeck\`"
[main d479776] Remove `Achronyms`
 1 file changed, 1 deletion(-)
 delete mode 100644 Achronyms/models.json

rm -rf $subdeck

echo "Just deleted prefix"
Just deleted prefix

git subtree add --prefix $subdeck $remote main

git fetch https://github.com/mshafer1/test-ki-achronyms2.git main
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 6 (delta 1), reused 5 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (6/6), 770 bytes | 15.00 KiB/s, done.
From https://github.com/mshafer1/test-ki-achronyms2
 * branch            main       -> FETCH_HEAD
Added dir 'Achronyms'
echo "commits for deck '$subdeck' pushed to '$remote'"
commits for deck 'Achronyms' pushed to 'https://github.com/mshafer1/test-ki-achronyms2.git'

@langfield
Copy link
Owner

@mshafer1 Well it looked like it ran without any issues. Are you still seeing any unexpected behavior?

@mshafer1
Copy link
Author

Maybe I'm not expecting correctly?

It cloned the full repo to the "dest', did I misunderstand that it was supposed to turn a folder into a sub-tree and push it?

@langfield
Copy link
Owner

langfield commented Aug 21, 2024 via email

@mshafer1
Copy link
Author

(setup with a completely fresh ki clone again)

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection (main)
$ subdeck-verbose Achronyms https://github.com/mshafer1/test-ki-achronyms3.git
set -e
subdeck=$(echo "$1" | sed 's,/*$,,')
remote=$2
root=$(git rev-parse --show-toplevel)

rm -rf /tmp/ki
mkdir -p /tmp/ki
cd /tmp/ki
git clone $root $subdeck
Cloning into 'Achronyms'...
done.
cd $subdeck
ls
 Achronyms   Definitions  'Network Topologies'  'Subnet Classes'  'WAN types'   ccna_achronyms   models.json   netmasks
git subtree split --prefix $subdeck --annotate="($subdeck) " --rejoin
Added dir 'Achronyms'
1c28a7bdda887ca436373e1bfc7a08af4409422f
ls
 Achronyms   Definitions  'Network Topologies'  'Subnet Classes'  'WAN types'   ccna_achronyms   models.json   netmasks
exit 0

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection (main)
$ ls -al
total 46
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  ./
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  ../
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  .git/
-rw-r--r-- 1 Admin 197121    26 Aug 24 07:59  .gitattributes
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  .github/
-rw-r--r-- 1 Admin 197121    13 Aug 24 07:59  .gitignore
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  .ki/
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  Achronyms/
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  Definitions/
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59 'Network Topologies'/
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59 'Subnet Classes'/
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59 'WAN types'/
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  _media/
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  ccna_achronyms/
-rw-r--r-- 1 Admin 197121 13880 Aug 24 07:59  models.json
drwxr-xr-x 1 Admin 197121     0 Aug 24 07:59  netmasks/

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection (main)
$ nano /c/Users/Admin/.local/bin/subdeck-verbose

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection (main)
$ cd Achronyms/

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection/Achronyms (main)
$ git status
On branch main
nothing to commit, working tree clean

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection/Achronyms (main)
$ git remote -v

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection/Achronyms (main)
$ cd ..

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection (main)
$ git log Achronyms/
commit 593258f499e91ae2b6b4fc9f335c3bea1fb47509 (HEAD -> main, tag: last-successful-ki-push)
Author: mshafer1 <[email protected]>
Date:   Sat Aug 24 07:59:04 2024 -0500

    Initial commit

Admin@Matthew-Laptop2 MINGW64 ~/Documents/GitHub/ki_working_dir_3/collection (main)
$ git log Definitions/
commit 593258f499e91ae2b6b4fc9f335c3bea1fb47509 (HEAD -> main, tag: last-successful-ki-push)
Author: mshafer1 <[email protected]>
Date:   Sat Aug 24 07:59:04 2024 -0500

    Initial commit

@mshafer1
Copy link
Author

Playing with this a little bit and reading the sub-tree man page...

Is it conceivable that this line: https://github.com/langfield/ki/blob/eb32fbd3229dc1a60bcc76a937ad63f3eb869f65/subdeck#L15C1-L15C30

should be doing a subtree push instead of a push??
like git subtree push --prefix="$subdeck" $remote main?

@mshafer1
Copy link
Author

Also confirmed that behavior is the same between Git Bash and WSL

@langfield
Copy link
Owner

langfield commented Aug 24, 2024 via email

@langfield
Copy link
Owner

langfield commented Aug 24, 2024 via email

@mshafer1
Copy link
Author

mshafer1 commented Aug 24, 2024

In the temp repo?

Admin@Matthew-Laptop2 MINGW64 /tmp/ki/Achronyms (main)
$ git branch -v
* main 685c646 Split 'Achronyms/' into commit '1c28a7bdda887ca436373e1bfc7a08af4409422f'

Relatedly, what is the Git version you have?

@langfield
Copy link
Owner

I haven't forgotten about this! Just a tad busy at the moment 😅

@langfield
Copy link
Owner

I looked into this today and I simply don't have the time to investigate a fix with the proper care. If indeed a modified command of the form git subtree push works for you, if you write a test for it and submit a PR I'd be happy to merge it :)

@langfield
Copy link
Owner

See also: https://stackoverflow.com/questions/42026669/how-to-push-to-git-subtree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants