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

[Feature]: Make git usage on /storage/emulated/0 possible. #3777

Closed
kartonrad opened this issue Jan 7, 2024 · 7 comments
Closed

[Feature]: Make git usage on /storage/emulated/0 possible. #3777

kartonrad opened this issue Jan 7, 2024 · 7 comments
Labels

Comments

@kartonrad
Copy link

Feature description

Currently, git usage on /storage/emulated/0 is not feasible, because of frequent corruption of object files.
The severity of the corruption varies randomly, but is always a big disruption in workflow

The only way to use git on shared storage right now is through tools like MGit, which cannot be automated and are annoying to use compared to succesful lucky-runs of termux git scripts.
This is all necessary if other apps (code editors, notes, gallery, etc.) are to access the repo's files.

Unfortunately, i'll have to be upfront about this, i don't know why this is the case, just that Moderators on r/termux (contributers?) seem to be aware of this limitation.

Maybe this is an inherent property of the storage interaction, however, i would love if there was some possibility to fix this, even for a substantial performance penalty - when using an alternative api for precision-access for example.

I have zero expertise on this field, so feel free to make a successor issue and close this one.
If you have an idea how to implement this but don't see it as a priority, feel free to point me to some starting points -
i can't promise anything myself but one day i might be willing to dig in and aquire the neccesary skills to work on it

Thank you for this amazing app!

Additional information

https://www.reddit.com/r/termux/comments/131y4rh/git_object_corrupt/
https://github.com/termux/termux-packages/issues

@sylirre
Copy link
Member

sylirre commented Jan 7, 2024

The whole issue with git is limitation of file system mounted at /storage/emulated. It doesn't support special files (e.g. symlinks), file attributes and other common features. I guess the problem with Git occurs because file locking just doesn't work on this file system.

This is not about bugs or feature lack in Git or Termux. We are not going to re-implement Git to match FS behavior either.

The Git provided in Termux is compiled from sources available at https://mirrors.kernel.org/pub/software/scm/git. That's a mirror of the official Git implementation: https://git-scm.com/download/linux.

Termux app itself doesn't have effect on how software is being executed inside. It is just a display.

This is all necessary if other apps (code editors, notes, gallery, etc.) are to access the repo's files.

Apps can access files in Termux home directory. You don't need root for that. This directory can be opened as storage volume like MicroSD or USB drive.

i don't know why this is the case, just that Moderators on r/termux (contributers?) seem to be aware of this limitation.

Moderators in /r/termux (Reddit) are Termux developers. No need to report same issue again and again.

Users have to be aware about these two things:

  • Android OS design flaws and bugs (yes, system bugs more frequent than expected) are not going to be fixed by Termux.
  • We don't implement custom versions of utilities. What we get from upstream is what you will get after pkg install.

@sylirre sylirre closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2024
@sylirre sylirre added the wontfix label Jan 7, 2024
@kartonrad
Copy link
Author

kartonrad commented Jan 7, 2024

Thank you so much for your reply, i don't think you realize how much it helped me

Reimplementing git, or reimplementing filesystem features, sounds like a terrible idea honestly.
That would be crazy talk coming from me, and i would never ask something like that of anyone.

I know WSL has some special jank way of emulating linux file system permissions in NTFS, but honestly, i think it caused more problems than it solved, and i think someting like that would only happen here if someone tried this out of their own genuine interest.

Thank you so much for pointing me to other ways to fix my problem - if apps can access termux home, all my problems are solved.

Anyway - i apologise for opening an issue here, maybe i should've found help somewhere else -
unfortunately nothing had turned up for my unenlightened search terms.

@twaik
Copy link
Member

twaik commented Jan 7, 2024

if apps can access termux home, all my problems are solved.

https://wiki.termux.com/wiki/Internal_and_external_storage

@kartonrad
Copy link
Author

Unfortunately, the app Obsidian, that i'm using, doesn't support access to the Termux home directory.

But i found a solution and i'll share it for future reference:

I moved the repository to termux storage, created a new branch:

git branch empty
git checkout empty

then deleted all files except the .git folder and made a commit
deletion is optional though, just to save space.

then, i ran

git worktree add ~/storage/shared/Documents/reponame master

This will make sure git object files stay on the termux file system, while reading and writing happens on shared storage.
This approach apparently works better with the empty branch then it does with a bare repository.

If all is as expected, i should have way faster pulls and pushes, as well as a way smaller chance of corruption.
I am really happy with this hack, and thank you two for your suggestions

@DovieW
Copy link

DovieW commented Oct 29, 2024

@kartonrad just wanted to say thank you for this brilliant solution. have you been using it for a while and can confirm that it works?

I've been trying to figure out a solution for my obsidian sync project for a while before finding your idea.
DovieW/obsidian-android-sync#7

@kartonrad
Copy link
Author

@DovieW In use on two Android Devices, never faced repository corruption ever again
It's a bit annoying to set up sometimes but it really does work

One thing:
Since the working tree is on the more unreliable medium, it can happen (in very rare cases) that a file doesn't get removed when you switch branches.
So you have a clean working tree, switch branch and suddenly there is one untracked file

But it happens so rarely that maybe i just imagined it xD Maybe i really did forget to delete that file after all
And the commits are still correct in any case.

@DovieW
Copy link

DovieW commented Nov 10, 2024

@kartonrad Thanks for the response. Great to hear it's working. I think it's working for me too. I think I noticed that Git is running faster too? I'm not sure.

Hopefully people don't switch branches often for Obsidian use. I definitely don't. I wonder what the use case would be. But I'll keep an eye out for that.

I added a script to the issue that I linked that sets it up after you've cloned it to the dir you want the repos in. Maybe you can use it. Just change the variables at the top.

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

No branches or pull requests

4 participants