<commit_before>package git

import (
	"context"
	"fmt"

	"github.com/keybase/client/go/libkb"
	"github.com/keybase/client/go/protocol/keybase1"
)

func DeleteMetadata(ctx context.Context, g *libkb.GlobalContext, folder keybase1.Folder, repoName keybase1.GitRepoName) error {
	teamer := NewTeamer(g)

	teamIDVis, err := teamer.LookupOrCreate(ctx, folder)
	if err != nil {
		return err
	}

	// The GUI doesn't give us the repo_id back, so we need to figure it out.
	repos, err := GetMetadata(ctx, g, folder)
	if err != nil {
		return err
	}
	var repoID keybase1.RepoID
	for _, repo := range repos {
		if repo.LocalMetadata.RepoName == repoName {
			repoID = repo.RepoID
			break
		}
	}
	if repoID == "" {
		return fmt.Errorf("can't find repo named \"%s\"", repoName)
	}

	apiArg := libkb.APIArg{
		Endpoint:    "kbfs/git/team/delete",
		SessionType: libkb.APISessionTypeREQUIRED,
		NetContext:  ctx,
		Args: libkb.HTTPArgs{
			"team_id": libkb.S{Val: string(teamIDVis.TeamID)},
			"repo_id": libkb.S{Val: string(repoID)},
		},
	}
	_, err = g.GetAPI().Post(apiArg)
	if err != nil {
		return err
	}

	g.NotifyRouter.HandleRepoDeleted(ctx, folder, teamIDVis.TeamID, repoID, formatUniqueRepoID(teamIDVis.TeamID, repoID))

	return nil
}<commit_msg>still delete git metadata when git repo doesn't exist<commit_after>package git

import (
	"context"
	"fmt"

	"github.com/keybase/client/go/libkb"
	"github.com/keybase/client/go/protocol/keybase1"
)

func DeleteMetadata(ctx context.Context, g *libkb.GlobalContext, folder keybase1.Folder, repoName keybase1.GitRepoName) error {
	teamer := NewTeamer(g)

	teamIDVis, err := teamer.LookupOrCreate(ctx, folder)
	if err != nil {
		return err
	}

	// The GUI doesn't give us the repo_id back, so we need to figure it out.
	repos, err := GetMetadata(ctx, g, folder)
	if err != nil {
		return err
	}
	var repoID keybase1.RepoID
	for _, repo := range repos {
		if repo.LocalMetadata.RepoName == repoName {
			repoID = repo.RepoID
			break
		}
	}
	if repoID == "" {
		return fmt.Errorf("can't find repo named \"%s\"", repoName)
	}

	apiArg := libkb.APIArg{
		Endpoint:    "kbfs/git/team/delete",
		SessionType: libkb.APISessionTypeREQUIRED,
		NetContext:  ctx,
		Args: libkb.HTTPArgs{
			"team_id": libkb.S{Val: string(teamIDVis.TeamID)},
			"repo_id": libkb.S{Val: string(repoID)},
		},
	}
	_, err = g.GetAPI().Post(apiArg)
	if err != nil {
		switch err.(type) {
		case libkb.RepoDoesntExistError:
			g.Log.Warning("Git repo doesn't exist. Deleting metadata anyway.")
		default:
			return err
		}
	}

	g.NotifyRouter.HandleRepoDeleted(ctx, folder, teamIDVis.TeamID, repoID, formatUniqueRepoID(teamIDVis.TeamID, repoID))

	return nil
}
{'fraction_non_alphanumeric': 0.13208255159474672, 'fraction_numerical': 0.00300187617260788, 'mean_word_length': 3.9279112754158967, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '5063906', 'n_tokens_mistral': 1057, 'n_tokens_neox': 999, 'n_words': 232}