DodoApp: Clean up commits on branch/app delete

Fix redirect URL after app deletion.

Change-Id: Id26b114d9dc47a8de547368e55531816d21dd26c
diff --git a/core/installer/welcome/dodo_app.go b/core/installer/welcome/dodo_app.go
index 57de50e..00cf794 100644
--- a/core/installer/welcome/dodo_app.go
+++ b/core/installer/welcome/dodo_app.go
@@ -957,7 +957,7 @@
 		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return
 	}
-	http.Redirect(w, r, fmt.Sprintf("/%s", appName), http.StatusSeeOther)
+	http.Redirect(w, r, "/", http.StatusSeeOther)
 }
 
 type apiCreateAppReq struct {
@@ -1125,9 +1125,11 @@
 		return err
 	}
 	if branch != "master" {
-		return s.client.DeleteRepoBranch(appName, branch)
+		if err := s.client.DeleteRepoBranch(appName, branch); err != nil {
+			return err
+		}
 	}
-	return nil
+	return s.st.DeleteBranch(appName, branch)
 }
 
 func (s *DodoAppServer) deleteApp(appName string) error {
@@ -1147,7 +1149,10 @@
 			return err
 		}
 	}
-	return s.client.DeleteRepo(appName)
+	if err := s.client.DeleteRepo(appName); err != nil {
+		return err
+	}
+	return s.st.DeleteApp(appName)
 }
 
 func (s *DodoAppServer) createAppForBranch(
diff --git a/core/installer/welcome/store.go b/core/installer/welcome/store.go
index 7efdeaf..328c7fd 100644
--- a/core/installer/welcome/store.go
+++ b/core/installer/welcome/store.go
@@ -50,6 +50,8 @@
 	GetCommit(hash string) (Commit, error)
 	GetLastCommitInfo(name, branch string) (LastCommitInfo, error)
 	GetBranches(name string) ([]string, error)
+	DeleteBranch(name, branch string) error
+	DeleteApp(name string) error
 }
 
 func NewStore(cf soft.RepoIO, db *sql.DB) (Store, error) {
@@ -313,3 +315,15 @@
 	}
 	return ret, nil
 }
+
+func (s *storeImpl) DeleteBranch(name, branch string) error {
+	query := `DELETE FROM commits WHERE app_name = ? AND branch = ?`
+	_, err := s.db.Exec(query, name, branch)
+	return err
+}
+
+func (s *storeImpl) DeleteApp(name string) error {
+	query := `DELETE FROM apps WHERE name = ?`
+	_, err := s.db.Exec(query, name)
+	return err
+}