termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.15k stars 3.02k forks source link

[Bug]: Git diff can not recognize git repository on /sdcard. #11782

Closed zixijian closed 2 years ago

zixijian commented 2 years ago

Problem description

When the git repository exists on the /sdcard using git diff will not recognize the repository, directory copy to termux's own space is normal.

git diff
warning: Not a git repository. Use --no-index to compare two paths outside a working tree

Other git command have similar issue:

git add .
fatal: detected dubious ownership in repository at '/storage/emulated/0/6'
To add an exception for this directory, call:

        git config --global --add safe.directory /storage/emulated/0/6

If you create a new repository and execute the above command, you can use git diff as normal.

What steps will reproduce the bug?

First authorize the /sdcard permissions, then copy a git repository to the /sdcard, and link this directory to termux, ln -s /sdcard/tt ~/tt && cd ~/tt, modify some file,input git diffwill not recognize the repository.

But,cp -r /sdcard/tt ~/tt && cd ~/tt,here use git diff will be normal.

What is the expected behavior?

Can not see git diff when the repository on the sdcard.

System information

git version 2.37.2

termux-info:

Termux Variables:
TERMUX_API_VERSION=0.50.1
TERMUX_APK_RELEASE=UNKNOWN
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP_PID=11639
TERMUX_IS_DEBUGGABLE_BUILD=1
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://mirrors.njupt.edu.cn/termux/apt/termux-main stable main
Updatable packages:
curl/stable 7.85.0 aarch64 [upgradable from: 7.84.0]
inetutils/stable 2.3-1 aarch64 [upgradable from: 2.3]
libcurl/stable 7.85.0 aarch64 [upgradable from: 7.84.0]
termux-tools version:
1.29.1
Android version:
12
Kernel build information:
Linux 9pro 4.19.113-perf-g78f5c0ec7eba #1 SMP PREEMPT Wed Jul 6 15:23:17 CST 2022 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
M2007J17C
2096779623 commented 2 years ago

Example:

$ cd ~
$ termux-setup-storage
$ ln -s storage/external-1/nwipe nwipe
$ cd nwipe
~/nwipe $ git config --global --add safe.directory /sdcard/nwipe
~/nwipe $ git add .                             
~/nwipe $ git diff --cached autogen.sh
diff --git a/autogen.sh b/autogen.sh
old mode 100755
new mode 100644
index da9a805..e2103fe
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-
+114514
 # Script to create all the required autoconf files

 aclocal
~/nwipe $

Are you using an external sdcard?

zixijian commented 2 years ago

git config --global --add safe.directory /storage/emulated/0/tt is worked. but git config --global --add safe.directory /sdcard/tt is not worked.

I also deployed a chroot container on my phone, where the git diff works without adding a safe directory.

Even if the problem can be solved in this way, but there is no corresponding prompt with use git diff, I do not think this is a good solution.

And i am not using an external sdcard。

2096779623 commented 2 years ago

The path to /storage/emulated/0 can be replaced with ~/storage/shared/ . The path to /sdcard/ can be replaced with ~/storage/external-1/ .

/sdcard/ will be linked to internal storage if no external sdcard is inserted.

So please use ~/storage/shared/ when without inserting external sdcard .

zixijian commented 2 years ago
ls -la ~/tt
lrwxrwxrwx 1 u0_a244 u0_a244     34 Dec 22  2020 tt -> storage/shared/Quark/Download/.t

ls -la tt/
total 1643
drwxrwx--- 8 root everybody    3488 Aug 31 23:28 .git
-rw-rw---- 1 root everybody      18 Aug 25 09:42 .gitignore
-rw-rw---- 1 root everybody    1656 Aug 25 09:42 Guide.md
-rw-rw---- 1 root everybody   11261 Aug 25 09:42 README.md
-rw-rw---- 1 root everybody    9132 Aug 25 09:42 Special.md
-rw-rw---- 1 root everybody  171523 Sep  1 12:15 Wiki.md
-rw-rw---- 1 root everybody    1858 Aug 25 09:42 act.tt
-rw-rw---- 1 root everybody    7229 Aug 25 09:42 ali.tt
drwxrwx--- 2 root everybody    3488 Aug 25 09:42 bot
-rw-rw---- 1 root everybody     924 Aug 25 09:42 colorpad.tt
-rw-rw---- 1 root everybody     832 Aug 25 09:42 config.tt
-rw-rw---- 1 root everybody   13130 Aug 25 09:42 emote.tt
-rw-rw---- 1 root everybody     349 Aug 25 09:42 example.tt
-rw-rw---- 1 root everybody   77181 Aug 25 23:31 goto.tt
-rw-rw---- 1 root everybody    1797 Aug 25 00:16 init.tt
-rw-rw---- 1 root everybody   10520 Aug 25 09:42 newbie.tin
-rw-rw---- 1 root everybody     102 Aug 25 09:42 pku.tt
drwxrwx--- 2 root everybody    3488 Aug 25 09:48 refer
-rw-rw---- 1 root everybody 1319185 Aug 25 09:42 rooms.tt
-rw-rw---- 1 root everybody    1904 Aug 25 09:42 ttm.tt

Termux already has read and write access to this directory, so why set up a safe directory? I don't think that's reasonable.

sylirre commented 2 years ago

Just don't store your git repository on /sdcard or other storage directories that are FAT32 (exFAT) or tend to emulate such file system. Such file systems have issues setting correct timestamps as well as Unix file permissions. As result, git is confused and doesn't work properly.

Store your repositories in $HOME of Termux instead. If need file editing using external application, consider using Storage Access Framework features. See the last section of https://wiki.termux.com/wiki/Internal_and_external_storage.

This is not a bug.

zixijian commented 2 years ago

Just don't store your git repository on /sdcard or other storage directories that are FAT32 (exFAT) or tend to emulate such file system. Such file systems have issues setting correct timestamps as well as Unix file permissions. As result, git is confused and doesn't work properly.

Store your repositories in $HOME of Termux instead. If need file editing using external application, consider using Storage Access Framework features. See the last section of https://wiki.termux.com/wiki/Internal_and_external_storage.

This is not a bug.

Thank you for your explanation.

I chose to place the git repository in /sdcard really because I needed an external editor. Even if you think it's not a bug, I still have two problem here. 1). my chroot container on my phone,deployed ubuntu 18,There are no exceptions to using git to manager /sdcard repository. 2).git prompts information that doesn't help users solve problems effectively. when we find a problem, all we have to do is solve it.