Skip to content

Commit

Permalink
Merge pull request #15 from xavierzwirtz/omit_branch
Browse files Browse the repository at this point in the history
Added omit_branch config setting, if true the entire repo history is cloned
  • Loading branch information
xtremerui authored Jun 9, 2020
2 parents 5dd25cc + fecb632 commit 00ead53
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down
13 changes: 10 additions & 3 deletions hg/hg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type Repository struct {
Path string
Branch string
OmitBranch bool
IncludePaths []string
ExcludePaths []string
TagFilter string
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions hgresource/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions hgresource/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
10 changes: 10 additions & 0 deletions test/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
18 changes: 18 additions & 0 deletions test/test_in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 00ead53

Please sign in to comment.