Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
uses: asdf-vm/actions/install@v4
# uses: asdf-vm/actions/install@9cd779f40fe38688dd19505ccbc4eaaf018b44e7
with:
asdf_version: 0.18.0
asdf_version: 0.19.0

- name: Check out full code history
run: |
Expand Down
10 changes: 5 additions & 5 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# UPDATE_HERE
# https://golang.org/dl/
golang 1.25.5
golang 1.26.4
# https://github.com/goreleaser/goreleaser/releases
goreleaser 2.13.2
goreleaser 2.16.0
# https://github.com/vektra/mockery/releases
mockery 3.6.1
mockery 3.7.0
# https://github.com/caarlos0/svu/releases
svu 3.3.0
svu 3.4.1
# https://github.com/golangci/golangci-lint/releases
golangci-lint 2.8.0
golangci-lint 2.12.2
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test: ## Placeholder to run unit tests
.PHONY: check
check: ## Runs linting
@echo "Linting"
@for d in $$(go list ./... | egrep -v 'vendor|asdf'); do staticcheck $${d}; done
golangci-lint run ./...
@echo

.PHONY: fmt
Expand Down
8 changes: 5 additions & 3 deletions bitbucket/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/stretchr/testify/assert"
)

const expectedProjectName = "MYPROJECTNAME"

func TestGitGetBitbucket_Init_Success(t *testing.T) {
// Set up environment variables
originalUsername := os.Getenv("BITBUCKET_USERNAME")
Expand Down Expand Up @@ -67,12 +69,12 @@ func TestGenerateProjectKey(t *testing.T) {
{
name: "name with hyphens",
input: "my-project-name",
expected: "MYPROJECTNAME",
expected: expectedProjectName,
},
{
name: "name with special chars",
input: "my@project#name!",
expected: "MYPROJECTNAME",
expected: expectedProjectName,
},
{
name: "name with underscores",
Expand All @@ -87,7 +89,7 @@ func TestGenerateProjectKey(t *testing.T) {
{
name: "name with dots",
input: "my.project.name",
expected: "MYPROJECTNAME",
expected: expectedProjectName,
},
{
name: "complex name",
Expand Down
42 changes: 27 additions & 15 deletions gitget/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ import (
const (
HTTPS = "https"
SSH = "ssh"

gitCmdClone = "clone"
gitCmdDiff = "diff"
gitCmdRevParse = "rev-parse"
gitCmdShowRef = "show-ref"
gitCmdStash = "stash"
gitFlagMirror = "--mirror"
gitFlagBranch = "--branch"
gitFlagQuiet = "--quiet"
gitFlagAbbrevRef = "--abbrev-ref"
gitFlagVerify = "--verify"
gitRefHEAD = "HEAD"
)

var (
Expand Down Expand Up @@ -274,7 +286,7 @@ func (repo *Repo) SetRepoFullPath() {
}

// PathExists returns `true` if given `path` passed as sting exists, otherwise returns false.
func PathExists(pathToCheck string) (bool, os.FileInfo) {
func PathExists(pathToCheck string) (exists bool, info os.FileInfo) {
finfo, err := os.Stat(pathToCheck)

if os.IsNotExist(err) {
Expand All @@ -293,7 +305,7 @@ func (repo *Repo) CloneMirror() bool {
log.Infof("%s: Clone repository '%s' for mirror", repo.sha, repo.URL)
var serr bytes.Buffer
_, err := (*repo.executor).ExecGitCommand(
[]string{"clone", "--mirror", repo.URL, repo.fullPath},
[]string{gitCmdClone, gitFlagMirror, repo.URL, repo.fullPath},
nil,
&serr,
"",
Expand All @@ -310,7 +322,7 @@ func (repo *Repo) PushMirror() bool {
log.Infof("%s: Push repository '%s' as a mirror '%s'", repo.sha, repo.URL, repo.mirrorURL)
var serr bytes.Buffer
_, err := (*repo.executor).ExecGitCommand(
[]string{"push", "--mirror", repo.mirrorURL},
[]string{"push", gitFlagMirror, repo.mirrorURL},
nil,
&serr,
repo.fullPath,
Expand All @@ -327,7 +339,7 @@ func (repo *Repo) Clone() bool {
log.Infof("%s: Clone repository '%s'", repo.sha, repo.URL)
var serr bytes.Buffer
_, err := (*repo.executor).ExecGitCommand(
[]string{"clone", "--branch", repo.Ref, repo.URL, repo.fullPath},
[]string{gitCmdClone, gitFlagBranch, repo.Ref, repo.URL, repo.fullPath},
nil,
&serr,
"",
Expand All @@ -345,7 +357,7 @@ func (repo *Repo) ShallowClone() bool {
log.Infof("%s: Clone repository '%s'", repo.sha, repo.URL)
var serr bytes.Buffer
_, err := (*repo.executor).ExecGitCommand(
[]string{"clone", "--depth", "1", "--branch", repo.Ref, repo.URL, repo.fullPath},
[]string{gitCmdClone, "--depth", "1", gitFlagBranch, repo.Ref, repo.URL, repo.fullPath},
nil,
&serr,
"",
Expand Down Expand Up @@ -373,18 +385,18 @@ func (repo *Repo) RemoveTargetDir(dotGit bool) {
}

func (repo *Repo) IsClean() bool {
_, err := (*repo.executor).ExecGitCommand([]string{"diff", "--quiet"}, nil, nil, repo.fullPath)
_, err := (*repo.executor).ExecGitCommand([]string{gitCmdDiff, gitFlagQuiet}, nil, nil, repo.fullPath)
if err != nil {
return false
}
_, err = (*repo.executor).ExecGitCommand([]string{"diff", "--staged", "--quiet"}, nil, nil, repo.fullPath)
_, err = (*repo.executor).ExecGitCommand([]string{gitCmdDiff, "--staged", gitFlagQuiet}, nil, nil, repo.fullPath)
return err == nil
}

func (repo *Repo) IsCurrentBranchRef() bool {
var outb, errb bytes.Buffer
_, err := (*repo.executor).ExecGitCommand(
[]string{"rev-parse", "--abbrev-ref", "HEAD"},
[]string{gitCmdRevParse, gitFlagAbbrevRef, gitRefHEAD},
&outb,
&errb,
repo.fullPath,
Expand All @@ -398,7 +410,7 @@ func (repo *Repo) IsCurrentBranchRef() bool {
func (repo *Repo) GetCurrentBranch() string {
var outb, errb bytes.Buffer
_, err := (*repo.executor).ExecGitCommand(
[]string{"rev-parse", "--abbrev-ref", "HEAD"},
[]string{gitCmdRevParse, gitFlagAbbrevRef, gitRefHEAD},
&outb,
&errb,
repo.fullPath,
Expand All @@ -413,7 +425,7 @@ func (repo *Repo) GetCurrentBranch() string {
func (repo *Repo) GitStashSave() bool {
log.Infof("%s: Stash unsaved changes", repo.sha)
var serr bytes.Buffer
_, err := (*repo.executor).ExecGitCommand([]string{"stash", "save"}, nil, &serr, repo.fullPath)
_, err := (*repo.executor).ExecGitCommand([]string{gitCmdStash, "save"}, nil, &serr, repo.fullPath)
if err != nil {
repo.status.Error = true
log.Warnf("%s: %v: %v", repo.sha, err, serr.String())
Expand All @@ -425,7 +437,7 @@ func (repo *Repo) GitStashSave() bool {
func (repo *Repo) GitStashPop() bool {
log.Infof("%s: Restore stashed changes", repo.sha)
var serr bytes.Buffer
_, err := (*repo.executor).ExecGitCommand([]string{"stash", "pop"}, nil, &serr, repo.fullPath)
_, err := (*repo.executor).ExecGitCommand([]string{gitCmdStash, "pop"}, nil, &serr, repo.fullPath)
if err != nil {
repo.status.Error = true
log.Warnf("%s: %v: %v", repo.sha, err, serr.String())
Expand All @@ -438,7 +450,7 @@ func (repo *Repo) GitStashPop() bool {
func (repo *Repo) IsRefBranch() bool {
fullRef := fmt.Sprintf("refs/heads/%s", repo.Ref)
_, err := (*repo.executor).ExecGitCommand(
[]string{"show-ref", "--quiet", "--verify", fullRef},
[]string{gitCmdShowRef, gitFlagQuiet, gitFlagVerify, fullRef},
nil,
nil,
repo.fullPath,
Expand All @@ -449,7 +461,7 @@ func (repo *Repo) IsRefBranch() bool {
func (repo *Repo) IsRefTag() bool {
fullRef := fmt.Sprintf("refs/tags/%s", repo.Ref)
_, err := (*repo.executor).ExecGitCommand(
[]string{"show-ref", "--quiet", "--verify", fullRef},
[]string{gitCmdShowRef, gitFlagQuiet, gitFlagVerify, fullRef},
nil,
nil,
repo.fullPath,
Expand Down Expand Up @@ -842,7 +854,7 @@ func GetRepositories(
fmt.Fprintln(w)
fmt.Fprintln(w, "REPOSITORY\tPATH\tLOCAL_CHANGES\tNOT_ON_REF\tERROR\tSKIPPED\tCLEAN")
for _, repo := range *repoList {
clean := !(!repo.status.Processed || repo.status.UncommittedChanges || repo.status.NotOnRefBranch || repo.status.Error)
clean := repo.status.Processed && !repo.status.UncommittedChanges && !repo.status.NotOnRefBranch && !repo.status.Error
if repo.status.Processed {
fmt.Fprintf(w, "%s\t%s\t%t\t%t\t%t\t%t\t%t\n",
repo.URL,
Expand Down Expand Up @@ -1087,7 +1099,7 @@ func writeReposToFile(repoSha, cfgFile string, repoList []Repo) {
// if these are existing and returns list of repositories, if any file
// is missing - it fails
func GetConfigRepoList(cfgFiles []string) *RepoList {
var mergedRepoList []Repo
mergedRepoList := make([]Repo, 0, len(cfgFiles))
for _, cfgFile := range cfgFiles {
var singleRepoList []Repo
yamlFile, err := os.ReadFile(cfgFile)
Expand Down
Loading
Loading