Skip to content

Commit

Permalink
fix(platform): don't panic if platform not in git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveRuble committed Nov 13, 2020
1 parent 9ad8f11 commit 3c13ba7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cmd/release_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ var releasePlanDiscardCmd = addCommand(releasePlanCmd, &cobra.Command{
if err != nil {
return err
}
branch := p.GetCurrentBranch()
branch, err := p.GetCurrentBranch()
if err != nil {
return err
}
g, err := git.NewGitWrapper(p.FromPath)
if err != nil {
return err
Expand Down
21 changes: 15 additions & 6 deletions pkg/bosun/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ func (p *Platform) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err
}

func (p *Platform) GetCurrentBranch() git.BranchName {
func (p *Platform) GetCurrentBranch() (git.BranchName, error) {
g, err := git.NewGitWrapper(p.FromPath)
if err != nil {
panic(err)
return git.BranchName(""), err
}
return git.BranchName(g.Branch())
return git.BranchName(g.Branch()), nil
}

func (p *Platform) GetEnvironmentConfigs() ([]*environment.Config, error) {
Expand Down Expand Up @@ -1075,7 +1075,11 @@ func (p *Platform) MustGetReleaseManifestBySlot(name string) *ReleaseManifest {
}

func (p *Platform) GetReleaseManifestBySlot(slot string) (*ReleaseManifest, error) {
return p.GetReleaseManifestBySlotAndBranch(slot, slot, p.GetCurrentBranch())
branch, err := p.GetCurrentBranch()
if err != nil {
return nil, err
}
return p.GetReleaseManifestBySlotAndBranch(slot, slot, branch)
}

func (p *Platform) GetReleaseManifestBySlotAndBranch(fromSlot string, asSlot string, branch git.BranchName) (*ReleaseManifest, error) {
Expand Down Expand Up @@ -1132,9 +1136,14 @@ func (p *Platform) GetReleaseManifestBySlotAndBranch(fromSlot string, asSlot str
p.releaseManifests[key] = manifest
manifest.Slot = asSlot

p.log.Debugf("loading release from slot %s into slot %s on branch %s", fromSlot, asSlot, p.GetCurrentBranch())
currentBranch, err := p.GetCurrentBranch()
if err != nil {
return nil, err
}

p.log.Debugf("loading release from slot %s into slot %s on branch %s", fromSlot, asSlot, currentBranch)

if p.Branching.IsRelease(p.GetCurrentBranch()) && asSlot == SlotStable {
if p.Branching.IsRelease(currentBranch) && asSlot == SlotStable {
p.log.Debugf("marking release as current")
manifest.isCurrentRelease = true
}
Expand Down

0 comments on commit 3c13ba7

Please sign in to comment.