Skip to content

Commit

Permalink
feat!: mobile support
Browse files Browse the repository at this point in the history
close #57
  • Loading branch information
Vinzent03 committed Sep 5, 2022
1 parent 9dc5f7c commit 9ffda76
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 31 deletions.
10 changes: 2 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,10 @@ body:
- Windows
- Linux
- macOS
- Android
- iOS
validations:
required: true
- type: dropdown
id: plugin
attributes:
label: Plugin variant
description: Which plugin are you using?
options:
- Obsidian Git
- Obsidian Git Mobile
validations:
required: true
- type: input
Expand Down
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
# Obsidian Git
Simple plugin that allows you to back up your [Obsidian.md](https://obsidian.md) vault to a remote git repository (e.g. private repo on GitHub).
This plugin assumes credentials are set up.
Simple plugin that allows you to back up your [Obsidian.md](https://obsidian.md) vault to a remote Git repository (e.g. private repo on GitHub).

On advantages of backing up your vault with git I suggest reading this [amazing article](https://medium.com/analytics-vidhya/how-i-put-my-mind-under-version-control-24caea37b8a5) by [@tallguyjenks](https://github.com/tallguyjenks).

## Mobile support
# ⚠ Mobile

For mobile usage please install the [Obsidian Git Mobile](https://github.com/Vinzent03/obsidian-git-mobile#readme) plugin instead.
## Restrictions of the mobile version

### Installation
I am using [isomorphic-git](https://isomorphic-git.org/), which is a re-implementation of git in JavaScript, because you cannot use native git on Android or iOS.

- SSH authentication is not supported ([isomorphic-git issue](https://github.com/isomorphic-git/isomorphic-git/issues/231))
- Repo size is limited, because of memory restrictions
- Rebase merge strategy is not supported
- Submodules are not supported

## Performance on **Mobile**
**Setup:** iPad Pro M1 with a [repo](https://github.com/Vinzent03/obsidian-git-stress-test) of 3000 files reduced from [10000 markdown files](https://github.com/Zettelkasten-Method/10000-markdown-files)

The only really time consuming part is to check the whole working directory for file changes. So checking all files for changes to stage takes 03:40 min. Other commands like pull, push and commit are very fast (1-5 seconds). So the best way is to stage individual directories in which you have worked and commit only staged files after it.
The initial clone took 00:25 min.

### Installation on Desktop

⚠ Installing Obsidian via Snap on Linux is not supported. Please use AppImage or Flatpak instead ([Linux installation guide](https://github.com/denolehov/obsidian-git/wiki/Installation#linux))

See the [installation guide](https://github.com/denolehov/obsidian-git/wiki/Installation) for further instructions.


<details>
<summary>Installation and clone a repo on Mobile</summary>

1. Create new vault
2. Change config directory in Settings -> About
3. Install Obsidian Git plugin from community plugins
5. If cloning private repo, set password/personal access token and username in Settings -> Obsidian Git Mobile
6. Execute clone repo command
7. Reload plugin
</details>
<br>

# Desktop

### Documentation

Requirements, tips and tricks, common issues and more can be found in the [wiki](https://github.com/denolehov/obsidian-git/wiki/)
Expand Down
12 changes: 4 additions & 8 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,26 @@ import process from "process";
const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source visit the plugins github repository (https://github.com/phibr0/obsidian-dictionary)
if you want to view the source visit the plugins github repository (https://github.com/denolehov/obsidian-git)
*/
`;

const prod = (process.argv[2] === 'production');
const allowSimpleGit = (process.argv[3] === "true");

esbuild.build({
banner: {
js: banner,
},
entryPoints: ['src/main.ts'],
bundle: true,
external: ['obsidian', 'electron'],
external: ['obsidian', 'electron','child_process','fs','path'],
format: 'cjs',
watch: !prod,
target: 'es2016',
logLevel: "info",
define: {
ALLOWSIMPLEGIT: allowSimpleGit,
},
sourcemap: prod ? false : 'inline',
treeShaking: true,
platform: (allowSimpleGit || !prod) ? 'node' : 'browser',
platform: 'browser',
plugins: [
sveltePlugin({
compileOptions: {
Expand All @@ -39,6 +35,6 @@ esbuild.build({
preprocess: autoPreprocess(),
}),
],
inject: (allowSimpleGit || !prod) ? [] : ["polyfill_buffer.js"],
inject: ["polyfill_buffer.js"],
outfile: 'main.js',
}).catch(() => process.exit(1));
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
"description": "Backup your Obsidian (https://obsidian.md) vault with git",
"main": "main.js",
"scripts": {
"devnode": "node esbuild.config.mjs dev true",
"devbrowser": "node esbuild.config.mjs dev false",
"buildnode": "node esbuild.config.mjs production true",
"buildbrowser": "node esbuild.config.mjs production false",
"dev": "node esbuild.config.mjs dev",
"build": "node esbuild.config.mjs production",
"release": "standard-version"
},
"keywords": [],
Expand Down
10 changes: 9 additions & 1 deletion polyfill_buffer.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export const Buffer = require('buffer/').Buffer
import { Platform } from 'obsidian';
let buffer;
if (Platform.isMobileApp) {
buffer = require('buffer/index.js').Buffer
} else {
buffer = global.Buffer
}

export const Buffer = buffer;
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce, Debouncer, EventRef, Menu, normalizePath, Notice, Plugin, TAbstractFile, TFile } from "obsidian";
import { debounce, Debouncer, EventRef, Menu, normalizePath, Notice, Platform, Plugin, TAbstractFile, TFile } from "obsidian";
import { PromiseQueue } from "src/promiseQueue";
import { ObsidianGitSettingsTab } from "src/settings";
import { StatusBar } from "src/statusBar";
Expand Down Expand Up @@ -436,7 +436,7 @@ export default class ObsidianGit extends Plugin {

async init(): Promise<void> {
try {
if (ALLOWSIMPLEGIT) {
if (Platform.isDesktopApp) {
this.gitManager = new SimpleGit(this);
await (this.gitManager as SimpleGit).setGitInstance();

Expand Down
3 changes: 0 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export interface Status {
conflicted: string[];
}

declare global {
var ALLOWSIMPLEGIT: boolean;
}

/**
* `index` and `working_dir` are each one-character codes, based off the git
Expand Down

0 comments on commit 9ffda76

Please sign in to comment.