From fecb6322f5c574104e5d9596688920c6fa7a536c Mon Sep 17 00:00:00 2001 From: xavierzwirtz Date: Tue, 1 Oct 2019 19:52:56 -0500 Subject: [PATCH] Added omit_branch config setting, if true the entire repo history is cloned. Signed-off-by: xavierzwirtz --- README.md | 2 ++ hg/hg.go | 13 ++++++++++--- hgresource/in.go | 1 + hgresource/types.go | 1 + test/helpers.sh | 10 ++++++++++ test/test_in.sh | 18 ++++++++++++++++++ 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 524c229..5240ed3 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Tracks the commits in a [Mercurial](https://www.mercurial-scm.org/) repository. * `branch`: The branch to track, defaults to `default`. +* `omit_branch`: If set to true, the entire repository history will be cloned. Defaults to false. + * `private_key`: *Optional.* Private key to use when pulling/pushing. Example: ``` diff --git a/hg/hg.go b/hg/hg.go index 1124991..8690574 100644 --- a/hg/hg.go +++ b/hg/hg.go @@ -13,6 +13,7 @@ import ( type Repository struct { Path string Branch string + OmitBranch bool IncludePaths []string ExcludePaths []string TagFilter string @@ -57,12 +58,18 @@ func (self *Repository) CloneOrPull(sourceUri string) ([]byte, error) { } func (self *Repository) clone(sourceUri string) (output []byte, err error) { - _, output, err = self.run("clone", []string{ + args := []string{ "-q", - "--branch", self.Branch, sourceUri, self.Path, - }) + } + + if !self.OmitBranch { + args = append(args, + "--branch", self.Branch) + } + + _, output, err = self.run("clone", args) if err != nil { err = fmt.Errorf("Error cloning repository from %s: %s", sourceUri, err) } diff --git a/hgresource/in.go b/hgresource/in.go index 70bcfe2..c8e8851 100644 --- a/hgresource/in.go +++ b/hgresource/in.go @@ -21,6 +21,7 @@ func runIn(args []string, params *JsonInput, outWriter io.Writer, errWriter io.W repo := &hg.Repository{ Path: destination, Branch: params.Source.Branch, + OmitBranch: params.Source.OmitBranch, IncludePaths: params.Source.IncludePaths, ExcludePaths: params.Source.ExcludePaths, TagFilter: params.Source.TagFilter, diff --git a/hgresource/types.go b/hgresource/types.go index 9925b34..c7fd798 100644 --- a/hgresource/types.go +++ b/hgresource/types.go @@ -14,6 +14,7 @@ type Source struct { IncludePaths []string `json:"paths"` ExcludePaths []string `json:"ignore_paths"` Branch string `json:"branch"` + OmitBranch bool `json:"omit_branch"` TagFilter string `json:"tag_filter"` RevSetFilter string `json:"revset_filter"` SkipSslVerification bool `json:"skip_ssl_verification"` diff --git a/test/helpers.sh b/test/helpers.sh index f85dd15..cda1a7d 100644 --- a/test/helpers.sh +++ b/test/helpers.sh @@ -466,6 +466,16 @@ get_uri_at_branch() { }" | ${resource_dir}/in "$3" | tee /dev/stderr } + +get_uri_omit_branch() { + jq -n "{ + source: { + uri: $(echo $1 | jq -R .), + omit_branch: true + } + }" | ${resource_dir}/in "$2" | tee /dev/stderr +} + put_uri() { jq -n "{ source: { diff --git a/test/test_in.sh b/test/test_in.sh index fd27269..4e1b008 100755 --- a/test/test_in.sh +++ b/test/test_in.sh @@ -207,4 +207,22 @@ test_path_changed() { assertEquals "$expected2" "$(get_uri_at_ref $repo2 $repo2_ref $dest | jq '.version')" } +test_it_ommits_branch() { + local repo=$(init_repo) + local ref1=$(make_commit $repo) + local ref2=$(make_commit_to_branch $repo branch1) + local ref3=$(make_commit_to_branch $repo branch2) + + local dest=$TMPDIR/destination + + # verify that default, branch1, and branch2 were pulled + local cloneExpected=$(echo "{\"ref\": $(echo $ref3 | jq -R .)}" | jq ".") + assertEquals "$cloneExpected" "$(get_uri_omit_branch $repo $dest | jq '.version')" + + local ref4=$(make_commit_to_branch $repo branch3) + + local pullExpected=$(echo "{\"ref\": $(echo $ref4 | jq -R .)}" | jq ".") + assertEquals "$pullExpected" "$(get_uri_omit_branch $repo $dest | jq '.version')" +} + source $(dirname $0)/shunit2