Browse Source

pull_request: able to ignore whitespace when check conflict (#4834)

Unknwon 7 years ago
parent
commit
3b8b8a2ee3

+ 1 - 0
conf/locale/locale_en-US.ini

@@ -739,6 +739,7 @@ settings.tracker_issue_style.numeric = Numeric
 settings.tracker_issue_style.alphanumeric = Alphanumeric
 settings.tracker_url_format_desc = You can use placeholder <code>{user} {repo} {index}</code> for user name, repository name and issue index.
 settings.pulls_desc = Enable pull requests to accept public contributions
+settings.pulls.ignore_whitespace = Ignore changes in whitespace
 settings.pulls.allow_rebase_merge = Allow use rebase to merge commits
 settings.danger_zone = Danger Zone
 settings.cannot_fork_to_same_owner = You cannot fork a repository to its original owner.

+ 7 - 1
models/pull.go

@@ -392,10 +392,16 @@ func (pr *PullRequest) testPatch() (err error) {
 		return fmt.Errorf("UpdateLocalCopy [%d]: %v", pr.BaseRepoID, err)
 	}
 
+	args := []string{"apply", "--check"}
+	if pr.BaseRepo.PullsIgnoreWhitespace {
+		args = append(args, "--ignore-whitespace")
+	}
+	args = append(args, patchPath)
+
 	pr.Status = PULL_REQUEST_STATUS_CHECKING
 	_, stderr, err := process.ExecDir(-1, pr.BaseRepo.LocalCopyPath(),
 		fmt.Sprintf("testPatch (git apply --check): %d", pr.BaseRepo.ID),
-		"git", "apply", "--check", patchPath)
+		"git", args...)
 	if err != nil {
 		log.Trace("PullRequest[%d].testPatch (apply): has conflit\n%s", pr.ID, stderr)
 		pr.Status = PULL_REQUEST_STATUS_CONFLICT

+ 1 - 0
models/repo.go

@@ -184,6 +184,7 @@ type Repository struct {
 	ExternalTrackerStyle  string
 	ExternalMetas         map[string]string `xorm:"-"`
 	EnablePulls           bool              `xorm:"NOT NULL DEFAULT true"`
+	PullsIgnoreWhitespace bool              `xorm:"NOT NULL DEFAULT false"`
 	PullsAllowRebase      bool              `xorm:"NOT NULL DEFAULT false"`
 
 	IsFork   bool `xorm:"NOT NULL DEFAULT false"`

File diff suppressed because it is too large
+ 0 - 0
pkg/bindata/bindata.go


+ 1 - 0
pkg/form/repo.go

@@ -102,6 +102,7 @@ type RepoSetting struct {
 	TrackerURLFormat      string
 	TrackerIssueStyle     string
 	EnablePulls           bool
+	PullsIgnoreWhitespace bool
 	PullsAllowRebase      bool
 }
 

+ 1 - 0
routes/repo/setting.go

@@ -147,6 +147,7 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
 		repo.ExternalTrackerFormat = f.TrackerURLFormat
 		repo.ExternalTrackerStyle = f.TrackerIssueStyle
 		repo.EnablePulls = f.EnablePulls
+		repo.PullsIgnoreWhitespace = f.PullsIgnoreWhitespace
 		repo.PullsAllowRebase = f.PullsAllowRebase
 
 		if err := models.UpdateRepository(repo, false); err != nil {

+ 12 - 4
templates/repo/settings/options.tmpl

@@ -197,10 +197,18 @@
 									<label>{{.i18n.Tr "repo.settings.pulls_desc"}}</label>
 								</div>
 							</div>
-							<div class="ui segment field {{if not .Repository.EnablePulls}}disabled{{end}}" id="pull_box">
-								<div class="ui checkbox">
-									<input name="pulls_allow_rebase" type="checkbox" {{if .Repository.PullsAllowRebase}}checked{{end}}>
-									<label>{{.i18n.Tr "repo.settings.pulls.allow_rebase_merge"}}</label>
+							<div class="ui segment {{if not .Repository.EnablePulls}}disabled{{end}}" id="pull_box">
+								<div class="field">
+									<div class="ui checkbox">
+										<input name="pulls_ignore_whitespace" type="checkbox" {{if .Repository.PullsIgnoreWhitespace}}checked{{end}}>
+										<label>{{.i18n.Tr "repo.settings.pulls.ignore_whitespace"}}</label>
+									</div>
+								</div>
+								<div class="field">
+									<div class="ui checkbox">
+										<input name="pulls_allow_rebase" type="checkbox" {{if .Repository.PullsAllowRebase}}checked{{end}}>
+										<label>{{.i18n.Tr "repo.settings.pulls.allow_rebase_merge"}}</label>
+									</div>
 								</div>
 							</div>
 						{{end}}

Some files were not shown because too many files changed in this diff