Skip to content

Commit

Permalink
reuse input values where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Hoß committed Aug 10, 2022
1 parent 1bc87a8 commit 3d32d54
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
6 changes: 3 additions & 3 deletions internal/provider/data_source_git_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ func (r *dataSourceGitBranch) Read(ctx context.Context, req tfsdk.ReadDataSource
return
}

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: directory}
state.Branch = types.String{Value: branch.Name}
state.Directory = inputs.Directory
state.Id = inputs.Directory
state.Branch = inputs.Branch
state.Remote = types.String{Value: branch.Remote}
state.Rebase = types.String{Value: branch.Rebase}

Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_git_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func (r *dataSourceGitCommit) Read(ctx context.Context, req tfsdk.ReadDataSource
return
}

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: sha1}
state.SHA1 = types.String{Value: sha1}
state.Directory = inputs.Directory
state.Id = inputs.SHA1
state.SHA1 = inputs.SHA1

commit, err := repository.CommitObject(plumbing.NewHash(sha1))
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_git_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func (r *dataSourceGitConfig) Read(ctx context.Context, req tfsdk.ReadDataSource
"scope": scope,
})

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: directory}
state.Scope = types.String{Value: scope}
state.Directory = inputs.Directory
state.Id = inputs.Directory
state.Scope = inputs.Scope
state.UserName = types.String{Value: cfg.User.Name}
state.UserEmail = types.String{Value: cfg.User.Email}
state.AuthorName = types.String{Value: cfg.Author.Name}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/data_source_git_remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ func (r *dataSourceGitRemotes) Read(ctx context.Context, req tfsdk.ReadDataSourc
}
}

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: directory}
state.Directory = inputs.Directory
state.Id = inputs.Directory
state.Remotes = types.Map{
ElemType: types.ObjectType{
AttrTypes: remoteType,
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/data_source_git_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (r *dataSourceGitRepository) Read(ctx context.Context, req tfsdk.ReadDataSo
"head": head.Name().String(),
})

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: directory}
state.Directory = inputs.Directory
state.Id = inputs.Directory
state.Branch = types.String{Value: head.Name().Short()}

diags = resp.State.Set(ctx, &state)
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_git_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ func (r *dataSourceGitStatus) Read(ctx context.Context, req tfsdk.ReadDataSource
return
}

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: fileName}
state.File = types.String{Value: fileName}
state.Directory = inputs.Directory
state.Id = inputs.File
state.File = inputs.File

worktree, err := repository.Worktree()
if err == git.ErrIsBareRepository {
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/data_source_git_statuses.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (r *dataSourceGitStatuses) Read(ctx context.Context, req tfsdk.ReadDataSour
return
}

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: directory}
state.Directory = inputs.Directory
state.Id = inputs.Directory

statusType := map[string]attr.Type{
"staging": types.StringType,
Expand Down
11 changes: 8 additions & 3 deletions internal/provider/resource_git_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (r *resourceGitInit) Create(ctx context.Context, req tfsdk.CreateResourceRe
return
}

// NOTE: It seems default values are not working?
if inputs.Bare.IsNull() {
inputs.Bare = types.Bool{Value: false}
}

directory := inputs.Directory.Value
bare := inputs.Bare.Value

Expand All @@ -102,9 +107,9 @@ func (r *resourceGitInit) Create(ctx context.Context, req tfsdk.CreateResourceRe
"bare": bare,
})

state.Directory = types.String{Value: directory}
state.Id = types.String{Value: directory}
state.Bare = types.Bool{Value: bare}
state.Directory = inputs.Directory
state.Id = inputs.Directory
state.Bare = inputs.Bare

diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
Expand Down

0 comments on commit 3d32d54

Please sign in to comment.