Repository: seachicken/gh-poi (go)

Issue:
Commands do not complete in repositories with long commit history
**Describe the bug**
I waited a few tens of seconds and it was still loading.

```
$ gh poi
⠏ Fetching pull requests...
```

**Your Environment**
 - OS: macOS Catalina
 - gh --version: 2.5.0
 - gh-poi: 0.3.3


Pull request description:
Improve performance when commit logs are long
Fixes #34 

Patch:
diff --git a/conn/command.go b/conn/command.go
index 88b3828..d8c8f18 100644
--- a/conn/command.go
+++ b/conn/command.go
@@ -53,7 +53,7 @@ func (conn *Connection) GetBranchNames() (string, error) {
 
 func (conn *Connection) GetLog(branchName string) (string, error) {
 	args := []string{
-		"log", "--first-parent", "--format=%H", branchName,
+		"log", "--first-parent", "--max-count=30", "--format=%H", branchName,
 	}
 	return run("git", args)
 }
diff --git a/conn/fixtures/gh/pr_notFound.json b/conn/fixtures/gh/pr_notFound.json
new file mode 100644
index 0000000..4ea1999
--- /dev/null
+++ b/conn/fixtures/gh/pr_notFound.json
@@ -0,0 +1,8 @@
+{
+  "data": {
+    "search": {
+      "issueCount": 0,
+      "edges": []
+    }
+  }
+}
\ No newline at end of file
diff --git a/conn/fixtures/git/log_issue1ManyCommits.txt b/conn/fixtures/git/log_issue1ManyCommits.txt
new file mode 100644
index 0000000..0773a7a
--- /dev/null
+++ b/conn/fixtures/git/log_issue1ManyCommits.txt
@@ -0,0 +1,3 @@
+62d5d8280031f607f1db058da959a97f6a8e6d90
+b8a2645298053fb62ea03e27feea6c483d3fd27e
+d787669ee4a103fe0b361fe31c10ea037c72f27c
diff --git a/poi.go b/poi.go
index c91f13d..b1a69de 100644
--- a/poi.go
+++ b/poi.go
@@ -210,7 +210,7 @@ func applyCommits(branches []Branch, defaultBranchName string, conn Connection)
 			return nil, err
 		}
 
-		trimmedOids, err := trimBranch(splitLines(oids), branch.Name, conn)
+		trimmedOids, err := trimBranch(splitLines(oids), branch.Name, defaultBranchName, conn)
 		if err != nil {
 			return nil, err
 		}
@@ -222,7 +222,7 @@ func applyCommits(branches []Branch, defaultBranchName string, conn Connection)
 	return results, nil
 }
 
-func trimBranch(oids []string, branchName string, conn Connection) ([]string, error) {
+func trimBranch(oids []string, branchName string, defaultBranchName string, conn Connection) ([]string, error) {
 	results := []string{}
 	childNames := []string{}
 
@@ -235,6 +235,9 @@ func trimBranch(oids []string, branchName string, conn Connection) ([]string, er
 
 		if i == 0 {
 			for _, name := range names {
+				if name == defaultBranchName {
+					return []string{}, nil
+				}
 				if name != branchName {
 					childNames = append(childNames, name)
 				}


Test patch:
diff --git a/poi_test.go b/poi_test.go
index cb402aa..31535a8 100644
--- a/poi_test.go
+++ b/poi_test.go
@@ -493,6 +493,85 @@ func Test_ShouldNotDeletableWhenDefaultBranchAssociatedWithMergedPR(t *testing.T
 	}, actual)
 }
 
+func Test_BranchesAndPRsAreNotAssociatedWhenManyLocalCommitsAreAhead(t *testing.T) {
+	ctrl := gomock.NewController(t)
+	defer ctrl.Finish()
+
+	s := conn.Setup(ctrl).
+		CheckRepos(nil, nil).
+		GetRemoteNames("origin", nil, nil).
+		GetRepoNames("origin", nil, nil).
+		GetBranchNames("@main_issue1", nil, nil).
+		GetLog([]conn.LogStub{
+			{"main", "main"},
+			{"issue1", "issue1ManyCommits"}, // return with '--max-count=3'
+		}, nil, nil).
+		GetAssociatedRefNames([]conn.AssociatedBranchNamesStub{
+			{"62d5d8280031f607f1db058da959a97f6a8e6d90", "issue1"},
+			{"b8a2645298053fb62ea03e27feea6c483d3fd27e", "issue1"},
+			{"d787669ee4a103fe0b361fe31c10ea037c72f27c", "issue1"},
+		}, nil, nil).
+		GetPullRequests("notFound", nil, nil).
+		GetUncommittedChanges("", nil, nil)
+
+	actual, _ := GetBranches(s.Conn, false)
+
+	assert.Equal(t, []Branch{
+		{
+			false, "issue1",
+			[]string{
+				"62d5d8280031f607f1db058da959a97f6a8e6d90",
+				"b8a2645298053fb62ea03e27feea6c483d3fd27e",
+				"d787669ee4a103fe0b361fe31c10ea037c72f27c",
+			},
+			[]PullRequest{},
+			NotDeletable,
+		},
+		{
+			true, "main",
+			[]string{},
+			[]PullRequest{},
+			NotDeletable,
+		},
+	}, actual)
+}
+
+func Test_ShouldBeNoCommitHistoryWhenTheFirstCommitOfATopicBranchIsAssociatedWithTheDefaultBranch(t *testing.T) {
+	ctrl := gomock.NewController(t)
+	defer ctrl.Finish()
+
+	s := conn.Setup(ctrl).
+		CheckRepos(nil, nil).
+		GetRemoteNames("origin", nil, nil).
+		GetRepoNames("origin", nil, nil).
+		GetBranchNames("@main_issue1", nil, nil).
+		GetLog([]conn.LogStub{
+			{"main", "main"}, {"issue1", "main"},
+		}, nil, nil).
+		GetAssociatedRefNames([]conn.AssociatedBranchNamesStub{
+			{"6ebe3d30d23531af56bd23b5a098d3ccae2a534a", "main_issue1"},
+		}, nil, nil).
+		GetPullRequests("notFound", nil, nil).
+		GetUncommittedChanges("", nil, nil)
+
+	actual, _ := GetBranches(s.Conn, false)
+
+	assert.Equal(t, []Branch{
+		{
+			false, "issue1",
+			[]string{},
+			[]PullRequest{},
+			NotDeletable,
+		},
+		{
+			true, "main",
+			[]string{},
+			[]PullRequest{},
+			NotDeletable,
+		},
+	}, actual)
+}
+
 func Test_ReturnsAnErrorWhenGetRemoteNamesFails(t *testing.T) {
 	ctrl := gomock.NewController(t)
 	defer ctrl.Finish()