-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt auto-generated files being hidden by default #421
Changes from 1 commit
7284255
ddfcece
948203b
3844daa
e31661d
0f82fb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ui/bindata.go linguist-generated=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -693,7 +693,7 @@ var ContentFor = function(line, regexp) { | |
|
||
var FileContentView = React.createClass({ | ||
getInitialState: function() { | ||
return { open: true }; | ||
return { open: !this.props.isAutoGenerated }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be nice to put an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea, will do! |
||
}, | ||
toggleContent: function() { | ||
this.state.open ? this.closeContent(): this.openContent(); | ||
|
@@ -763,7 +763,8 @@ var FilesView = React.createClass({ | |
rev={rev} | ||
fileName={match.Filename} | ||
blocks={CoalesceMatches(match.Matches)} | ||
regexp={regexp}/> | ||
regexp={regexp} | ||
isAutoGenerated={match.AutoGenerated}/> | ||
}); | ||
|
||
|
||
|
@@ -886,7 +887,8 @@ var ResultView = React.createClass({ | |
rev={result.Rev} | ||
repo={result.Repo} | ||
regexp={regexp} | ||
files={result.FilesWithMatch}/> | ||
files={result.FilesWithMatch} | ||
/> | ||
); | ||
}); | ||
var actions = ''; | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package vcs | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"regexp" | ||
|
@@ -15,6 +17,7 @@ import ( | |
const defaultRef = "master" | ||
|
||
var headBranchRegexp = regexp.MustCompile(`HEAD branch: (?P<branch>.+)`) | ||
var autoGeneratedFileRegexp = regexp.MustCompile(`(?P<path>.+) linguist-generated=true`) | ||
|
||
func init() { | ||
Register(newGit, "git") | ||
|
@@ -151,6 +154,29 @@ func (g *GitDriver) SpecialFiles() []string { | |
} | ||
} | ||
|
||
func (g *GitDriver) AutoGeneratedFilePatterns(dir string) []string { | ||
var filePatterns []string | ||
path := filepath.Join(dir, ".gitattributes") | ||
|
||
file, err := os.Open(path) | ||
if err != nil { | ||
return filePatterns | ||
} | ||
defer file.Close() | ||
|
||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
matches := autoGeneratedFileRegexp.FindStringSubmatch(scanner.Text()) | ||
if len(matches) == 2 { | ||
pattern := strings.ReplaceAll(matches[1], "**", "*") | ||
pattern = strings.ReplaceAll(pattern, "*", ".*") | ||
filePatterns = append(filePatterns, pattern) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Could you add a test for this pattern-to-regex conversion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah i might change this logic (see my comment about regexes and using direct file paths instead). but either way, i will add a test for the code added in this file! |
||
} | ||
} | ||
|
||
return filePatterns | ||
} | ||
|
||
func (d *headBranchDetector) detectRef(dir string) string { | ||
output, err := run("git show remote info", dir, | ||
"git", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, you swapped the order of this block so that we don't create
opt
if there's an error pulling?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah i swapped it because i needed
wd.PullOrClone
to be executed first so that whenwd.AutoGeneratedFilePatterns(vcsDir)
is called, it can find the.gitattributes
file.wd.PullOrClone
will populate the directory so without it, the first run of this flow will not see accurate results for autogenerated filesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh gotcha, that makes sense.