{"action":"created","comment":{"url":"https://api.github.com/repos/git-tfs/git-tfs/pulls/comments/41097054","id":41097054,"diff_hunk":"@@ -508,9 +513,30 @@ public string AssertValidBranchName(string gitBranchName)\n         {\n             if (!Reference.IsValidName(ShortToLocalName(gitBranchName)))\n                 throw new GitTfsException(\"The name specified for the new git branch is not allowed. Choose another one!\");\n+            var refs = _repository.Refs.Select(r => r.CanonicalName).ToList();\n+            while (IsRefNameUsed(gitBranchName, refs))\n+            {\n+                gitBranchName = \"_\" + gitBranchName;\n+            }\n             return gitBranchName;\n         }\n \n+        private static bool IsRefNameUsed(string gitBranchName, List<string> refs)\n+        {\n+            var parts = gitBranchName.Split('/');\n+            var refName = parts.First();\n+            for (int i = 1; i <= parts.Length; i++)\n+            {\n+                if (refs.Exists(s=>string.Compare(ShortToLocalName(refName), s, StringComparison.InvariantCultureIgnoreCase) == 0)\n+                    || refs.Exists(s => string.Compare(ShortToTfsRemoteName(refName), s, StringComparison.InvariantCultureIgnoreCase) == 0))","path":"GitTfs/Core/GitRepository.cs","position":31,"original_position":31,"commit_id":"0172bbf16b32c8bd49c4a107ccdbd151427c0a72","original_commit_id":"0172bbf16b32c8bd49c4a107ccdbd151427c0a72","user":{"login":"pmiossec","id":460196,"avatar_url":"https://avatars.githubusercontent.com/u/460196?v=3","gravatar_id":"","url":"https://api.github.com/users/pmiossec","html_url":"https://github.com/pmiossec","followers_url":"https://api.github.com/users/pmiossec/followers","following_url":"https://api.github.com/users/pmiossec/following{/other_user}","gists_url":"https://api.github.com/users/pmiossec/gists{/gist_id}","starred_url":"https://api.github.com/users/pmiossec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmiossec/subscriptions","organizations_url":"https://api.github.com/users/pmiossec/orgs","repos_url":"https://api.github.com/users/pmiossec/repos","events_url":"https://api.github.com/users/pmiossec/events{/privacy}","received_events_url":"https://api.github.com/users/pmiossec/received_events","type":"User","site_admin":false},"body":"Thanks for the good idea.\r\nIn fact, we already have a method `HasRef()` which do that and that's better to use it ;)","created_at":"2015-10-04T11:58:12Z","updated_at":"2015-10-04T11:58:12Z","html_url":"https://github.com/git-tfs/git-tfs/pull/856#discussion_r41097054","pull_request_url":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856","_links":{"self":{"href":"https://api.github.com/repos/git-tfs/git-tfs/pulls/comments/41097054"},"html":{"href":"https://github.com/git-tfs/git-tfs/pull/856#discussion_r41097054"},"pull_request":{"href":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856"}}},"pull_request":{"url":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856","id":45475805,"html_url":"https://github.com/git-tfs/git-tfs/pull/856","diff_url":"https://github.com/git-tfs/git-tfs/pull/856.diff","patch_url":"https://github.com/git-tfs/git-tfs/pull/856.patch","issue_url":"https://api.github.com/repos/git-tfs/git-tfs/issues/856","number":856,"state":"open","locked":false,"title":"When a ref name is already used, find a strategy to give another one","user":{"login":"pmiossec","id":460196,"avatar_url":"https://avatars.githubusercontent.com/u/460196?v=3","gravatar_id":"","url":"https://api.github.com/users/pmiossec","html_url":"https://github.com/pmiossec","followers_url":"https://api.github.com/users/pmiossec/followers","following_url":"https://api.github.com/users/pmiossec/following{/other_user}","gists_url":"https://api.github.com/users/pmiossec/gists{/gist_id}","starred_url":"https://api.github.com/users/pmiossec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmiossec/subscriptions","organizations_url":"https://api.github.com/users/pmiossec/orgs","repos_url":"https://api.github.com/users/pmiossec/repos","events_url":"https://api.github.com/users/pmiossec/events{/privacy}","received_events_url":"https://api.github.com/users/pmiossec/received_events","type":"User","site_admin":false},"body":"An example of the case happening when cloning an existing tfs repository\r\nwas a branch created in \"$/project/dev/my_branch\" when in the past was\r\nexisting or still exists a branch with the path \"$/project/dev_my_branch\"\r\n(the 2 refs will have the same git name).\r\n\r\nThe solution here is to add a `_` at the beginning of the expected ref name\r\nuntil we found a ref name is not used.","created_at":"2015-09-19T12:35:51Z","updated_at":"2015-10-04T11:58:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"72ffc6630083415c7aab7cd5bb835826f70d798a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856/commits","review_comments_url":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856/comments","review_comment_url":"https://api.github.com/repos/git-tfs/git-tfs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/git-tfs/git-tfs/issues/856/comments","statuses_url":"https://api.github.com/repos/git-tfs/git-tfs/statuses/0172bbf16b32c8bd49c4a107ccdbd151427c0a72","head":{"label":"pmiossec:find_new_ref_name_for_one_branch_already_taken","ref":"find_new_ref_name_for_one_branch_already_taken","sha":"0172bbf16b32c8bd49c4a107ccdbd151427c0a72","user":{"login":"pmiossec","id":460196,"avatar_url":"https://avatars.githubusercontent.com/u/460196?v=3","gravatar_id":"","url":"https://api.github.com/users/pmiossec","html_url":"https://github.com/pmiossec","followers_url":"https://api.github.com/users/pmiossec/followers","following_url":"https://api.github.com/users/pmiossec/following{/other_user}","gists_url":"https://api.github.com/users/pmiossec/gists{/gist_id}","starred_url":"https://api.github.com/users/pmiossec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmiossec/subscriptions","organizations_url":"https://api.github.com/users/pmiossec/orgs","repos_url":"https://api.github.com/users/pmiossec/repos","events_url":"https://api.github.com/users/pmiossec/events{/privacy}","received_events_url":"https://api.github.com/users/pmiossec/received_events","type":"User","site_admin":false},"repo":{"id":6213807,"name":"git-tfs","full_name":"pmiossec/git-tfs","owner":{"login":"pmiossec","id":460196,"avatar_url":"https://avatars.githubusercontent.com/u/460196?v=3","gravatar_id":"","url":"https://api.github.com/users/pmiossec","html_url":"https://github.com/pmiossec","followers_url":"https://api.github.com/users/pmiossec/followers","following_url":"https://api.github.com/users/pmiossec/following{/other_user}","gists_url":"https://api.github.com/users/pmiossec/gists{/gist_id}","starred_url":"https://api.github.com/users/pmiossec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmiossec/subscriptions","organizations_url":"https://api.github.com/users/pmiossec/orgs","repos_url":"https://api.github.com/users/pmiossec/repos","events_url":"https://api.github.com/users/pmiossec/events{/privacy}","received_events_url":"https://api.github.com/users/pmiossec/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pmiossec/git-tfs","description":"A Git/TFS bridge, similar to git-svn","fork":true,"url":"https://api.github.com/repos/pmiossec/git-tfs","forks_url":"https://api.github.com/repos/pmiossec/git-tfs/forks","keys_url":"https://api.github.com/repos/pmiossec/git-tfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pmiossec/git-tfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pmiossec/git-tfs/teams","hooks_url":"https://api.github.com/repos/pmiossec/git-tfs/hooks","issue_events_url":"https://api.github.com/repos/pmiossec/git-tfs/issues/events{/number}","events_url":"https://api.github.com/repos/pmiossec/git-tfs/events","assignees_url":"https://api.github.com/repos/pmiossec/git-tfs/assignees{/user}","branches_url":"https://api.github.com/repos/pmiossec/git-tfs/branches{/branch}","tags_url":"https://api.github.com/repos/pmiossec/git-tfs/tags","blobs_url":"https://api.github.com/repos/pmiossec/git-tfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pmiossec/git-tfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pmiossec/git-tfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/pmiossec/git-tfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pmiossec/git-tfs/statuses/{sha}","languages_url":"https://api.github.com/repos/pmiossec/git-tfs/languages","stargazers_url":"https://api.github.com/repos/pmiossec/git-tfs/stargazers","contributors_url":"https://api.github.com/repos/pmiossec/git-tfs/contributors","subscribers_url":"https://api.github.com/repos/pmiossec/git-tfs/subscribers","subscription_url":"https://api.github.com/repos/pmiossec/git-tfs/subscription","commits_url":"https://api.github.com/repos/pmiossec/git-tfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/pmiossec/git-tfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/pmiossec/git-tfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/pmiossec/git-tfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/pmiossec/git-tfs/contents/{+path}","compare_url":"https://api.github.com/repos/pmiossec/git-tfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pmiossec/git-tfs/merges","archive_url":"https://api.github.com/repos/pmiossec/git-tfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pmiossec/git-tfs/downloads","issues_url":"https://api.github.com/repos/pmiossec/git-tfs/issues{/number}","pulls_url":"https://api.github.com/repos/pmiossec/git-tfs/pulls{/number}","milestones_url":"https://api.github.com/repos/pmiossec/git-tfs/milestones{/number}","notifications_url":"https://api.github.com/repos/pmiossec/git-tfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pmiossec/git-tfs/labels{/name}","releases_url":"https://api.github.com/repos/pmiossec/git-tfs/releases{/id}","created_at":"2012-10-14T13:16:17Z","updated_at":"2015-05-06T09:02:19Z","pushed_at":"2015-10-02T15:13:40Z","git_url":"git://github.com/pmiossec/git-tfs.git","ssh_url":"git@github.com:pmiossec/git-tfs.git","clone_url":"https://github.com/pmiossec/git-tfs.git","svn_url":"https://github.com/pmiossec/git-tfs","homepage":"http://git-tfs.com/","size":11182,"stargazers_count":3,"watchers_count":3,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":1,"forks":4,"open_issues":1,"watchers":3,"default_branch":"master"}},"base":{"label":"git-tfs:master","ref":"master","sha":"5b6a481e28d3c9b265bb2050300fcad24f1b35e2","user":{"login":"git-tfs","id":1229346,"avatar_url":"https://avatars.githubusercontent.com/u/1229346?v=3","gravatar_id":"","url":"https://api.github.com/users/git-tfs","html_url":"https://github.com/git-tfs","followers_url":"https://api.github.com/users/git-tfs/followers","following_url":"https://api.github.com/users/git-tfs/following{/other_user}","gists_url":"https://api.github.com/users/git-tfs/gists{/gist_id}","starred_url":"https://api.github.com/users/git-tfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/git-tfs/subscriptions","organizations_url":"https://api.github.com/users/git-tfs/orgs","repos_url":"https://api.github.com/users/git-tfs/repos","events_url":"https://api.github.com/users/git-tfs/events{/privacy}","received_events_url":"https://api.github.com/users/git-tfs/received_events","type":"Organization","site_admin":false},"repo":{"id":252774,"name":"git-tfs","full_name":"git-tfs/git-tfs","owner":{"login":"git-tfs","id":1229346,"avatar_url":"https://avatars.githubusercontent.com/u/1229346?v=3","gravatar_id":"","url":"https://api.github.com/users/git-tfs","html_url":"https://github.com/git-tfs","followers_url":"https://api.github.com/users/git-tfs/followers","following_url":"https://api.github.com/users/git-tfs/following{/other_user}","gists_url":"https://api.github.com/users/git-tfs/gists{/gist_id}","starred_url":"https://api.github.com/users/git-tfs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/git-tfs/subscriptions","organizations_url":"https://api.github.com/users/git-tfs/orgs","repos_url":"https://api.github.com/users/git-tfs/repos","events_url":"https://api.github.com/users/git-tfs/events{/privacy}","received_events_url":"https://api.github.com/users/git-tfs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/git-tfs/git-tfs","description":"A Git/TFS bridge, similar to git-svn","fork":false,"url":"https://api.github.com/repos/git-tfs/git-tfs","forks_url":"https://api.github.com/repos/git-tfs/git-tfs/forks","keys_url":"https://api.github.com/repos/git-tfs/git-tfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/git-tfs/git-tfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/git-tfs/git-tfs/teams","hooks_url":"https://api.github.com/repos/git-tfs/git-tfs/hooks","issue_events_url":"https://api.github.com/repos/git-tfs/git-tfs/issues/events{/number}","events_url":"https://api.github.com/repos/git-tfs/git-tfs/events","assignees_url":"https://api.github.com/repos/git-tfs/git-tfs/assignees{/user}","branches_url":"https://api.github.com/repos/git-tfs/git-tfs/branches{/branch}","tags_url":"https://api.github.com/repos/git-tfs/git-tfs/tags","blobs_url":"https://api.github.com/repos/git-tfs/git-tfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/git-tfs/git-tfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/git-tfs/git-tfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/git-tfs/git-tfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/git-tfs/git-tfs/statuses/{sha}","languages_url":"https://api.github.com/repos/git-tfs/git-tfs/languages","stargazers_url":"https://api.github.com/repos/git-tfs/git-tfs/stargazers","contributors_url":"https://api.github.com/repos/git-tfs/git-tfs/contributors","subscribers_url":"https://api.github.com/repos/git-tfs/git-tfs/subscribers","subscription_url":"https://api.github.com/repos/git-tfs/git-tfs/subscription","commits_url":"https://api.github.com/repos/git-tfs/git-tfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/git-tfs/git-tfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/git-tfs/git-tfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/git-tfs/git-tfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/git-tfs/git-tfs/contents/{+path}","compare_url":"https://api.github.com/repos/git-tfs/git-tfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/git-tfs/git-tfs/merges","archive_url":"https://api.github.com/repos/git-tfs/git-tfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/git-tfs/git-tfs/downloads","issues_url":"https://api.github.com/repos/git-tfs/git-tfs/issues{/number}","pulls_url":"https://api.github.com/repos/git-tfs/git-tfs/pulls{/number}","milestones_url":"https://api.github.com/repos/git-tfs/git-tfs/milestones{/number}","notifications_url":"https://api.github.com/repos/git-tfs/git-tfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/git-tfs/git-tfs/labels{/name}","releases_url":"https://api.github.com/repos/git-tfs/git-tfs/releases{/id}","created_at":"2009-07-16T15:36:26Z","updated_at":"2015-10-02T17:30:44Z","pushed_at":"2015-09-28T13:25:32Z","git_url":"git://github.com/git-tfs/git-tfs.git","ssh_url":"git@github.com:git-tfs/git-tfs.git","clone_url":"https://github.com/git-tfs/git-tfs.git","svn_url":"https://github.com/git-tfs/git-tfs","homepage":"http://git-tfs.com/","size":12704,"stargazers_count":827,"watchers_count":827,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":281,"mirror_url":null,"open_issues_count":150,"forks":281,"open_issues":150,"watchers":827,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856"},"html":{"href":"https://github.com/git-tfs/git-tfs/pull/856"},"issue":{"href":"https://api.github.com/repos/git-tfs/git-tfs/issues/856"},"comments":{"href":"https://api.github.com/repos/git-tfs/git-tfs/issues/856/comments"},"review_comments":{"href":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856/comments"},"review_comment":{"href":"https://api.github.com/repos/git-tfs/git-tfs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/git-tfs/git-tfs/pulls/856/commits"},"statuses":{"href":"https://api.github.com/repos/git-tfs/git-tfs/statuses/0172bbf16b32c8bd49c4a107ccdbd151427c0a72"}}}}