-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite parts to be easier to read / understand / better structured and more obvious to make it easier to pick up randomly in the future
- Loading branch information
1 parent
520c675
commit cc3608e
Showing
47 changed files
with
1,365 additions
and
954 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
name: "Tests" | ||
on: ["push"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
ci: | ||
name: "Run CI" | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: ["ubuntu-latest", "macOS-latest"] | ||
go: ["1.23.x"] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 1 | ||
- uses: WillAbides/[email protected] | ||
with: | ||
fetch-depth: 2 | ||
- uses: actions/setup-go@v3 | ||
go-version: ${{ matrix.go }} | ||
- run: "go test ./..." | ||
- run: "go vet ./..." | ||
- uses: dominikh/staticcheck-action@v1 | ||
with: | ||
go-version: '1.20' | ||
- name: Run tests | ||
run: go test -v ./... | ||
version: "latest" | ||
install-go: false | ||
cache-key: ${{ matrix.go }} | ||
working-directory: ${{ matrix.dir }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,7 @@ | |
|
||
Learning Git Internals by writing a Git in Go. | ||
|
||
## CLI Usage | ||
|
||
See `go run ./cmd/gitg --help` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,84 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/richardjennings/g/git" | ||
"fmt" | ||
"github.com/richardjennings/g" | ||
"github.com/spf13/cobra" | ||
"log" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
var addCmd = &cobra.Command{ | ||
Use: "add <path> ...", | ||
Args: cobra.MinimumNArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := configure(); err != nil { | ||
log.Fatalln(err) | ||
return err | ||
} | ||
return git.Add(args...) | ||
return Add(args...) | ||
}, | ||
} | ||
|
||
// Add adds one or more file paths to the Index. | ||
func Add(paths ...string) error { | ||
idx, err := g.ReadIndex() | ||
if err != nil { | ||
return err | ||
} | ||
// get working directory files with idx status | ||
wdFiles, err := g.FsStatus(g.Path()) | ||
if err != nil { | ||
return err | ||
} | ||
var updates []*g.FileStatus | ||
for _, p := range paths { | ||
if p == "." { | ||
// special case meaning add everything | ||
for _, v := range wdFiles.Files() { | ||
switch v.WorkingDirectoryStatus() { | ||
case g.Untracked, g.WorktreeChangedSinceIndex, g.DeletedInWorktree: | ||
updates = append(updates, v) | ||
} | ||
} | ||
} else { | ||
found := false | ||
for _, v := range wdFiles.Files() { | ||
if v.Path() == p { | ||
switch v.WorkingDirectoryStatus() { | ||
case g.Untracked, g.WorktreeChangedSinceIndex, g.DeletedInWorktree: | ||
updates = append(updates, v) | ||
} | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
// try directory @todo more efficient implementation | ||
for _, v := range wdFiles.Files() { | ||
if strings.HasPrefix(v.Path(), p+string(filepath.Separator)) { | ||
switch v.WorkingDirectoryStatus() { | ||
case g.Untracked, g.WorktreeChangedSinceIndex, g.DeletedInWorktree: | ||
updates = append(updates, v) | ||
} | ||
found = true | ||
} | ||
} | ||
} | ||
|
||
if !found { | ||
return fmt.Errorf("fatal: pathspec '%s' did not match any files (directories not implemented yet)", p) | ||
} | ||
} | ||
} | ||
for _, v := range updates { | ||
if err := idx.Add(v); err != nil { | ||
return err | ||
} | ||
} | ||
// once all files are added to idx struct, write it out | ||
return idx.Write() | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(addCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/richardjennings/g/git" | ||
"github.com/richardjennings/g" | ||
"github.com/spf13/cobra" | ||
"log" | ||
) | ||
|
||
var initCmd = &cobra.Command{ | ||
Use: "init", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := configure(); err != nil { | ||
log.Fatalln(err) | ||
return err | ||
} | ||
return git.Init() | ||
return Init() | ||
}, | ||
} | ||
|
||
func Init() error { | ||
return g.Init() | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(initCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.