Skip to content
This repository was archived by the owner on Dec 19, 2020. It is now read-only.
Open
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
8 changes: 8 additions & 0 deletions lib/gitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def set_path(self, wsroot):
assert self.path is None, "Trying to set path, but it has already been set!"
self.path = wsroot / self.name

# find the repo based on path variable
def find_source(self, repo_paths):
for path in repo_paths:
tmp_path = str(Path(path) / self.name)
if GitRepo.is_git_repo(tmp_path):
self.source = tmp_path
return

def clone(self):
assert self.path is not None, "Path must be set before cloning!"
assert not GitRepo.is_git_repo(self.path), "Trying to clone and checkout into existing git repo!"
Expand Down
10 changes: 9 additions & 1 deletion lib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import sys
import argparse
import os
from lib.workspace import WorkSpace
from lib.package import Package
import logging
Expand All @@ -28,7 +29,9 @@ def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--verbose', action='store_true')
parser.add_argument('-d', '--debug', action='store_true')
parser.add_argument('--repomap', default=None)
parser.add_argument('--repo-path', default=os.environ.get('WIT_REPO_PATH'))
parser.add_argument('--prepend-repo-path', default=None)

subparsers = parser.add_subparsers(dest='command', help='sub-command help')

init_parser = subparsers.add_parser('init', help='create workspace')
Expand Down Expand Up @@ -62,6 +65,7 @@ def main() -> None:
# workspace cannot be found.
try:
ws = WorkSpace.find(Path.cwd())
ws.set_repo_path(args.repo_path)

except FileNotFoundError as e:
log.error("Unable to find workspace root [{}]. Cannot continue.".format(e))
Expand All @@ -83,6 +87,10 @@ def create(args):
else:
packages = args.add_pkg
ws = WorkSpace.create(args.workspace_name, packages)
ws.set_repo_path(args.repo_path)
for package in packages:
ws.add_package(package)

if not args.no_update:
ws.update()

Expand Down
10 changes: 5 additions & 5 deletions lib/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def from_arg(s):
...
argparse.ArgumentTypeError: Remote git repo 'not-a-repo' does not exist!
"""
# TODO Could speed up valiation
# TODO Could speed up validation
# - use git ls-remote to validate remote exists
# - use git ls-remote to validate revision for tags and branches
# - if github repo, check if page exists (or if you get 404)
Expand All @@ -29,18 +29,18 @@ def from_arg(s):
source, rev = (s.split("::") + [None])[:2]
if rev is None:
rev = "HEAD"
if not lib.gitrepo.GitRepo.is_git_repo(source):
msg = "Remote git repo '{}' does not exist!".format(source)
raise argparse.ArgumentTypeError(msg)

return lib.gitrepo.GitRepo(source, rev)

@staticmethod
def from_manifest(wsroot, m):
commit = m['commit']
name = m['name']
source = m['source']
# Source is not required, because the repo may be found on
# $WIT_REPO_PATH
source = m.get('source', None)
path = wsroot / name

# if not lib.gitrepo.GitRepo.is_git_repo(path):
# # TODO implement redownloading from remote
# msg = "path '{}' is not a git repo even though it's in the manifest!".format(path)
Expand Down
19 changes: 10 additions & 9 deletions lib/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def __init__(self, path, manifest, lock=None):
self.path = path
self.manifest = manifest
self.lock = lock
self.repo_paths = [ ]

# create a new workspace root given a name.
@staticmethod
def create(name, packages):
path = Path.cwd() / name

manifest_path = WorkSpace._manifest_path(path)
if path.exists():
log.info("Using existing directory [{}]".format(str(path)))
Expand All @@ -50,10 +50,7 @@ def create(name, packages):
log.error("Unable to create workspace [{}]: {}".format(str(path), e))
sys.exit(1)

for package in packages:
package.set_path(path)
package.clone_and_checkout()
manifest = Manifest(packages)
manifest = Manifest([ ])
manifest.write(manifest_path)
return WorkSpace(path, manifest)

Expand Down Expand Up @@ -146,10 +143,7 @@ def update(self):
log.debug("Dependencies for [{}]: [{}]".format(repo.path, dependencies))

for dep_repo in dependencies:
# Check to see if there is a path specified in the repomap.
# If so, use that path instead.
# dependent['source'] = self.resolve_repomap(dependent['source'])

dep_repo.find_source(self.repo_paths)
# 8. Clone without checking out the dependency
if not GitRepo.is_git_repo(dep_repo.path):
dep_repo.clone()
Expand Down Expand Up @@ -189,8 +183,15 @@ def update(self):
new_lock.write(self.lockfile_path())
self.lock = new_lock

def set_repo_path(self, repo_path):
if repo_path is not None:
self.repo_paths = repo_path.split(":")
else:
self.repo_paths = [ ]

def add_package(self, package):
package.set_path(self.path)
package.find_source(self.repo_paths)

if GitRepo.is_git_repo(package.path):
raise NotImplementedError
Expand Down
9 changes: 9 additions & 0 deletions t/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!groovy

node('tiny') {
stage('Test') {
timeout(time: 5, unit: 'MINUTES') {
sh 't/regress.sh'
}
}
}
2 changes: 1 addition & 1 deletion t/regress_util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ make_repo() {

mkdir $repo_name
git -C $repo_name init
touch $repo_name/file
echo $RANDOM > $repo_name/file
git -C $repo_name add -A
git -C $repo_name commit -m "commit1"
}
Expand Down
66 changes: 66 additions & 0 deletions t/repo_path.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh

. $(dirname $0)/regress_util.sh

# Set up repo foo
make_repo 'foo'
foo_commit=$(git -C foo rev-parse HEAD)

# Set up repo foo2
make_repo 'foo2'
foo2_commit=$(git -C foo2 rev-parse HEAD)

# Set up repo foo3
make_repo 'foo3'
foo3_commit=$(git -C foo3 rev-parse HEAD)

# Now set up repo bar to depend on foo, foo2, foo3
mkdir bar
git -C bar init

cat << EOF | jq . > bar/wit-manifest.json
[
{ "commit": "$foo_commit", "name": "foo", "source": "$PWD/foo" },
{ "commit": "$foo2_commit", "name": "foo2", "source": "$PWD/foo2" },
{ "commit": "$foo3_commit", "name": "foo3", "source": "$PWD/foo3" }
]
EOF

git -C bar add -A
git -C bar commit -m "commit1"
bar_commit=$(git -C bar rev-parse HEAD)

# Move foo to another directory
mkdir newdir
mv foo newdir/

mkdir newdir2
mv foo2 newdir2/

# Now create a workspace from bar
wit init myws -a $PWD/bar

# Should fail because foo wasn't found
check "wit init with missing dependency fails" [ $? -ne 0 ]


wit --repo-path=$PWD:$PWD/newdir:$PWD/newdir2 init myws2 -a $PWD/bar
check "wit with path set succeeds" [ $? -eq 0 ]

WIT_REPO_PATH=$PWD:$PWD/newdir:$PWD/newdir2 wit init myws3 -a $PWD/bar
check "wit with \$WIT_REPO_PATH succeeds" [ $? -eq 0 ]

cd myws2

check "foo should be pulled in as a dependency of bar" [ -d foo ]
foo_ws_commit=$(git -C foo rev-parse HEAD)
check "foo commit should match the dependency in bar" [ "$foo_ws_commit" = "$foo_commit" ]

foo_lock_commit=$(jq -r '.foo.commit' wit-lock.json)
check "ws-lock.json should contain correct foo commit" [ "$foo_lock_commit" = "$foo_commit" ]

bar_lock_commit=$(jq -r '.bar.commit' wit-lock.json)
check "ws-lock.json should contain correct bar commit" [ "$bar_lock_commit" = "$bar_commit" ]

report
finish
66 changes: 66 additions & 0 deletions t/repo_path_nosource.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh

. $(dirname $0)/regress_util.sh

# Set up repo foo
make_repo 'foo'
foo_commit=$(git -C foo rev-parse HEAD)

# Set up repo foo2
make_repo 'foo2'
foo2_commit=$(git -C foo2 rev-parse HEAD)

# Set up repo foo3
make_repo 'foo3'
foo3_commit=$(git -C foo3 rev-parse HEAD)

# Now set up repo bar to depend on foo, foo2, foo3
mkdir bar
git -C bar init

cat << EOF | jq . > bar/wit-manifest.json
[
{ "commit": "$foo_commit", "name": "foo" },
{ "commit": "$foo2_commit", "name": "foo2" },
{ "commit": "$foo3_commit", "name": "foo3" }
]
EOF

git -C bar add -A
git -C bar commit -m "commit1"
bar_commit=$(git -C bar rev-parse HEAD)

# Move foo to another directory
mkdir newdir
mv foo newdir/

mkdir newdir2
mv foo2 newdir2/

# Now create a workspace from bar
wit init myws -a $PWD/bar

# Should fail because foo wasn't found
check "wit init with missing dependency fails" [ $? -ne 0 ]


wit --repo-path=$PWD:$PWD/newdir:$PWD/newdir2 init myws2 -a $PWD/bar
check "wit with path set succeeds" [ $? -eq 0 ]

WIT_REPO_PATH=$PWD:$PWD/newdir:$PWD/newdir2 wit init myws3 -a $PWD/bar
check "wit with \$WIT_REPO_PATH succeeds" [ $? -eq 0 ]

cd myws2

check "foo should be pulled in as a dependency of bar" [ -d foo ]
foo_ws_commit=$(git -C foo rev-parse HEAD)
check "foo commit should match the dependency in bar" [ "$foo_ws_commit" = "$foo_commit" ]

foo_lock_commit=$(jq -r '.foo.commit' wit-lock.json)
check "ws-lock.json should contain correct foo commit" [ "$foo_lock_commit" = "$foo_commit" ]

bar_lock_commit=$(jq -r '.bar.commit' wit-lock.json)
check "ws-lock.json should contain correct bar commit" [ "$bar_lock_commit" = "$bar_commit" ]

report
finish
53 changes: 53 additions & 0 deletions t/repo_path_relative_root_pkg.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh

. $(dirname $0)/regress_util.sh

# Set up repo foo
make_repo 'foo'
foo_commit=$(git -C foo rev-parse HEAD)

# Now set up repo bar to depend on foo, foo2, foo3
mkdir bar
git -C bar init

cat << EOF | jq . > bar/wit-manifest.json
[
{ "commit": "$foo_commit", "name": "foo", "source": "$PWD/foo" }
]
EOF

git -C bar add -A
git -C bar commit -m "commit1"
bar_commit=$(git -C bar rev-parse HEAD)

# Move foo and bar to another directory
mkdir newdir
mv foo bar newdir/

# Now create a workspace from bar
wit init myws -a bar

# Should fail because bar wasn't found
check "wit init with missing dependency fails" [ $? -ne 0 ]


wit --repo-path=$PWD/newdir init myws2 -a bar
check "wit with path set succeeds" [ $? -eq 0 ]

WIT_REPO_PATH=$PWD/newdir wit init myws3 -a bar
check "wit with \$WIT_REPO_PATH succeeds" [ $? -eq 0 ]

cd myws2

check "foo should be pulled in as a dependency of bar" [ -d foo ]
foo_ws_commit=$(git -C foo rev-parse HEAD)
check "foo commit should match the dependency in bar" [ "$foo_ws_commit" = "$foo_commit" ]

foo_lock_commit=$(jq -r '.foo.commit' wit-lock.json)
check "ws-lock.json should contain correct foo commit" [ "$foo_lock_commit" = "$foo_commit" ]

bar_lock_commit=$(jq -r '.bar.commit' wit-lock.json)
check "ws-lock.json should contain correct bar commit" [ "$bar_lock_commit" = "$bar_commit" ]

report
finish