{"action":"created","comment":{"url":"https://api.github.com/repos/github/hub/pulls/comments/24386192","id":24386192,"diff_hunk":"@@ -39,32 +39,38 @@ func transformInitArgs(args *Args) error {\n \t\treturn nil\n \t}\n \n-\tvar (\n-\t\tname   string\n-\t\tnewDir bool\n-\t\terr    error\n-\t)\n+\tvar err error\n+\tdirToInit := \".\"\n+\thasValueRegxp := regexp.MustCompile(\"^--(template|separate-git-dir|shared)$\")\n \n-\tif args.IsParamsEmpty() {\n-\t\tname, err = utils.DirName()\n-\t\tif err != nil {\n-\t\t\treturn err\n+\t// Find the first argument that isn't related to any of the init flags.\n+\t// We assume this is the optional `directory` argument to git init.\n+\tfor i := 0; i < args.ParamsSize(); i++ {\n+\t\targ := args.Params[i]\n+\t\tif hasValueRegxp.MatchString(arg) {\n+\t\t\ti++\n+\t\t} else if !strings.HasPrefix(arg, \"-\") {\n+\t\t\tdirToInit = arg\n+\t\t\tbreak\n \t\t}\n-\t} else {\n-\t\tname = args.LastParam()\n-\t\tnewDir = true\n \t}\n \n-\tproject := github.NewProject(\"\", name, \"\")\n+\tdirToInit, err = filepath.Abs(dirToInit)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// Assume that the name of the working directory is going to be the name of\n+\t// the project on GitHub.\n+\tprojectName := strings.Replace(filepath.Base(dirToInit), \" \", \"-\", -1)\n+\tproject := github.NewProject(\"\", projectName, \"\")\n \turl := project.GitURL(\"\", \"\", true)\n \n-\tcmds := []string{\"git\"}\n-\tif newDir {\n-\t\tcmds = append(cmds, \"--git-dir\", filepath.Join(name, \".git\"))\n+\taddRemote := []string{\n+\t\t\"git\", \"--git-dir\", filepath.Join(dirToInit, \".git\"),","path":"commands/init.go","position":70,"original_position":70,"commit_id":"9305b5bcb89fb66e67229b08e94551a4dff23c91","original_commit_id":"9305b5bcb89fb66e67229b08e94551a4dff23c91","user":{"login":"jingweno","id":169064,"avatar_url":"https://avatars.githubusercontent.com/u/169064?v=3","gravatar_id":"","url":"https://api.github.com/users/jingweno","html_url":"https://github.com/jingweno","followers_url":"https://api.github.com/users/jingweno/followers","following_url":"https://api.github.com/users/jingweno/following{/other_user}","gists_url":"https://api.github.com/users/jingweno/gists{/gist_id}","starred_url":"https://api.github.com/users/jingweno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jingweno/subscriptions","organizations_url":"https://api.github.com/users/jingweno/orgs","repos_url":"https://api.github.com/users/jingweno/repos","events_url":"https://api.github.com/users/jingweno/events{/privacy}","received_events_url":"https://api.github.com/users/jingweno/received_events","type":"User","site_admin":false},"body":":1 to less special cases","created_at":"2015-02-10T03:07:41Z","updated_at":"2015-02-10T03:07:41Z","html_url":"https://github.com/github/hub/pull/802#discussion_r24386192","pull_request_url":"https://api.github.com/repos/github/hub/pulls/802","_links":{"self":{"href":"https://api.github.com/repos/github/hub/pulls/comments/24386192"},"html":{"href":"https://github.com/github/hub/pull/802#discussion_r24386192"},"pull_request":{"href":"https://api.github.com/repos/github/hub/pulls/802"}}},"pull_request":{"url":"https://api.github.com/repos/github/hub/pulls/802","id":28972217,"html_url":"https://github.com/github/hub/pull/802","diff_url":"https://github.com/github/hub/pull/802.diff","patch_url":"https://github.com/github/hub/pull/802.patch","issue_url":"https://api.github.com/repos/github/hub/issues/802","number":802,"state":"open","locked":false,"title":"Better arguments processing for `init` command","user":{"login":"mislav","id":887,"avatar_url":"https://avatars.githubusercontent.com/u/887?v=3","gravatar_id":"","url":"https://api.github.com/users/mislav","html_url":"https://github.com/mislav","followers_url":"https://api.github.com/users/mislav/followers","following_url":"https://api.github.com/users/mislav/following{/other_user}","gists_url":"https://api.github.com/users/mislav/gists{/gist_id}","starred_url":"https://api.github.com/users/mislav/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mislav/subscriptions","organizations_url":"https://api.github.com/users/mislav/orgs","repos_url":"https://api.github.com/users/mislav/repos","events_url":"https://api.github.com/users/mislav/events{/privacy}","received_events_url":"https://api.github.com/users/mislav/received_events","type":"User","site_admin":true},"body":"Now the optional `directory` argument to `git init` is detected by looking for the first \"word\" in arguments that isn't a value for one of `--template`, `--shared`, or `--separate-git-dir` params.\n\nThis is done by simply iterating through args instead of pulling in a full-blown flag-parsing library. This is also the approach we take in the `clone` command.\n\nThis is an alternative implementation to #793. @jingweno, let me know what you think.\n\nFixes #792","created_at":"2015-02-10T01:02:17Z","updated_at":"2015-02-10T03:07:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2dc26a25010198aae2997f541ae42e8343ef2daf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/github/hub/pulls/802/commits","review_comments_url":"https://api.github.com/repos/github/hub/pulls/802/comments","review_comment_url":"https://api.github.com/repos/github/hub/pulls/comments/{number}","comments_url":"https://api.github.com/repos/github/hub/issues/802/comments","statuses_url":"https://api.github.com/repos/github/hub/statuses/9305b5bcb89fb66e67229b08e94551a4dff23c91","head":{"label":"github:git-init-dirs","ref":"git-init-dirs","sha":"9305b5bcb89fb66e67229b08e94551a4dff23c91","user":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"repo":{"id":401025,"name":"hub","full_name":"github/hub","owner":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/github/hub","description":"hub helps you win at git.","fork":false,"url":"https://api.github.com/repos/github/hub","forks_url":"https://api.github.com/repos/github/hub/forks","keys_url":"https://api.github.com/repos/github/hub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/github/hub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/github/hub/teams","hooks_url":"https://api.github.com/repos/github/hub/hooks","issue_events_url":"https://api.github.com/repos/github/hub/issues/events{/number}","events_url":"https://api.github.com/repos/github/hub/events","assignees_url":"https://api.github.com/repos/github/hub/assignees{/user}","branches_url":"https://api.github.com/repos/github/hub/branches{/branch}","tags_url":"https://api.github.com/repos/github/hub/tags","blobs_url":"https://api.github.com/repos/github/hub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/github/hub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/github/hub/git/refs{/sha}","trees_url":"https://api.github.com/repos/github/hub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/github/hub/statuses/{sha}","languages_url":"https://api.github.com/repos/github/hub/languages","stargazers_url":"https://api.github.com/repos/github/hub/stargazers","contributors_url":"https://api.github.com/repos/github/hub/contributors","subscribers_url":"https://api.github.com/repos/github/hub/subscribers","subscription_url":"https://api.github.com/repos/github/hub/subscription","commits_url":"https://api.github.com/repos/github/hub/commits{/sha}","git_commits_url":"https://api.github.com/repos/github/hub/git/commits{/sha}","comments_url":"https://api.github.com/repos/github/hub/comments{/number}","issue_comment_url":"https://api.github.com/repos/github/hub/issues/comments/{number}","contents_url":"https://api.github.com/repos/github/hub/contents/{+path}","compare_url":"https://api.github.com/repos/github/hub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/github/hub/merges","archive_url":"https://api.github.com/repos/github/hub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/github/hub/downloads","issues_url":"https://api.github.com/repos/github/hub/issues{/number}","pulls_url":"https://api.github.com/repos/github/hub/pulls{/number}","milestones_url":"https://api.github.com/repos/github/hub/milestones{/number}","notifications_url":"https://api.github.com/repos/github/hub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/github/hub/labels{/name}","releases_url":"https://api.github.com/repos/github/hub/releases{/id}","created_at":"2009-12-05T22:15:25Z","updated_at":"2015-02-10T02:11:56Z","pushed_at":"2015-02-10T01:14:06Z","git_url":"git://github.com/github/hub.git","ssh_url":"git@github.com:github/hub.git","clone_url":"https://github.com/github/hub.git","svn_url":"https://github.com/github/hub","homepage":"http://hub.github.com/","size":7281,"stargazers_count":5702,"watchers_count":5702,"language":"Go","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":505,"mirror_url":null,"open_issues_count":77,"forks":505,"open_issues":77,"watchers":5702,"default_branch":"master"}},"base":{"label":"github:master","ref":"master","sha":"1409606542e9140324d8b9c113bdb095355f8b4b","user":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"repo":{"id":401025,"name":"hub","full_name":"github/hub","owner":{"login":"github","id":9919,"avatar_url":"https://avatars.githubusercontent.com/u/9919?v=3","gravatar_id":"","url":"https://api.github.com/users/github","html_url":"https://github.com/github","followers_url":"https://api.github.com/users/github/followers","following_url":"https://api.github.com/users/github/following{/other_user}","gists_url":"https://api.github.com/users/github/gists{/gist_id}","starred_url":"https://api.github.com/users/github/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github/subscriptions","organizations_url":"https://api.github.com/users/github/orgs","repos_url":"https://api.github.com/users/github/repos","events_url":"https://api.github.com/users/github/events{/privacy}","received_events_url":"https://api.github.com/users/github/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/github/hub","description":"hub helps you win at git.","fork":false,"url":"https://api.github.com/repos/github/hub","forks_url":"https://api.github.com/repos/github/hub/forks","keys_url":"https://api.github.com/repos/github/hub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/github/hub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/github/hub/teams","hooks_url":"https://api.github.com/repos/github/hub/hooks","issue_events_url":"https://api.github.com/repos/github/hub/issues/events{/number}","events_url":"https://api.github.com/repos/github/hub/events","assignees_url":"https://api.github.com/repos/github/hub/assignees{/user}","branches_url":"https://api.github.com/repos/github/hub/branches{/branch}","tags_url":"https://api.github.com/repos/github/hub/tags","blobs_url":"https://api.github.com/repos/github/hub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/github/hub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/github/hub/git/refs{/sha}","trees_url":"https://api.github.com/repos/github/hub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/github/hub/statuses/{sha}","languages_url":"https://api.github.com/repos/github/hub/languages","stargazers_url":"https://api.github.com/repos/github/hub/stargazers","contributors_url":"https://api.github.com/repos/github/hub/contributors","subscribers_url":"https://api.github.com/repos/github/hub/subscribers","subscription_url":"https://api.github.com/repos/github/hub/subscription","commits_url":"https://api.github.com/repos/github/hub/commits{/sha}","git_commits_url":"https://api.github.com/repos/github/hub/git/commits{/sha}","comments_url":"https://api.github.com/repos/github/hub/comments{/number}","issue_comment_url":"https://api.github.com/repos/github/hub/issues/comments/{number}","contents_url":"https://api.github.com/repos/github/hub/contents/{+path}","compare_url":"https://api.github.com/repos/github/hub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/github/hub/merges","archive_url":"https://api.github.com/repos/github/hub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/github/hub/downloads","issues_url":"https://api.github.com/repos/github/hub/issues{/number}","pulls_url":"https://api.github.com/repos/github/hub/pulls{/number}","milestones_url":"https://api.github.com/repos/github/hub/milestones{/number}","notifications_url":"https://api.github.com/repos/github/hub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/github/hub/labels{/name}","releases_url":"https://api.github.com/repos/github/hub/releases{/id}","created_at":"2009-12-05T22:15:25Z","updated_at":"2015-02-10T02:11:56Z","pushed_at":"2015-02-10T01:14:06Z","git_url":"git://github.com/github/hub.git","ssh_url":"git@github.com:github/hub.git","clone_url":"https://github.com/github/hub.git","svn_url":"https://github.com/github/hub","homepage":"http://hub.github.com/","size":7281,"stargazers_count":5702,"watchers_count":5702,"language":"Go","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":true,"forks_count":505,"mirror_url":null,"open_issues_count":77,"forks":505,"open_issues":77,"watchers":5702,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/github/hub/pulls/802"},"html":{"href":"https://github.com/github/hub/pull/802"},"issue":{"href":"https://api.github.com/repos/github/hub/issues/802"},"comments":{"href":"https://api.github.com/repos/github/hub/issues/802/comments"},"review_comments":{"href":"https://api.github.com/repos/github/hub/pulls/802/comments"},"review_comment":{"href":"https://api.github.com/repos/github/hub/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/github/hub/pulls/802/commits"},"statuses":{"href":"https://api.github.com/repos/github/hub/statuses/9305b5bcb89fb66e67229b08e94551a4dff23c91"}}}}