Skip to content

Commit

Permalink
fix index access errors (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarumaj authored Jan 24, 2024
1 parent 5012f5d commit f209ea3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
12 changes: 3 additions & 9 deletions pkg/commands/command_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,9 @@ func updateRepoConfig(conf *configfile.Configuration, host string, repository *g
}

// set commiter and author
userSection := repoConf.Raw.Section("user")
userSection.SetOption("name", profile.Fullname)
userSection.SetOption("email", profile.Email)

// override remote origin url and remove authentication context
remoteOriginSection := repoConf.Raw.Section("remote").Subsection("origin")
url := remoteOriginSection.Options.Get("url")
conf.Generalize(&url)
remoteOriginSection.SetOption("url", url)
_ = repoConf.Raw.Section("user").
SetOption("name", profile.Fullname).
SetOption("email", profile.Email)

if err := repoConf.Validate(); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/operation_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ func operationLoop(fn func(pool.WorkUnit, operationContext), verbInfinitive stri
}

logger.Debug("Collected workers")
status.Sort().Print()
status.Sort().Align().Print()
}
1 change: 0 additions & 1 deletion pkg/commands/operation_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (p *operationStatus) appendRow(name string, args ...any) {

case string:
p.AddRowField(v, color.FgGreen)

case error:
p.AddRowField(v.Error(), color.FgRed)

Expand Down
5 changes: 4 additions & 1 deletion pkg/configfile/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (conf *Configuration) AppendRepositories(user *resources.User, repos ...res
func (conf Configuration) Authenticate(targetURL *string) {
loggerEntry.Debugf("Authenticating URL: %v", targetURL)
if targetURL == nil || *targetURL == "" || !urlRegex.MatchString(*targetURL) {
loggerEntry.Debugf("Got empty or invalid URL: %#v", targetURL)
return
}

Expand Down Expand Up @@ -340,11 +341,13 @@ func (conf *Configuration) FilterRepositories(repositories *[]resources.Reposito

// Remove username and token from URL.
func (conf Configuration) Generalize(targetURL *string) {
loggerEntry.Debugf("Generalizing URL: %v", targetURL)
if targetURL == nil || *targetURL == "" || !urlRegex.MatchString(*targetURL) {
loggerEntry.Debugf("Got empty or invalid URL: %#v", targetURL)
return
}

loggerEntry.Debugf("Generalizing URL: %s", *targetURL)

*targetURL = urlRegex.ReplaceAllString(*targetURL, "${Schema}${Hostpath}")
loggerEntry.Debugf("Generelized: %s", *targetURL)
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/util/table_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ type TablePrinter struct {
records [][]string
}

// Align records to match the maximum column width and prevent index errors.
func (t *TablePrinter) Align() *TablePrinter {
var max_row_width int
for _, row := range t.records {
if len(row) > max_row_width {
max_row_width = len(row)
}
}

for i := range t.records {
for len(t.records[i]) < max_row_width {
t.records[i] = append(t.records[i], "")
}
}

return t
}

// Get current printer.
func (t *TablePrinter) current() tableprinter.TablePrinter {
if t.isStdErr {
Expand Down

0 comments on commit f209ea3

Please sign in to comment.