diff --git a/cmd/notary/integration_test.go b/cmd/notary/integration_test.go index d5bc535b82..5c47287314 100644 --- a/cmd/notary/integration_test.go +++ b/cmd/notary/integration_test.go @@ -1605,7 +1605,7 @@ func TestWitness(t *testing.T) { // 12. check non-targets base roles all fail for _, role := range []string{data.CanonicalRootRole, data.CanonicalSnapshotRole, data.CanonicalTimestampRole} { // clear any pending changes to ensure errors are only related to the specific role we're trying to witness - _, err = runCommand(t, tempDir, "reset", "gun") + _, err = runCommand(t, tempDir, "reset", "gun", "--all") require.NoError(t, err) _, err = runCommand(t, tempDir, "witness", "gun", role) @@ -1618,7 +1618,7 @@ func TestWitness(t *testing.T) { // 13. test auto-publish functionality (just for witness) // purge the old staged witness - _, err = runCommand(t, tempDir, "reset", "gun") + _, err = runCommand(t, tempDir, "reset", "gun", "--all") require.NoError(t, err) // remove key2 and add back key1 diff --git a/cmd/notary/main_test.go b/cmd/notary/main_test.go index 25985c30a4..dcac3f5003 100644 --- a/cmd/notary/main_test.go +++ b/cmd/notary/main_test.go @@ -152,7 +152,7 @@ var exampleValidCommands = []string{ "init repo", "list repo", "status repo", - "reset repo", + "reset repo --all", "publish repo", "add repo v1 somefile", "addhash repo targetv1 --sha256 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 10", diff --git a/cmd/notary/tuf.go b/cmd/notary/tuf.go index 5158b0b654..e9dba68eda 100644 --- a/cmd/notary/tuf.go +++ b/cmd/notary/tuf.go @@ -116,6 +116,7 @@ type tufCommander struct { output string quiet bool + resetAll bool deleteIdx []int archiveChangelist string @@ -133,7 +134,8 @@ func (t *tufCommander) AddToCommand(cmd *cobra.Command) { cmd.AddCommand(cmdTUFStatusTemplate.ToCommand(t.tufStatus)) cmdReset := cmdTUFResetTemplate.ToCommand(t.tufReset) - cmdReset.Flags().IntSliceVarP(&t.deleteIdx, "unstage", "u", nil, "Numbers of specific changes to exclusively delete, as shown in status list") + cmdReset.Flags().IntSliceVarP(&t.deleteIdx, "number", "n", nil, "Numbers of specific changes to exclusively reset, as shown in status list") + cmdReset.Flags().BoolVar(&t.resetAll, "all", false, "Reset all changes shown in the status list") cmd.AddCommand(cmdReset) cmd.AddCommand(cmdTUFPublishTemplate.ToCommand(t.tufPublish)) @@ -589,6 +591,10 @@ func (t *tufCommander) tufReset(cmd *cobra.Command, args []string) error { cmd.Usage() return fmt.Errorf("Must specify a GUN") } + if !t.resetAll && len(t.deleteIdx) < 1 { + cmd.Usage() + return fmt.Errorf("Must specify changes to reset with -n or the --all flag") + } config, err := t.configGetter() if err != nil { @@ -612,11 +618,10 @@ func (t *tufCommander) tufReset(cmd *cobra.Command, args []string) error { return err } - - if len(t.deleteIdx) > 0 { - return cl.Remove(t.deleteIdx) + if t.resetAll { + return cl.Clear(t.archiveChangelist) } - return cl.Clear(t.archiveChangelist) + return cl.Remove(t.deleteIdx) } func (t *tufCommander) tufPublish(cmd *cobra.Command, args []string) error { diff --git a/cmd/notary/tuf_test.go b/cmd/notary/tuf_test.go index 36507b8f90..913f805298 100644 --- a/cmd/notary/tuf_test.go +++ b/cmd/notary/tuf_test.go @@ -137,7 +137,8 @@ func TestStatusUnstageAndReset(t *testing.T) { } // run a reset with an empty changelist and make sure it succeeds - err := tc.tufStatus(&cobra.Command{}, []string{"gun"}) + tc.resetAll = true + err := tc.tufReset(&cobra.Command{}, []string{"gun"}) require.NoError(t, err) // add some targets @@ -161,7 +162,7 @@ func TestStatusUnstageAndReset(t *testing.T) { require.Contains(t, out, "test3") require.Contains(t, out, "test4") - _, err = runCommand(t, tempBaseDir, "reset", "gun", "--unstage", "-1,1,3,10") + _, err = runCommand(t, tempBaseDir, "reset", "gun", "-n", "-1,1,3,10") require.NoError(t, err) out, err = runCommand(t, tempBaseDir, "status", "gun") @@ -171,7 +172,7 @@ func TestStatusUnstageAndReset(t *testing.T) { require.Contains(t, out, "test3") require.NotContains(t, out, "test4") - _, err = runCommand(t, tempBaseDir, "reset", "gun") + _, err = runCommand(t, tempBaseDir, "reset", "gun", "--all") require.NoError(t, err) out, err = runCommand(t, tempBaseDir, "status", "gun") @@ -204,6 +205,7 @@ func TestGetTrustPinningErrors(t *testing.T) { }, } require.Error(t, tc.tufStatus(&cobra.Command{}, []string{"gun"})) + tc.resetAll = true require.Error(t, tc.tufReset(&cobra.Command{}, []string{"gun"})) require.Error(t, tc.tufDeleteGUN(&cobra.Command{}, []string{"gun"})) require.Error(t, tc.tufInit(&cobra.Command{}, []string{"gun"})) diff --git a/docs/command_reference.md b/docs/command_reference.md index 6dcba0025e..5c7e188a75 100644 --- a/docs/command_reference.md +++ b/docs/command_reference.md @@ -76,10 +76,10 @@ You can view staged changes with `notary status` and unstage them with `notary r $ notary status # Unstage a specific change -$ notary reset --unstage 0 +$ notary reset -n 0 # Alternatively, reset all changes -$ notary reset +$ notary reset --all ``` When you're ready to publish your changes to the Notary server, run: diff --git a/docs/getting_started.md b/docs/getting_started.md index 33ff33dcb2..a9564a6492 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -144,7 +144,7 @@ $ notary -s https://notary.docker.io -d ~/.docker/trust publish docker.io/libra Note that each row in the status has a number associated with it, found in the first column. This number can be used to remove individual changes from the changelist if -they are no longer desired. This is done using the `reset` command and its `--unstage` flag: +they are no longer desired. This is done using the `reset` command: ``` $ notary -d ~/.docker/trust status docker.io/library/alpine @@ -154,7 +154,7 @@ Unpublished changes for docker.io/library/alpine: \- ------ ----- ---- ---- 0 delete targets target 2.6 1 create targets target 3.0 -$ notary -d ~/.docker/trust reset docker.io/library/alpine --unstage 0 +$ notary -d ~/.docker/trust reset docker.io/library/alpine -n 0 Unpublished changes for docker.io/library/alpine: \# ACTION SCOPE TYPE PATH @@ -163,12 +163,12 @@ Unpublished changes for docker.io/library/alpine: ``` Pay close attention to how the indices are updated as changes are removed. You may -pass multiple `--unstage` flags with multiple indices in a single invocation of the +pass multiple `-n` flags with multiple indices in a single invocation of the `reset` subcommand and they will all be handled correctly within that invocation. Between invocations however, you should list the changes again to check which indices you want to remove. -It is also possible to completely clear all pending changes by not passing any flags +It is also possible to completely clear all pending changes by passing the `--all` flag to the `reset` subcommand. This deletes all pending changes for the specified GUN. ## Configure the client