Skip to content

Commit

Permalink
fix: failing init if remote is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
10ko authored and eysi09 committed Dec 20, 2019
1 parent 4b3629b commit 938bb20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion garden-service/src/analytics/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface SystemInfo {

export interface AnalyticsEventProperties {
projectId: string
projectName: string
system: SystemInfo
isCI: boolean
sessionId: string
Expand Down Expand Up @@ -107,6 +108,7 @@ export class AnalyticsHandler {
private globalConfig: AnalyticsGlobalConfig
private globalConfigStore: GlobalConfigStore
private projectId = ""
private projectName = ""
private systemConfig: SystemInfo
private isCI = ci.isCI
private sessionId = uuid.v4()
Expand Down Expand Up @@ -171,7 +173,8 @@ export class AnalyticsHandler {

const vcs = new GitHandler(process.cwd(), [])
const originName = await vcs.getOriginName(this.log)
this.projectId = originName ? hasha(originName, { algorithm: "sha256" }) : "unset"
this.projectName = hasha(this.garden.projectName, { algorithm: "sha256" })
this.projectId = originName ? hasha(originName, { algorithm: "sha256" }) : this.projectName

if (this.globalConfig.firstRun || this.globalConfig.showOptInMessage) {
if (!this.isCI) {
Expand Down Expand Up @@ -273,6 +276,7 @@ export class AnalyticsHandler {
private getBasicAnalyticsProperties(): AnalyticsEventProperties {
return {
projectId: this.projectId,
projectName: this.projectName,
system: this.systemConfig,
isCI: this.isCI,
sessionId: this.sessionId,
Expand Down
7 changes: 6 additions & 1 deletion garden-service/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ export class GitHandler extends VcsHandler {
async getOriginName(log: LogEntry) {
const cwd = process.cwd()
const git = this.gitCli(log, cwd)
return (await git("config", "--get", "remote.origin.url"))[0]
try {
return (await git("config", "--get", "remote.origin.url"))[0]
} catch (error) {
log.silly(`Trying to retrieve "git remote origin.url" but encountered an error: ${error}`)
}
return undefined
}
}

0 comments on commit 938bb20

Please sign in to comment.