{"action":"created","issue":{"url":"https://api.github.com/repos/src-d/go-git/issues/553","repository_url":"https://api.github.com/repos/src-d/go-git","labels_url":"https://api.github.com/repos/src-d/go-git/issues/553/labels{/name}","comments_url":"https://api.github.com/repos/src-d/go-git/issues/553/comments","events_url":"https://api.github.com/repos/src-d/go-git/issues/553/events","html_url":"https://github.com/src-d/go-git/issues/553","id":251215770,"number":553,"title":"cloning a particular branch","user":{"login":"alekh2","id":24560176,"avatar_url":"https://avatars3.githubusercontent.com/u/24560176?v=4","gravatar_id":"","url":"https://api.github.com/users/alekh2","html_url":"https://github.com/alekh2","followers_url":"https://api.github.com/users/alekh2/followers","following_url":"https://api.github.com/users/alekh2/following{/other_user}","gists_url":"https://api.github.com/users/alekh2/gists{/gist_id}","starred_url":"https://api.github.com/users/alekh2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alekh2/subscriptions","organizations_url":"https://api.github.com/users/alekh2/orgs","repos_url":"https://api.github.com/users/alekh2/repos","events_url":"https://api.github.com/users/alekh2/events{/privacy}","received_events_url":"https://api.github.com/users/alekh2/received_events","type":"User","site_admin":false},"labels":[{"id":276436463,"url":"https://api.github.com/repos/src-d/go-git/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-08-18T11:21:13Z","updated_at":"2017-08-21T14:54:37Z","closed_at":null,"body":"I would like to implement :- _git clone <repo_url> -b <branch_name> --single-branch_."},"comment":{"url":"https://api.github.com/repos/src-d/go-git/issues/comments/323764882","html_url":"https://github.com/src-d/go-git/issues/553#issuecomment-323764882","issue_url":"https://api.github.com/repos/src-d/go-git/issues/553","id":323764882,"user":{"login":"orirawlings","id":57213,"avatar_url":"https://avatars0.githubusercontent.com/u/57213?v=4","gravatar_id":"","url":"https://api.github.com/users/orirawlings","html_url":"https://github.com/orirawlings","followers_url":"https://api.github.com/users/orirawlings/followers","following_url":"https://api.github.com/users/orirawlings/following{/other_user}","gists_url":"https://api.github.com/users/orirawlings/gists{/gist_id}","starred_url":"https://api.github.com/users/orirawlings/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orirawlings/subscriptions","organizations_url":"https://api.github.com/users/orirawlings/orgs","repos_url":"https://api.github.com/users/orirawlings/repos","events_url":"https://api.github.com/users/orirawlings/events{/privacy}","received_events_url":"https://api.github.com/users/orirawlings/received_events","type":"User","site_admin":false},"created_at":"2017-08-21T14:54:36Z","updated_at":"2017-08-21T14:54:36Z","body":"Hey @alekh2,\r\n\r\nI believe something like the following should do what you want:\r\n\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"os\"\r\n\r\n\t\"gopkg.in/src-d/go-git.v4\"\r\n\t. \"gopkg.in/src-d/go-git.v4/_examples\"\r\n\t\"gopkg.in/src-d/go-git.v4/plumbing\"\r\n)\r\n\r\n// Basic example of how to clone a single branch of a repository\r\nfunc main() {\r\n\tCheckArgs(\"<url>\", \"<directory>\", \"<branch>\")\r\n\turl := os.Args[1]\r\n\tdirectory := os.Args[2]\r\n\tbranch := os.Args[3]\r\n\r\n\t// Clone the given repository to the given directory\r\n\tInfo(\"git clone -b %s --single-branch %s %s\", branch, url, directory)\r\n\r\n\tr, err := git.PlainClone(directory, false, &git.CloneOptions{\r\n\t\tURL:           url,\r\n\t\tReferenceName: plumbing.ReferenceName(branch),\r\n\t\tSingleBranch:  true,\r\n\t})\r\n\r\n\tCheckIfError(err)\r\n\r\n\t// ... retrieving the branch being pointed by HEAD\r\n\tref, err := r.Head()\r\n\tCheckIfError(err)\r\n\t// ... retrieving the commit object\r\n\tcommit, err := r.CommitObject(ref.Hash())\r\n\tCheckIfError(err)\r\n\r\n\tfmt.Println(commit)\r\n}\r\n```\r\n\r\nUnfortunately, when I run this code, I get an error. :(\r\n\r\n```\r\n$ go run main.go https://github.com/src-d/go-git.git go-git v4\r\ngit clone -b v4 --single-branch https://github.com/src-d/go-git.git go-git\r\nerror: reference not found\r\nexit status 1\r\n```\r\n\r\nThe repository in indeed cloned, and only the `v4` branch was retrieved. Unfortunately, it looks like we don't create the local v4 branch or set `HEAD` to point to a local `v4` branch.\r\n\r\n```\r\n$ cd go-git/\r\n$ git show-ref --head\r\n8ddbecf782c2e340fd85bb4ba4d00dc73d749f87 refs/remotes/origin/v4\r\n$ cat .git/HEAD \r\nref: refs/heads/master\r\n```\r\n\r\nThis is what happens when using the standard git tooling:\r\n```\r\n$ git clone -b v4 --single-branch https://github.com/src-d/go-git.git go-git\r\nCloning into 'go-git'...\r\nremote: Counting objects: 6891, done.\r\nremote: Compressing objects: 100% (4/4), done.\r\nremote: Total 6891 (delta 0), reused 0 (delta 0), pack-reused 6887\r\nReceiving objects: 100% (6891/6891), 1.85 MiB | 0 bytes/s, done.\r\nResolving deltas: 100% (4227/4227), done.\r\n$ cd go-git/\r\n$ git show-ref --head\r\n8ddbecf782c2e340fd85bb4ba4d00dc73d749f87 HEAD\r\n8ddbecf782c2e340fd85bb4ba4d00dc73d749f87 refs/heads/v4\r\n8ddbecf782c2e340fd85bb4ba4d00dc73d749f87 refs/remotes/origin/v4\r\n6f43e8933ba3c04072d5d104acc6118aac3e52ee refs/tags/v1.0.0\r\nf821e1340752dce95f73375dc9a13dcd58d58f82 refs/tags/v2.0.0\r\nda5ab9de3e4c1bffa533108f46c5adc30929f7c2 refs/tags/v2.1.0\r\ncebec78608e7913b8c843390237fd609069022ae refs/tags/v2.1.1\r\n37cc5cf842c3c0fb989bcf7525cc8f826d96b295 refs/tags/v2.1.2\r\n35ee4d749be21691b78a7465361ad47179fe2eff refs/tags/v2.1.3\r\n1931dfbf38508e790e9f129873bc073aacc6a50f refs/tags/v2.2.0\r\n07ca1ac7f3058ea6d3274a01973541fb84782f5e refs/tags/v3.0.0\r\nb08327bfaf27171dddc5516c63e5646c40f0b004 refs/tags/v3.0.1\r\n36d14454b32eca89ac43d2934c50f3a1ae2e1d20 refs/tags/v3.0.2\r\n1cd347ec8970388f83745c9a530ea2bcd705c6d9 refs/tags/v3.0.3\r\n08f9e7015aad2ca768638b446fb8632f11601899 refs/tags/v3.0.4\r\n5e73f01cb2e027a8f02801635b79d3a9bc866914 refs/tags/v3.1.0\r\n5413c7aeadb7cb18a6d51dae0bc313f2e129a337 refs/tags/v3.1.1\r\n8cd772a53e8ecd2687b739eea110fa9b179f1e0f refs/tags/v4.0.0-rc1\r\n7e249dfcf28765939bde8f38784b3274b522f880 refs/tags/v4.0.0-rc10\r\nad02bf020460c210660db4fffda7f926b6aae95a refs/tags/v4.0.0-rc11\r\nd3c7400c39f86a4c59340c7a9cda8497186e00fc refs/tags/v4.0.0-rc12\r\n8ddbecf782c2e340fd85bb4ba4d00dc73d749f87 refs/tags/v4.0.0-rc13\r\n743989abd8c1277dff78e56c2583a9f6dff796ff refs/tags/v4.0.0-rc2\r\nf6ed7424cbf33c7013332d7e95b4262a4bc4a523 refs/tags/v4.0.0-rc3\r\neb89d2dd9a36440d58aea224c055b364e49785f7 refs/tags/v4.0.0-rc4\r\nc9353b2bd7c1cbdf8f78dad6deac64ed2f2ed9eb refs/tags/v4.0.0-rc5\r\ne42e10f112ec93fbca3d972dffa9566b94a0f6f8 refs/tags/v4.0.0-rc6\r\n441713897ef5604e8105379f45ebb982ab2c9a75 refs/tags/v4.0.0-rc7\r\nf84e3bbfe59f5438c90000e6a89b41ec8eab51fb refs/tags/v4.0.0-rc8\r\na9920b123ba1f6819a8c03209582d4d28e9fd831 refs/tags/v4.0.0-rc9\r\n```"}}
{"actor":{"display_login":"orirawlings"}}