From 0521e63f809e6f32dd1747c255bc56c4c04d0aa6 Mon Sep 17 00:00:00 2001 From: Fedor Korotkiy Date: Sat, 1 Feb 2020 03:59:45 +0300 Subject: [PATCH] Use tmp branch with random name --- tools/testtool/commands/export.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/testtool/commands/export.go b/tools/testtool/commands/export.go index 810c53d..21bf1a1 100644 --- a/tools/testtool/commands/export.go +++ b/tools/testtool/commands/export.go @@ -1,6 +1,9 @@ package commands import ( + "crypto/rand" + "encoding/hex" + "io" "log" "os" "os/exec" @@ -38,7 +41,13 @@ func git(args ...string) { } func exportCode(cmd *cobra.Command, args []string) { - git("checkout", "-b", "temp") + random := make([]byte, 4) + if _, err := io.ReadFull(rand.Reader, random); err != nil { + log.Fatal(err) + } + tmpBranch := "temp/" + hex.EncodeToString(random) + + git("checkout", "-b", tmpBranch) git("reset", "public") privateFiles := listPrivateFiles(".") @@ -50,7 +59,7 @@ func exportCode(cmd *cobra.Command, args []string) { } git("checkout", "public") - git("branch", "-D", "temp") + git("branch", "-D", tmpBranch) git("add", "-A") git("commit", "-m", "export public files", "--allow-empty")