baur icon indicating copy to clipboard operation
baur copied to clipboard

git: use go-git instead of commandline tools

Open fho opened this issue 5 years ago • 1 comments

Instead of using the git commandline tools, use https://github.com/go-git/go-git. This way not external git binary will be required anymore to interact with git. It might also be a bit faster, then having to spawn an external tool

fho avatar Jul 02 '20 14:07 fho

As of now it is not possible to transition to go-git because of the following issues:

  • When using go-git to evaluate if files are untracked, it takes in our monorepo for one of the apps 1m42s to run baur ls inputs. With baur 2.0.0 it takes 0.5s. This is a blocker. There is a related open issue in go-git: https://github.com/go-git/go-git/issues/181

    func (r *Repository) WithoutUntrackedFiles(paths ...string) ([]string, error) {
    	wt, err := r.repo.Worktree()
    	if err != nil {
    		return nil, err
    	}   
    	status, err := wt.Status()
    	if err != nil {
    		return nil, fmt.Errorf("fetching worktree status failed: %w", err)
    	}    
    	res := make([]string, 0, len(paths))    
    	for _, p := range paths {
    		fmt.Printf("calling IsUntracked: %q\n", p)
    		if !status.IsUntracked(p) {
    			res = append(res, p)
    		}
    	}  
    	return res, nil
    }
    
  • According to https://github.com/go-git/go-git/issues/500 go-git does not handle nested .gitignore files correctly

  • Retrieving the repository status fails if the new git fsmonitor is used: https://github.com/go-git/go-git/issues/299

fho avatar Sep 12 '22 14:09 fho