chshersh / zbg

✨ Zero Bullshit Git
Mozilla Public License 2.0
187 stars 11 forks source link

Global `.gitignore` #26

Closed worm2fed closed 11 months ago

worm2fed commented 1 year ago

Seems like zbg do not take in account by global .gitignore file

.DS_Store
.vscode/
*.code-workspace

Take a look

❯ zbg status    
 added  .DS_Store                                   | Bin 0 -> 6148 bytes
 added  .github/.DS_Store                           | Bin 0 -> 6148 bytes
 added  .vscode/settings.json                       |   6 ■■■■■■
 added  .vscode/tasks.json                          |  50 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
 added  other/.DS_Store                             | Bin 0 -> 6148 bytes
 added  other/join-service/.vscode/settings.json    |   6 ■■■■■■
 added  src/.DS_Store                               | Bin 0 -> 6148 bytes
 added  src/Context/.DS_Store                       | Bin 0 -> 6148 bytes
 added  src/Context/Individual/.DS_Store            | Bin 0 -> 6148 bytes
 added  src/Context/Individual/Connection/.DS_Store | Bin 0 -> 6148 bytes
 added  src/Context/Individual/Domain/.DS_Store     | Bin 0 -> 6148 bytes
 added  src/Core/.DS_Store                          | Bin 0 -> 6148 bytes
 added  tests/.DS_Store                             | Bin 0 -> 6148 bytes
 added  union-server.code-workspace                 |  39 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

and

union-server on  master via 🐳 desktop-linux via λ lts-20.26 
❯ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
etorreborre commented 11 months ago

I have the same issue and it's not clear to me why the git invocation from the OCaml code does not use the global config.

chshersh commented 11 months ago

I think this has to do with environment variables. Is there one that controls where git should look for global .gitignore?

For example, if I run env, I can see lots of env variables in my setup:

$ env
SHELL=/bin/bash
WSL2_GUI_APPS_ENABLED=1
WSL_DISTRO_NAME=Ubuntu
NAME=ocaml-machine
PWD=/home/chshersh
LOGNAME=chshersh
MOTD_SHOWN=update-motd
HOME=/home/chshersh
LANG=C.UTF-8

Unfortunately, the environment is not passed automatically, so I'm passing relevant bits explicitly. Example here:

https://github.com/chshersh/zbg/blob/998403c52fb2083984404f90739cd18c26dd78be/lib/git.ml#L21-L27

Looks like I need to pass $HOME directory to more git commands 🤔

worm2fed commented 11 months ago

@chshersh global ignore is a param in a git config, so basically seems that you're right and root is the missing HOME variable.

chshersh commented 11 months ago

To do this properly a consistently, I imagine having a global function git that would take all git arguments as an input parameter and will get the home_dir before each invocation. After that, all calls to "git ..." should be replaced with the usages of this function.

Implementing this refactoring is not on my top priority list but I'm happy to review the PR if anyone gives it a try 🙂

etorreborre commented 11 months ago

@chshersh I was about to push a PR with what you proposed but I wonder what harm there would be in specifying HOME before each command executed via the Process module? Here is the corresponding PR: https://github.com/chshersh/zbg/pull/32.

I attempted the refactoring you mentioned at first but this command eventually made me think twice. Not a simple git call :-):

let is_rebase_in_progress () : bool =
  let git_dirs = Process.proc_stdout "ls `git rev-parse --git-dir`" in
  String.is_substring ~substring:"rebase" git_dirs
chshersh commented 11 months ago

@etorreborre I see. Indeed, it turned out to be not that trivial 😅 I'm okay with adding HOME before each command. I want to avoid seeing this HOME prefix in the CLI output. But for now, I don't see any harm in adding it before each command.

etorreborre commented 11 months ago

For reference here is the other branch I started with a git function. It was nice anyway to start writing my first OCaml lines of code :-).

chshersh commented 11 months ago

Resolved by #32

Thanks again, @etorreborre!

@worm2fed, give it a try, the latest version from the main branch should work 🙂

worm2fed commented 11 months ago

Now it's working! cool, thanks guys!