grim/hgkeeper

Parents 876d62398b99
Children c7acf2d6bfe5
Fix an infinite loop in findHgrcsForRepo if the repo name starts with a /
  • +1 -1
    hg/hg.go
  • +1 -1
    hg/hgrc.go
  • +12 -0
    hg/hgrc_test.go
  • --- a/hg/hg.go Fri Nov 13 21:42:48 2020 -0600
    +++ b/hg/hg.go Fri Nov 13 21:57:16 2020 -0600
    @@ -31,7 +31,7 @@
    rcs := []string{filepath.Join(access.AdminRepoPath(), "site.hgrc")}
    // add the repo specific hgrc's
    - //rcs = append(rcs, findHgrcsForRepo(repoName)...)
    + rcs = append(rcs, findHgrcsForRepo(repoName)...)
    // add the hgrc that controls writability
    rcs = append(rcs, c.tmpHgrc)
    --- a/hg/hgrc.go Fri Nov 13 21:42:48 2020 -0600
    +++ b/hg/hgrc.go Fri Nov 13 21:57:16 2020 -0600
    @@ -40,7 +40,7 @@
    for {
    ret = append(ret, filepath.Join(adminPath, "config", repoName, "hgrc"))
    - if repoName == "." || repoName == "" {
    + if repoName == "." || repoName == "" || repoName == "/" {
    break
    }
    repoName = filepath.Dir(repoName)
    --- a/hg/hgrc_test.go Fri Nov 13 21:42:48 2020 -0600
    +++ b/hg/hgrc_test.go Fri Nov 13 21:57:16 2020 -0600
    @@ -34,3 +34,15 @@
    assert.Equal(t, expected, actual)
    }
    +
    +func TestFindHgrcsForRepoAbsolute(t *testing.T) {
    + actual := findHgrcsForRepo("/grim/testing/abc123")
    + expected := []string{
    + "config/hgrc",
    + "config/grim/hgrc",
    + "config/grim/testing/hgrc",
    + "config/grim/testing/abc123/hgrc",
    + }
    +
    + assert.Equal(t, expected, actual)
    +}