-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
WIP: Add require signed commits feature #8584
Conversation
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.
Some spelling mistakes and a hint as to how to get the git commands to work
return | ||
} | ||
|
||
stdout, err := git.NewCommand("rev-list", oldCommitID+"..."+newCommitID).RunInDirBytes(repo.RepoPath()) |
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.
In pre-receive the new commits and objects are not placed directly into the object tree (depending on your git version of course). They are placed in to Quarantine and/or various other places.
You need to set the environment for any git commands to tell it to look in those directories for objects too.
Lines 67 to 82 in 0a004a6
env := os.Environ() | |
if gitAlternativeObjectDirectories != "" { | |
env = append(env, | |
private.GitAlternativeObjectDirectories+"="+gitAlternativeObjectDirectories) | |
} | |
if gitObjectDirectory != "" { | |
env = append(env, | |
private.GitObjectDirectory+"="+gitObjectDirectory) | |
} | |
if gitQuarantinePath != "" { | |
env = append(env, | |
private.GitQuarantinePath+"="+gitQuarantinePath) | |
} | |
output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).RunInDirWithEnv(repo.RepoPath(), env) | |
if err != nil { |
I wouldn't use OpenRepository either just use the git repo commands directly. If you want to use gogit commands I'm fairly certain you can set its environs similarly.
@@ -1336,6 +1336,8 @@ settings.protect_merge_whitelist_teams = Whitelisted teams for merging: | |||
settings.protect_check_status_contexts = Enable Status Check | |||
settings.protect_check_status_contexts_desc = Require status checks to pass before merging Choose which status checks must pass before branches can be merged into a branch that matches this rule. When enabled, commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed. If no contexts are selected, the last commit must be successful regardless of context. | |||
settings.protect_check_status_contexts_list = Status checks found in the last week for this repository | |||
settings.requrie_signed_commits = Require signed commits |
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.
settings.requrie_signed_commits = Require signed commits | |
settings.require_signed_commits = Require signed commits |
@@ -1336,6 +1336,8 @@ settings.protect_merge_whitelist_teams = Whitelisted teams for merging: | |||
settings.protect_check_status_contexts = Enable Status Check | |||
settings.protect_check_status_contexts_desc = Require status checks to pass before merging Choose which status checks must pass before branches can be merged into a branch that matches this rule. When enabled, commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed. If no contexts are selected, the last commit must be successful regardless of context. | |||
settings.protect_check_status_contexts_list = Status checks found in the last week for this repository | |||
settings.requrie_signed_commits = Require signed commits | |||
settings.requrie_signed_commits_desc = Commits pushed to this branch must have verified signatures. |
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.
settings.requrie_signed_commits_desc = Commits pushed to this branch must have verified signatures. | |
settings.require_signed_commits_desc = Commits pushed to this branch must have verified signatures. |
<div class="field"> | ||
<div class="ui checkbox"> | ||
<input class="require-signedcommits" name="require_signed_commits" type="checkbox" {{if .Branch.RequireSignedCommits}}checked{{end}}> | ||
<label>{{.i18n.Tr "repo.settings.requrie_signed_commits"}}</label> |
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.
<label>{{.i18n.Tr "repo.settings.requrie_signed_commits"}}</label> | |
<label>{{.i18n.Tr "repo.settings.require_signed_commits"}}</label> |
<div class="ui checkbox"> | ||
<input class="require-signedcommits" name="require_signed_commits" type="checkbox" {{if .Branch.RequireSignedCommits}}checked{{end}}> | ||
<label>{{.i18n.Tr "repo.settings.requrie_signed_commits"}}</label> | ||
<p class="help">{{.i18n.Tr "repo.settings.requrie_signed_commits_desc"}}</p> |
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.
<p class="help">{{.i18n.Tr "repo.settings.requrie_signed_commits_desc"}}</p> | |
<p class="help">{{.i18n.Tr "repo.settings.require_signed_commits_desc"}}</p> |
Of course, this doesn't solve the issue of merge and web commits - we still need some way of indicating whether such a commit would be signed and if not possibly disable their merge/submit buttons. As an aside what happens when you try to use the web editor to commit to a protected branch? Presumably it would fail - but do we nicely disable the submit button? |
If I understand your question correctly, yes: the only option available when the branch is protected is "create new branch". |
@guillep2k excellent. I'm sure I've looked at this code before but just forgot. Ok. So for CRUD we'd need to adjust whatever code does that check to add a check using: Line 169 in 5a62ae5
For merges it could just be on attempt to merge that it fails immediately, we do an individual test on display of the UI if the merge button would be displayed or we could cache the results of the individual tests and recombine them on display at the UI depending on the users 2fa status if that matters. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions. |
replaced by #9708 |
Fix #4249, This PR is not work yet because on prereceive hook, you should not get the commit information from the repository.