[pm publish] add clean option and use in build

This is a DX feature request to reduce confusion that comes from having a
build-controlled repository. The user intention is that the repository
contains only the packages specified by the build. It should not contain
packages that are not included in the build configuration.

Test: pm publish -a -f mypkg-0.far; then pm publish -ps -f /dev/null -C
Change-Id: Ie257ba4aeb4c017b57a0faff6cadf1f20048ceae
diff --git a/garnet/go/src/pm/cmd/pm/publish/publish.go b/garnet/go/src/pm/cmd/pm/publish/publish.go
index bd08eed..12a7b8b9 100644
--- a/garnet/go/src/pm/cmd/pm/publish/publish.go
+++ b/garnet/go/src/pm/cmd/pm/publish/publish.go
@@ -22,8 +22,9 @@
 )
 
 const (
-	usage = `Usage: %s publish (-a|-ps) -f file [-r <repo_path>]
-		Pass any one of the mode flags (-a|-ps), and at least one file to pubish.
+	usage = `Usage: %s publish (-a|-ps) -C -f file [-r <repo_path>]
+
+Pass any one of the mode flags (-a|-ps), and at least one file to pubish.
 `
 	serverBase = "amber-files"
 	metaFar    = "meta.far"
@@ -62,6 +63,8 @@
 	filePaths := RepeatedArg{}
 	fs.Var(&filePaths, "f", "Path(s) of the file(s) to publish")
 
+	clean := fs.Bool("C", false, "\"clean\" the repository. only new publications remain.")
+
 	fs.Usage = func() {
 		fmt.Fprintf(os.Stderr, usage, filepath.Base(os.Args[0]))
 		fmt.Fprintln(os.Stderr)
@@ -116,6 +119,16 @@
 	if *verbose {
 		fmt.Printf("initialized repo %s\n", config.RepoDir)
 	}
+	if *clean {
+		// Remove any staged items from the repository that are yet to be published.
+		if err := repo.Clean(); err != nil {
+			return err
+		}
+		// Removes all existing published targets from the repository.
+		if err := repo.RemoveTargets([]string{}); err != nil {
+			return err
+		}
+	}
 
 	switch {
 	case *archiveMode:
diff --git a/garnet/go/src/pm/pm.gni b/garnet/go/src/pm/pm.gni
index c3cfae6..faedf6e 100644
--- a/garnet/go/src/pm/pm.gni
+++ b/garnet/go/src/pm/pm.gni
@@ -67,6 +67,7 @@
 
     args = [
       "publish",
+      "-C",
       "-r",
       rebase_path(amber_repository_dir, root_build_dir),
       "-ps",