6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 14:31:49 +00:00

Merge pull request #31 from grdl/issue-30-windows-installation

Fix Windows installation problems
This commit is contained in:
Greg Dlugoszewski
2025-08-24 13:36:20 +02:00
committed by GitHub
9 changed files with 56 additions and 106 deletions

View File

@@ -61,14 +61,7 @@ checksum:
name_template: 'checksums.txt'
changelog:
sort: asc
use: github
filters:
exclude:
- '^docs:'
- '^test:'
- '^chore'
- typo
disable: true # Changelogs are crafted manually
release:
github:
@@ -110,17 +103,18 @@ nfpms:
formats:
- deb
- rpm
scripts:
postinstall: "release/scripts/postinstall.sh"
preremove: "release/scripts/preremove.sh"
contents:
- src: /usr/local/bin/git-get
dst: /usr/local/bin/git-list
type: "symlink"
scoops:
- name: git-get
repository:
owner: grdl
name: git-get
name: homebrew-tap
branch: master
directory: release/bucket
directory: Scoop
url_template: "https://github.com/grdl/git-get/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: Grzegorz Dlugoszewski
@@ -130,5 +124,9 @@ scoops:
description: "Better way to clone, organize and manage multiple git repositories"
license: MIT
post_install: [
"New-Item -ItemType HardLink -Path \"$dir\\git-list.exe\" -Target \"$dir\\git-get.exe\" -Force | Out-Null"
"New-Item -ItemType HardLink -Path \"$dir\\git-list.exe\" -Target \"$dir\\git-get.exe\" -Force | Out-Null",
"scoop shim add git-list \"$dir\\git-list.exe\""
],
post_uninstall: [
"scoop shim rm git-list"
]

View File

@@ -113,7 +113,7 @@ brew install grdl/tap/git-get
**Option 1: Scoop (Recommended)**
```powershell
scoop bucket add grdl https://github.com/grdl/git-get
scoop bucket add grdl https://github.com/grdl/homebrew-tap
scoop install git-get
```
*This automatically creates both `git-get.exe` and `git-list.exe` commands.*

1
go.mod
View File

@@ -3,7 +3,6 @@ module git-get
go 1.24
require (
github.com/karrick/godirwalk v1.17.0
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1
github.com/stretchr/testify v1.10.0

2
go.sum
View File

@@ -12,8 +12,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/karrick/godirwalk v1.17.0 h1:b4kY7nqDdioR/6qnbHQyDvmA17u5G1cZ6J+CZXwSWoI=
github.com/karrick/godirwalk v1.17.0/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=

View File

@@ -1,26 +1,19 @@
package git
import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
"syscall"
"github.com/karrick/godirwalk"
)
// Max number of concurrently running status loading workers.
const maxWorkers = 100
// errSkipNode is used as an error indicating that .git directory has been found.
// It's handled by ErrorsCallback to tell the WalkCallback to skip this dir.
var errSkipNode = errors.New(".git directory found, skipping this node")
var errDirNoAccess = errors.New("directory can't be accessed")
var errDirNotExist = errors.New("directory doesn't exist")
var errDirNoAccess = fmt.Errorf("directory can't be accessed")
var errDirNotExist = fmt.Errorf("directory doesn't exist")
// Exists returns true if a directory exists. If it doesn't or the directory can't be accessed it returns an error.
func Exists(path string) (bool, error) {
@@ -30,10 +23,8 @@ func Exists(path string) (bool, error) {
return true, nil
}
if err != nil {
if os.IsNotExist(err) {
return false, fmt.Errorf("can't access %s: %w", path, errDirNotExist)
}
if os.IsNotExist(err) {
return false, fmt.Errorf("can't access %s: %w", path, errDirNotExist)
}
// Directory exists but can't be accessed
@@ -60,19 +51,43 @@ func NewRepoFinder(root string) *RepoFinder {
// Returns error if root repo path can't be found or accessed.
func (f *RepoFinder) Find() error {
if _, err := Exists(f.root); err != nil {
return err
return fmt.Errorf("failed to access root path: %w", err)
}
walkOpts := &godirwalk.Options{
ErrorCallback: f.errorCb,
Callback: f.walkCb,
// Use Unsorted to improve speed because repos will be processed by goroutines in a random order anyway.
Unsorted: true,
}
err := filepath.WalkDir(f.root, func(path string, d fs.DirEntry, err error) error {
// Handle walk errors
if err != nil {
// Skip permission errors but continue walking
if os.IsPermission(err) {
return nil // Skip this path but continue
}
return fmt.Errorf("failed to walk %s: %w", path, err)
}
// Only process directories
if !d.IsDir() {
return nil
}
// Case 1: We're looking at a .git directory itself
if d.Name() == dotgit {
parentPath := filepath.Dir(path)
f.addIfOk(parentPath)
return fs.SkipDir // Skip the .git directory contents
}
// Case 2: Check if this directory contains a .git subdirectory
gitPath := filepath.Join(path, dotgit)
if _, err := os.Stat(gitPath); err == nil {
f.addIfOk(path)
return fs.SkipDir // Skip this directory's contents since it's a repo
}
return nil // Continue walking
})
err := godirwalk.Walk(f.root, walkOpts)
if err != nil {
return err
return fmt.Errorf("failed to walk directory tree: %w", err)
}
if len(f.repos) == 0 {
@@ -131,41 +146,12 @@ func statusWorker(fetch bool, reposChan <-chan *Repo, statusChan chan<- *Status)
}
}
func (f *RepoFinder) walkCb(path string, ent *godirwalk.Dirent) error {
// Do not traverse .git directories
if ent.IsDir() && ent.Name() == dotgit {
f.addIfOk(path)
return errSkipNode
}
// Do not traverse directories containing a .git directory
if ent.IsDir() {
_, err := os.Stat(filepath.Join(path, dotgit))
if err == nil {
f.addIfOk(path)
return errSkipNode
}
}
return nil
}
// addIfOk adds the found repo to the repos slice if it can be opened.
func (f *RepoFinder) addIfOk(path string) {
// TODO: is the case below really correct? What if there's a race condition and the dir becomes unaccessible between finding it and opening?
// Open() should never return an error here. If a finder found a .git inside this dir, it means it could open and access it.
// If the dir was unaccessible, then it would have been skipped by the check in errorCb().
repo, err := Open(strings.TrimSuffix(path, dotgit))
// Open() should never return an error here since we already verified the .git directory exists.
// The path should already be the repository root (not the .git subdirectory).
repo, err := Open(path)
if err == nil {
f.repos = append(f.repos, repo)
}
}
func (f *RepoFinder) errorCb(_ string, err error) godirwalk.ErrorAction {
// Skip .git directory and directories we don't have permissions to access
// TODO: Will syscall.EACCES work on windows?
if errors.Is(err, errSkipNode) || errors.Is(err, syscall.EACCES) {
return godirwalk.SkipNode
}
return godirwalk.Halt
}

View File

@@ -6,7 +6,7 @@ import (
"fmt"
"os"
"os/exec"
pathpkg "path"
"path/filepath"
"strings"
)
@@ -45,7 +45,7 @@ func (c *Cmd) OnRepo(path string) *Cmd {
return c
}
insert := []string{"--work-tree", path, "--git-dir", pathpkg.Join(path, ".git")}
insert := []string{"--work-tree", path, "--git-dir", filepath.Join(path, ".git")}
// Insert into the args slice after the 1st element (https://github.com/golang/go/wiki/SliceTricks#insert)
c.cmd.Args = append(c.cmd.Args[:1], append(insert, c.cmd.Args[1:]...)...)

View File

@@ -1,25 +0,0 @@
{
"version": "0.6.0",
"architecture": {
"64bit": {
"url": "https://github.com/grdl/git-get/releases/download/v0.6.0/git-get_0.6.0_windows_amd64vv1.zip",
"bin": [
"git-get.exe"
],
"hash": "77370170adbf2021047b0b9bc363b5f19b308a6d28382c5fc92d333509470926"
},
"arm64": {
"url": "https://github.com/grdl/git-get/releases/download/v0.6.0/git-get_0.6.0_windows_arm64.zip",
"bin": [
"git-get.exe"
],
"hash": "3900843203ec27e4b7d4a859e1b0b5c474661bbfd98ee8586d8e3744cb8a8d55"
}
},
"homepage": "https://github.com/grdl/git-get",
"license": "MIT",
"description": "Better way to clone, organize and manage multiple git repositories",
"post_install": [
"New-Item -ItemType HardLink -Path \"$dir\\git-list.exe\" -Target \"$dir\\git-get.exe\" -Force | Out-Null"
]
}

View File

@@ -1,3 +0,0 @@
#!/bin/sh
# Create symlink for git-list command
ln -sf /usr/local/bin/git-get /usr/local/bin/git-list

View File

@@ -1,3 +0,0 @@
#!/bin/sh
# Remove symlink for git-list command
rm -f /usr/local/bin/git-list