<commit_before>package main

import (
	"fmt"
	libgit "github.com/driusan/git"
	"os"
	"strings"
)

func Clone(c *Client, args []string) {
	var repoid string
	var dirName string
	// TODO: This argument parsing should be smarter and more
	// in line with how cgit does it.
	switch len(args) {
	case 0:
		fmt.Fprintln(os.Stderr, "Usage: go-git clone repo [directory]")
		return
	case 1:
		repoid = args[0]
	case 2:
		repoid = args[0]
		dirName = args[1]
	default:
		repoid = args[0]
	}
	repoid = strings.TrimRight(repoid, "/")
	pieces := strings.Split(repoid, "/")

	if dirName == "" {
		if len(pieces) > 0 {
			dirName = pieces[len(pieces)-1]
		}
		dirName = strings.TrimSuffix(dirName, ".git")

		if _, err := os.Stat(dirName); err == nil {
			fmt.Fprintf(os.Stderr, "Directory %s already exists, can not clone.\n", dirName)
			return
		}
		if dirName == "" {
			panic("No directory left to clone into.")
		}
	}

	c = Init(c, []string{dirName})
	repo, err := libgit.OpenRepository(c.GitDir.String())
	if err != nil {
		panic(err)
	}
	Config(c, []string{"--set", "remote.origin.url", repoid})
	Config(c, []string{"--set", "branch.master.remote", "origin"})

	// This should be smarter and try and get the HEAD branch from Fetch.
	// The HEAD refspec isn't necessarily named refs/heads/master.
	Config(c, []string{"--set", "branch.master.merge", "refs/heads/master"})

	Fetch(c, repo, []string{"origin"})
	Reset(c, repo, []string{"--hard"})
}<commit_msg>Update the SymbolicRef for HEAD on clone<commit_after>package main

import (
	"fmt"
	libgit "github.com/driusan/git"
	"os"
	"strings"
)

func Clone(c *Client, args []string) {
	var repoid string
	var dirName string
	// TODO: This argument parsing should be smarter and more
	// in line with how cgit does it.
	switch len(args) {
	case 0:
		fmt.Fprintln(os.Stderr, "Usage: go-git clone repo [directory]")
		return
	case 1:
		repoid = args[0]
	case 2:
		repoid = args[0]
		dirName = args[1]
	default:
		repoid = args[0]
	}
	repoid = strings.TrimRight(repoid, "/")
	pieces := strings.Split(repoid, "/")

	if dirName == "" {
		if len(pieces) > 0 {
			dirName = pieces[len(pieces)-1]
		}
		dirName = strings.TrimSuffix(dirName, ".git")

		if _, err := os.Stat(dirName); err == nil {
			fmt.Fprintf(os.Stderr, "Directory %s already exists, can not clone.\n", dirName)
			return
		}
		if dirName == "" {
			panic("No directory left to clone into.")
		}
	}

	c = Init(c, []string{dirName})
	repo, err := libgit.OpenRepository(c.GitDir.String())
	if err != nil {
		panic(err)
	}
	Config(c, []string{"--set", "remote.origin.url", repoid})
	Config(c, []string{"--set", "branch.master.remote", "origin"})

	// This should be smarter and try and get the HEAD branch from Fetch.
	// The HEAD refspec isn't necessarily named refs/heads/master.
	Config(c, []string{"--set", "branch.master.merge", "refs/heads/master"})

	Fetch(c, repo, []string{"origin"})
	SymbolicRef(c, []string{"HEAD", "refs/heads/master"})
	Reset(c, repo, []string{"--hard"})
}
{'fraction_non_alphanumeric': 0.17169684775318578, 'fraction_numerical': 0.006036217303822937, 'mean_word_length': 3.6976377952755906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6007348', 'n_tokens_mistral': 1190, 'n_tokens_neox': 1091, 'n_words': 297}