gitfs

package module
v0.0.0-...-71ce912 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 7 Imported by: 2

README

gitfs

A wrapper around go-git, compatible with the fs.FS and fs.StatFS from the standard library. package.

Usage

package main

import (
	"fmt"
	"github.com/magnuswahlstrand/gitfs"
	"io/fs"
	"log"
)

func main() {
	gitFS, err := gitfs.New("../local-repo")
	if err != nil {
		log.Fatalf("failed to setup repository: %s", err)
	}

	err = fs.WalkDir(gitFS, ".", func(path string, d fs.DirEntry, err error) error {
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(path)
		return nil
	})
	if err != nil {
		log.Fatalf("failed to walk dir: %s\n", err)
	}
}

Examples

See ./examples.

Basic (same as above)
go run ./examples/basic

Output:

.
.air.toml
.gitignore
LICENSE
README.md
examples
examples/basic
examples/basic/go.mod
examples/basic/go.sum
examples/basic/main.go
...

...
go.work
go.work.sum
Output markdown

Traverses a git repo and outputs the markdown in a nice way to the terminal.

go run ./examples/markdown-directory -repo https://github.com/magnuswahlstrand/til.git -path /src/pages/blog

Output:

img.png

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(URL string) (fs.StatFS, error)

Types

type FS

type FS struct {
	// contains filtered or unexported fields
}

FS wraps a git work tree. Compatible with fs.FS and fs.StatFS

func (*FS) Open

func (d *FS) Open(name string) (fs.File, error)

func (*FS) ReadDir

func (d *FS) ReadDir(name string) ([]fs.DirEntry, error)

func (*FS) Stat

func (d *FS) Stat(name string) (fs.FileInfo, error)

Directories

Path Synopsis
examples
basic Module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL