diff --git a/kci-dev/subcommands/commit.py b/kci-dev/subcommands/commit.py index 3366768..d7c2a9b 100644 --- a/kci-dev/subcommands/commit.py +++ b/kci-dev/subcommands/commit.py @@ -14,14 +14,14 @@ def api_connection(host): return host -def find_diff(path, branch, repository): +def find_diff(path, branch, origin, repository): repo = Repo(path) assert not repo.bare - hcommit = repo.iter_commits("origin/master.." + branch) + hcommit = repo.iter_commits(origin + ".." + branch) commits = [] for i in hcommit: commits.append(repo.git.show(i)) - return commits + return commits[0] def send_build(url, patch, branch, treeurl, token): @@ -48,6 +48,7 @@ def send_build(url, patch, branch, treeurl, token): help="define the kernel upstream repository where to test local changes", ) @click.option("--branch", default="master", help="define the repository branch") +@click.option("--origin", default="master", help="define the origin repository branch") @click.option( "--private", default=False, @@ -60,11 +61,11 @@ def send_build(url, patch, branch, treeurl, token): help="define the directory of the local tree with local changes", ) @click.pass_context -def commit(ctx, repository, branch, private, path): +def commit(ctx, repository, branch, origin, private, path): config = ctx.obj.get("CFG") instance = ctx.obj.get("INSTANCE") url = api_connection(config[instance]["host"]) - diff = find_diff(path, branch, repository) + diff = find_diff(path, branch, origin, repository) send_build(url, diff, branch, repository, config[instance]["token"]) diff --git a/tests/test_kcidev.py b/tests/test_kcidev.py index f3ddf69..4cffab2 100644 --- a/tests/test_kcidev.py +++ b/tests/test_kcidev.py @@ -1,6 +1,9 @@ import os from subprocess import PIPE, run +import git +import pytest + def test_prepare(): os.system("cp .kci-dev.toml.example .kci-dev.toml") @@ -38,3 +41,42 @@ def test_kcidev_patch_help(): print("#### stderr ####") print(result.stderr) assert result.returncode == 0 + + +def test_create_repo(): + repo_dir = os.path.join("my-new-repo") + file_name = os.path.join(repo_dir, "new-file") + file_name2 = os.path.join(repo_dir, "new-file2") + r = git.Repo.init(repo_dir) + open(file_name, "wb").close() + r.index.add("new-file") + r.index.commit("initial commit") + test_branch = r.create_head("test") + r.head.reference = test_branch + open(file_name2, "wb").close() + r.index.add("new-file2") + r.index.commit("test") + + +def test_kcidev_commit(): + command = [ + "poetry", + "run", + "kci-dev", + "commit", + "--repository", + "linux-next", + "--origin", + "master", + "--branch", + "test", + "--path", + "my-new-repo", + ] + result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True) + print("returncode: " + str(result.returncode)) + print("#### stdout ####") + print(result.stdout) + print("#### stderr ####") + print(result.stderr) + assert result.returncode == 1