| 114 | } |
| 115 | |
| 116 | func (c *Command) Run() error { |
| 117 | c.DefaultValues() |
| 118 | |
| 119 | kptFile, err := kptfileutil.ReadFile(c.Path) |
| 120 | if err != nil { |
| 121 | return errors.Errorf("package missing Kptfile at '%s': %v", c.Path, err) |
| 122 | } |
| 123 | |
| 124 | // Create a staging directory to store all compared packages |
| 125 | stagingDirectory, err := ioutil.TempDir("", "kpt-") |
| 126 | if err != nil { |
| 127 | return errors.Errorf("failed to create stage dir: %v", err) |
| 128 | } |
| 129 | defer func() { |
| 130 | // Cleanup staged content after diff. Ignore cleanup if debugging. |
| 131 | if !c.Debug { |
| 132 | defer os.RemoveAll(stagingDirectory) |
| 133 | } |
| 134 | }() |
| 135 | |
| 136 | // Stage current package |
| 137 | // This prevents prepareForDiff from modifying the local package |
| 138 | localPkgName := NameStagingDirectory(localPackageSource, |
| 139 | kptFile.Upstream.Git.Ref, |
| 140 | kptFile.Upstream.Git.Commit) |
| 141 | currPkg, err := stageDirectory(stagingDirectory, localPkgName) |
| 142 | if err != nil { |
| 143 | return errors.Errorf("failed to create stage dir for current package: %v", err) |
| 144 | } |
| 145 | |
| 146 | err = copyutil.CopyDir(c.Path, currPkg) |
| 147 | if err != nil { |
| 148 | return errors.Errorf("failed to stage current package: %v", err) |
| 149 | } |
| 150 | |
| 151 | // get the upstreamPkg at current version |
| 152 | upstreamPkgName := NameStagingDirectory(remotePackageSource, |
| 153 | kptFile.Upstream.Git.Ref, |
| 154 | kptFile.Upstream.Git.Commit) |
| 155 | upstreamPkg, err := c.PkgGetter.GetPkg(stagingDirectory, |
| 156 | upstreamPkgName, |
| 157 | kptFile.Upstream.Git.Repo, |
| 158 | kptFile.Upstream.Git.Directory, |
| 159 | kptFile.Upstream.Git.Commit) |
| 160 | if err != nil { |
| 161 | return err |
| 162 | } |
| 163 | |
| 164 | var upstreamTargetPkg string |
| 165 | |
| 166 | if c.Ref == "" { |
| 167 | c.Ref, err = gitutil.DefaultRef(kptFile.Upstream.Git.Repo) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if c.DiffType == DiffTypeRemote || |