Repository navigation
git: Allow signing of commits #376
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/MichaelMure/git-bug/cache" | ||
| ) | ||
|
|
||
| func newUserKeyCommand() *cobra.Command { | ||
| env := newEnv() | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "key [<user-id>]", | ||
| Short: "Display, add or remove keys to/from a user.", | ||
| PreRunE: loadBackendEnsureUser(env), | ||
| PostRunE: closeBackend(env), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return runUserKey(env, args) | ||
| }, | ||
| } | ||
|
|
||
| cmd.AddCommand(newUserKeyAddCommand()) | ||
| cmd.AddCommand(newUserKeyRmCommand()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func ResolveUser(repo *cache.RepoCache, args []string) (*cache.IdentityCache, []string, error) { | ||
| var err error | ||
| var id *cache.IdentityCache | ||
| if len(args) > 0 { | ||
| id, err = repo.ResolveIdentityPrefix(args[0]) | ||
| args = args[1:] | ||
| } else { | ||
| id, err = repo.GetUserIdentity() | ||
| } | ||
| return id, args, err | ||
| } | ||
|
|
||
| func runUserKey(env *Env, args []string) error { | ||
| id, args, err := ResolveUser(env.backend, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(args) > 0 { | ||
| return fmt.Errorf("unexpected arguments: %s", args) | ||
| } | ||
|
|
||
| for _, key := range id.Keys() { | ||
| fmt.Println(key.Fingerprint()) | ||
| } | ||
|
|
||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/MichaelMure/git-bug/identity" | ||
| "github.com/MichaelMure/git-bug/input" | ||
| "github.com/MichaelMure/git-bug/validate" | ||
| ) | ||
|
|
||
| type userKeyAddOptions struct { | ||
| ArmoredFile string | ||
| Armored string | ||
| } | ||
|
|
||
| func newUserKeyAddCommand() *cobra.Command { | ||
| env := newEnv() | ||
| options := userKeyAddOptions{} | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "add [<user-id>]", | ||
| Short: "Add a PGP key from a user.", | ||
| PreRunE: loadBackendEnsureUser(env), | ||
| PostRunE: closeBackend(env), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return runUserKeyAdd(env, options, args) | ||
| }, | ||
| } | ||
|
|
||
| flags := cmd.Flags() | ||
| flags.SortFlags = false | ||
|
|
||
| flags.StringVarP(&options.ArmoredFile, "file", "F", "", | ||
| "Take the armored PGP public key from the given file. Use - to read the message from the standard input", | ||
| ) | ||
|
|
||
| flags.StringVarP(&options.Armored, "key", "k", "", | ||
| "Provide the armored PGP public key from the command line", | ||
| ) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
|
|
||
| func runUserKeyAdd(env *Env, opts userKeyAddOptions, args []string) error { | ||
| id, args, err := ResolveUser(env.backend, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(args) > 0 { | ||
| return fmt.Errorf("unexpected arguments: %s", args) | ||
| } | ||
|
|
||
| if opts.ArmoredFile != "" && opts.Armored == "" { | ||
| opts.Armored, err = input.TextFileInput(opts.ArmoredFile) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| if opts.ArmoredFile == "" && opts.Armored == "" { | ||
| opts.Armored, err = input.IdentityVersionKeyEditorInput(env.repo, "") | ||
| if err == input.ErrEmptyMessage { | ||
| fmt.Println("Empty PGP key, aborting.") | ||
| return nil | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| key, err := identity.NewKeyFromArmored(opts.Armored) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| validator, err := validate.NewValidator(env.backend) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to create validator") | ||
| } | ||
| commitHash := validator.KeyCommitHash(key.PublicKey().KeyId) | ||
| if commitHash != "" { | ||
| return fmt.Errorf("key id %d is already used by the key introduced in commit %s", key.PublicKey().KeyId, commitHash) | ||
| } | ||
|
|
||
| err = id.Mutate(identity.AddKeyMutator(key)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return id.Commit() | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is that really useful? Maybe I'm missing something but it looks to me that once a commit is read for validation, it's not useful anymore as it won't be shared with any other identities.
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.
Yes, it does not seem useful.