Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: shihanng/gig
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.5.0
Choose a base ref
...
head repository: shihanng/gig
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref

Commits on Dec 12, 2019

  1. Copy the full SHA
    f730ef4 View commit details
  2. Merge pull request #48 from shihanng/bug__debug

    Remove unnecessary debug message
    shihanng authored Dec 12, 2019
    Copy the full SHA
    99c2a05 View commit details

Commits on Dec 13, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    85c69e3 View commit details
  2. Copy the full SHA
    0828371 View commit details
  3. Merge pull request #49 from shihanng/issues-40__search

    Add search subcommand
    shihanng authored Dec 13, 2019
    Copy the full SHA
    6f0f241 View commit details

Commits on Dec 14, 2019

  1. feat(cmd): add autogen

    shihanng committed Dec 14, 2019
    Copy the full SHA
    e09878f View commit details
  2. Copy the full SHA
    9ed054f View commit details
  3. Copy the full SHA
    8b987b5 View commit details
  4. fix(doc): update README

    shihanng committed Dec 14, 2019
    Copy the full SHA
    22a4cb7 View commit details
  5. Merge pull request #50 from shihanng/issues-39__autogen

    Add autogen subcommand
    shihanng authored Dec 14, 2019
    Copy the full SHA
    2881945 View commit details

Commits on Dec 15, 2019

  1. Copy the full SHA
    4a0b9fa View commit details
  2. fix(doc): update README

    shihanng committed Dec 15, 2019
    Copy the full SHA
    a12dd83 View commit details
  3. Merge pull request #51 from shihanng/issues-22__brew

    Add brew install
    shihanng authored Dec 15, 2019
    Copy the full SHA
    411c43f View commit details

Commits on Jan 21, 2022

  1. repo: Use force checkout

    Close #53
    shihanng committed Jan 21, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b72411c View commit details
  2. Use github.com/go-git/go-git/v5

    Replacing gopkg.in/src-d/go-git.v4
    shihanng committed Jan 21, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c6bb059 View commit details
  3. Use goreleaser-action v2

    This solve issue
    
       Warning: Calling bottle :unneeded is deprecated! There is no replacement.
    shihanng committed Jan 21, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bf1809b View commit details
  4. Copy the full SHA
    798287a View commit details
  5. Use go 1.17

    shihanng committed Jan 21, 2022
    Copy the full SHA
    e774c3a View commit details
  6. List returns unique files

    shihanng committed Jan 21, 2022
    Copy the full SHA
    87d44e9 View commit details
  7. Fix integration tests

    - Update upstream API endpoint
    
    - Update golden files
    
    - Compare list using string to ease debugging
    shihanng committed Jan 21, 2022
    Copy the full SHA
    4f2ad4a View commit details
  8. Copy the full SHA
    e8e73fa View commit details
  9. Copy the full SHA
    f0f7897 View commit details
  10. Fix missing return error

    shihanng committed Jan 21, 2022
    Copy the full SHA
    936df7e View commit details
  11. Fix style linting errors

    shihanng committed Jan 21, 2022
    Copy the full SHA
    110d810 View commit details
  12. Copy the full SHA
    ba54cb3 View commit details
  13. Fix gosec linting errors

    shihanng committed Jan 21, 2022
    Copy the full SHA
    9146732 View commit details
  14. Fix style

    shihanng committed Jan 21, 2022
    Copy the full SHA
    a33a709 View commit details
  15. Use inline nolint for gosec

    shihanng committed Jan 21, 2022
    Copy the full SHA
    95cf16c View commit details
  16. Ignore lll

    shihanng committed Jan 21, 2022
    Copy the full SHA
    0ad993d View commit details
  17. Copy the full SHA
    a8f79a8 View commit details
  18. Move gochecknoglobals to inline ignore

    Remove scopelint config
    shihanng committed Jan 21, 2022
    Copy the full SHA
    12e7bcd View commit details
  19. Disable some linters

    shihanng committed Jan 21, 2022
    Copy the full SHA
    e422363 View commit details
  20. Copy the full SHA
    b367a93 View commit details
  21. Copy the full SHA
    5cabdea View commit details
  22. Merge pull request #54 from shihanng/fix-checkout-error

    Fix checkout error
    shihanng authored Jan 21, 2022
    Copy the full SHA
    588fe45 View commit details
  23. Fix goreleaser config error

    shihanng committed Jan 21, 2022
    Copy the full SHA
    0b2f030 View commit details
  24. Merge pull request #55 from shihanng/fix-goreleaser

    Fix goreleaser config error
    shihanng authored Jan 21, 2022
    Copy the full SHA
    6c48191 View commit details
  25. Bump Go version

    shihanng committed Jan 21, 2022
    Copy the full SHA
    52dadde View commit details
Binary file added .github/images/search.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
go-version: 1.17.x

- name: Check out code into the Go module directory
uses: actions/checkout@v1
@@ -36,6 +36,7 @@ jobs:
uses: actions/checkout@v1

- name: Set up golangci-lint
uses: "actions-contrib/golangci-lint@master"
uses: golangci/golangci-lint-action@v2
with:
args: "run -v"
args: "-v"
version: v1.43
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
go-version: 1.17.x
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
21 changes: 10 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -4,20 +4,19 @@ run:

linters:
enable-all: true
disable:
- exhaustivestruct
- gofumpt
- golint
- interfacer
- maligned
- paralleltest
- scopelint
- varnamelen
- wrapcheck

issues:
exclude-rules:
- path: _test\.go
linters:
- scopelint
text: Using the variable on range scope `(tc|tt)` in function literal

# For golden file
- path: (file|main)_test\.go
linters:
- gochecknoglobals
text: "`update` is a global variable"

# Usually we have table driven tests which make the test function too long.
- path: _test\.go
linters:
16 changes: 16 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -18,6 +18,22 @@ archives:
windows: Windows
amd64: x86_64

brews:
- tap:
owner: shihanng
name: homebrew-gig
commit_author:
name: "Shi Han NG"
email: shihanng@gmail.com
description: "gitignore file generator"
homepage: "https://github.com/shihanng/gig"
dependencies:
- fzf
install: |
bin.install Dir['gig']
test: |
system "#{bin}/gig"
checksum:
name_template: "checksums.txt"

65 changes: 40 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `gig` -- .*g*it*i*gnore *g*enerator
# `gig` -- .gitignore generator

[![](https://github.com/shihanng/gig/workflows/main/badge.svg?branch=develop)](https://github.com/shihanng/gig/actions?query=workflow%3Amain)
[![](https://github.com/shihanng/gig/workflows/release/badge.svg?branch=develop)](https://github.com/shihanng/gig/actions?query=workflow%3Arelease)
@@ -25,6 +25,12 @@ Therefore this tool is created to solve the two main problems above.

# Install

## [Homebrew (macOS)](https://github.com/shihanng/homebrew-gig)

```
brew install shihanng/gig/gig
```

## Binaries

The [release page contains](https://github.com/shihanng/gig/releases) binaries built
@@ -39,10 +45,12 @@ go get github.com/shihanng/gig

# Usage

Use the supported language as input arguments, e.g. `Go Elm`.
There are several ways you can generate the `.gitignore` file:

### Using the supported language as input arguments

```
gig gen Go Elm
$ gig gen Go Elm
### Elm ###
# elm-package generated files
@@ -52,37 +60,34 @@ repl-temp-*
### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
### Go Patch ###
/vendor/
/Godeps/
...
```

At the very first run the program will clone the templates repository <https://github.com/toptal/gitignore.git>
into `$XDG_CACHE_HOME/gig`.
This means that internet connection is not required after the first successful run.

For more information:
### Using the search functionality (depends on [fzf](https://github.com/junegunn/fzf))

```
$ gig search
```

![gig search demo](./.github/images/search.gif)

### Using the EXPERIMENTAL auto generate functionality

```
$ gig autogen
```

### For more information, see

```
gig --help
```

# Contributing
# Development

Found a bug or want to hack around? Clone the repository:

@@ -102,5 +107,15 @@ Where `test` run the tests that can be run locally.
`integ-test` run the tests that require internet access.
`lint` help you write better Go codes.

If you are adding new subcommand, we are using [cobra](https://github.com/spf13/cobra)
and managed the version with [tools.go](./tools.go) and [go.mod](./go.mod).
Add subcommand with [cobra](https://github.com/spf13/cobra)
(version managed in [tools.go](./tools.go) with [go.mod](./go.mod)):

```
$ cobra --config .cobra.yaml add <new subcommand>
```

Update golden file:

```
$ go test . -tags=integration -update
```
147 changes: 147 additions & 0 deletions cmd/autogen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
Copyright © 2019 Shi Han NG <shihanng@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"

"github.com/cockroachdb/errors"
"github.com/shihanng/gig/internal/file"
"github.com/spf13/cobra"
"github.com/src-d/enry/v2"
)

func newAutogenCmd(c *command) *cobra.Command {
return &cobra.Command{
Use: "autogen",
Short: "(EXPERIMENTAL) I'm Feeling Lucky",
Long: `(EXPERIMENTAL) Automatically generate .gitignore based on the content of the current directory.
This feature uses github.com/src-d/enry
(which is a port of GitHub's linguist library) to detect
the programming languages in the current working directory
and pass that to the gen command. Known limitation of this
feature is that it could not detect a framework.`,
RunE: c.autogenRunE,
}
}

// Heavily borrowed from:
// https://github.com/src-d/enry/blob/697929e1498cbdb7726a4d3bf4c48e706ee8c967/cmd/enry/main.go#L27
func (c *command) autogenRunE(cmd *cobra.Command, args []string) error { // nolint:cyclop
templates, err := file.List(c.templatePath())
if err != nil {
return err
}

supported := make(map[string]bool, len(templates))

for _, t := range templates {
supported[file.Canon(t)] = true
}

var found []string

errWalk := filepath.Walk(".", func(path string, f os.FileInfo, err error) error {
if err != nil {
return filepath.SkipDir
}

if !f.Mode().IsDir() && !f.Mode().IsRegular() {
return nil
}

if enry.IsVendor(path) ||
enry.IsDotFile(path) ||
enry.IsDocumentation(path) ||
enry.IsConfiguration(path) {
if f.IsDir() {
return filepath.SkipDir
}

return nil
}

if f.IsDir() {
return nil
}

//nolint:gomnd
content, err := readFile(path, 16*1024)
if err != nil {
return err
}

language := enry.GetLanguage(path, content)
if language == enry.OtherLanguage {
return nil
}

if supported[file.Canon(language)] {
found = append(found, language)
}

return nil
})

if errWalk != nil {
return errors.Wrap(err, "cmd: walking file")
}

return c.generateIgnoreFile(found)
}

func readFile(path string, limit int64) ([]byte, error) {
if limit <= 0 {
b, err := ioutil.ReadFile(path)

return b, errors.Wrap(err, "cmd: read file")
}

f, err := os.Open(path)
if err != nil {
return nil, errors.Wrap(err, "cmd: open file")
}

defer f.Close()

st, err := f.Stat()
if err != nil {
return nil, errors.Wrap(err, "cmd: get file stat")
}

size := st.Size()
if limit > 0 && size > limit {
size = limit
}

buf := bytes.NewBuffer(nil)
buf.Grow(int(size))

_, err = io.Copy(buf, io.LimitReader(f, limit))

return buf.Bytes(), errors.Wrap(err, "cmd: copy to buffer")
}
22 changes: 1 addition & 21 deletions cmd/gen.go
Original file line number Diff line number Diff line change
@@ -22,10 +22,6 @@ THE SOFTWARE.
package cmd

import (
"path/filepath"

"github.com/shihanng/gig/internal/file"
"github.com/shihanng/gig/internal/order"
"github.com/spf13/cobra"
)

@@ -44,21 +40,5 @@ https://github.com/toptal/gitignore.git into $XDG_CACHE_HOME/gig.`,
}

func (c *command) genRunE(cmd *cobra.Command, args []string) error {
items := args

orders, err := order.ReadOrder(filepath.Join(c.templatePath(), `order`))
if err != nil {
return err
}

items = file.Sort(items, orders)

wc, err := c.newWriteCloser()
if err != nil {
return err
}

defer wc.Close()

return file.Generate(wc, c.templatePath(), items...)
return c.generateIgnoreFile(args)
}
Loading