~kornellapacz/gmnigit

9cdc82885cf4286f621f8cb7f26c45aa4e513ad6 — Korneliusz Ɓapacz 3 years ago 56adc53
specify url by command line argument
3 files changed, 7 insertions(+), 16 deletions(-)

M README.md
M files.go
M main.go
M README.md => README.md +2 -7
@@ 26,13 26,8 @@ Usage of gmnigit:
        show files permissions in browsable tree (default false)
  -repo string
        path to repository
```

### Specifying url for cloning (optional)

In root of bare git repository put file called `url` with url for cloning, for example
```
echo "https://git.sr.ht/~kornellapacz/gmnigit" > url
  -url string
       clone URL for end user (optional)
```

## Tips

M files.go => files.go +2 -9
@@ 113,18 113,11 @@ func createBrowsableTree() {
}

func createIndexFile() {
	// check if in bare repository is `url` file with git url for cloning
	url, err := os.ReadFile(filepath.Join(repositoryPath, "url"))

	if err != nil && !os.IsNotExist(err) {
		log.Fatal(err)
	}

	indexFile, err := os.Create(filepath.Join(distPath, "index.gmi"))
	check(err)

	if url != nil {
		indexFile.WriteString("```\ngit clone " + strings.TrimSpace(string(url)) + "\n```\n\n")
	if cloneURL != "" {
		indexFile.WriteString("```\ngit clone " + strings.TrimSpace(cloneURL) + "\n```\n\n")
	}

	indexFile.WriteString("=> " + commitsSubPath + "/\n")

M main.go => main.go +3 -0
@@ 19,12 19,15 @@ const (
var (
	repositoryPath  string
	distPath        string
	cloneURL        string
	showPermissions bool
)

func main() {
	flag.StringVar(&repositoryPath, "repo", "", "path to repository")
	flag.StringVar(&distPath, "dist", "", "destination path (if exists will be overwritten)")

	flag.StringVar(&cloneURL, "url", "", "clone URL for end user (optional)")
	flag.BoolVar(&showPermissions, "perms", false, "show files permissions in browsable tree")

	flag.Parse()