Skip to content

Commit

Permalink
Merge pull request #604 from rhubert/git-fixes
Browse files Browse the repository at this point in the history
fix unit tests on arch linux
  • Loading branch information
jkloetzke authored Jan 6, 2025
2 parents ca7a67d + 9d8f3fd commit c1146f8
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 39 deletions.
25 changes: 16 additions & 9 deletions pym/bob/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ def getProperties(self, isJenkins, pretty=False):
properties.update({GitScm.REMOTE_PREFIX+key : val})
return properties

def _getGitConfigOptions(self):
config = [ "-c", "submodule.recurse=0" ]
if self.__url.startswith("file:") or self.__url.startswith("/"):
config += [ "-c", "protocol.file.allow=always" ]
return config

async def invoke(self, invoker, switch=False):
alternatesFile = invoker.joinPath(self.__dir, ".git/objects/info/alternates")

Expand Down Expand Up @@ -240,7 +246,7 @@ async def invoke(self, invoker, switch=False):
# refspec is kept in the git config.

# Base fetch command with shallow support
fetchCmd = ["git", "-c", "submodule.recurse=0", "fetch", "-p"]
fetchCmd = ["git", *self._getGitConfigOptions(), "fetch", "-p"]
if isinstance(self.__shallow, int):
fetchCmd.append("--depth={}".format(self.__shallow))
elif isinstance(self.__shallow, str):
Expand Down Expand Up @@ -366,8 +372,8 @@ async def __checkoutTagOnBranch(self, invoker, fetchCmd, switch):
# move to attic
invoker.fail("Cannot switch: Current state woulde be lost.")

await invoker.checkCommand(["git", "-c", "submodule.recurse=0", "reset",
"--keep", commit], cwd=self.__dir)
await invoker.checkCommand(["git", *self._getGitConfigOptions(),
"reset", "--keep", commit], cwd=self.__dir)
await self.__updateSubmodulesPost(invoker, preUpdate)

async def __checkoutTag(self, invoker, fetchCmd, switch):
Expand Down Expand Up @@ -476,28 +482,28 @@ async def __forwardBranch(self, invoker, oldUpstreamCommit):
# commits on the newly fetched upstream.
if oldUpstreamCommit is not None:
await invoker.checkCommand(
["git", "-c", "submodule.recurse=0", "rebase", "--onto",
["git", *self._getGitConfigOptions(), "rebase", "--onto",
"refs/remotes/origin/"+self.__branch, oldUpstreamCommit],
cwd=self.__dir)
else:
# That's bad. We don't know how upstream moved. Try to rebase
# anyway.
invoker.warn("Rebasing", self.__dir, "but old upstream commit not known! Please check result.")
await invoker.checkCommand(
["git", "-c", "submodule.recurse=0", "rebase",
["git", *self._getGitConfigOptions(), "rebase",
"refs/remotes/origin/"+self.__branch],
cwd=self.__dir)
else:
# Just do a fast-forward only merge.
await invoker.checkCommand(
["git", "-c", "submodule.recurse=0", "merge", "--ff-only",
["git", *self._getGitConfigOptions(), "merge", "--ff-only",
"refs/remotes/origin/"+self.__branch],
cwd=self.__dir)

async def __checkoutSubmodules(self, invoker):
if not self.__submodules: return

args = ["git", "-c", "submodule.recurse=0", "submodule", "update", "--init"]
args = ["git", *self._getGitConfigOptions(), "submodule", "update", "--init"]
if self.__shallowSubmodules:
args += ["--depth", "1"]
if self.__recurseSubmodules:
Expand Down Expand Up @@ -574,7 +580,7 @@ async def __updateSubmodulesPost(self, invoker, oldState, base = "."):
return {}

# Sync remote URLs into our config in case they were changed
args = ["git", "-c", "submodule.recurse=0", "-C", base, "submodule", "sync"]
args = ["git", *self._getGitConfigOptions(), "-C", base, "submodule", "sync"]
await invoker.checkCommand(args, cwd=self.__dir)

# List all paths as per .gitmodules. This gives us the list of all
Expand Down Expand Up @@ -603,7 +609,8 @@ async def __updateSubmodulesPost(self, invoker, oldState, base = "."):
}

# Do the update of safe submodules
args = ["git", "-c", "submodule.recurse=0", "-C", base, "submodule", "update", "--init"]
args = ["git", *self._getGitConfigOptions(), "-C", base,
"submodule", "update", "--init"]
if self.__shallowSubmodules:
args += ["--depth", "1"]
args.append("--")
Expand Down
6 changes: 6 additions & 0 deletions src/namespace-sandbox/namespace-sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,17 @@ static void SetupDevices() {
// Recursively creates the file or directory specified in "path" and its parent
// directories.
static int CreateTarget(const char *path, bool is_directory) {
static const char* ROOT_DIR = ".";

if (path == NULL) {
errno = EINVAL;
return -1;
}

if (strlen(path) == 0) {
path = ROOT_DIR;
}

struct stat sb;
// If the path already exists...
if (stat(path, &sb) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion test/black-box/buildid-change/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ popd
# fill git repo
D="$(mktemp -d)"
pushd "$D"
git init .
git init -b master .
git config user.email "[email protected]"
git config user.name test
echo "first" > first.txt
Expand Down
2 changes: 1 addition & 1 deletion test/black-box/clean/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rm -rf default.yaml
# init a git - repo
gitDir=$(mktemp -d)
pushd "${gitDir}"
git init
git init -b master
git config user.email "[email protected]"
git config user.name test
echo "git" > test.dat
Expand Down
4 changes: 2 additions & 2 deletions test/black-box/fingerprints/recipes/sandbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ multiPackage:
- name: sandbox-image-2
use: [sandbox]
fingerprintIf: True
fingerprintScript: "hostname -A"
fingerprintScript: "hostid"
buildScript: |
cp /id.txt . 2>/dev/null || hostname -A > id.txt
cp /id.txt . 2>/dev/null || hostid > id.txt
packageScript: |
cp -a $1/* .
Expand Down
2 changes: 1 addition & 1 deletion test/black-box/git-alternatives/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cp recipe1.yaml "$bob/recipes/t.yaml"
repo=$dir/repo.git
init_repo() {
mkdir "$1"
git init "$1"
git init -b master "$1"
git -C "$1" config user.email "[email protected]"
git -C "$1" config user.name test

Expand Down
2 changes: 1 addition & 1 deletion test/black-box/git-scm-retry/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cp t.yaml "$bob/recipes"
# Directory to play in
work=$dir/_work
mkdir "$work"
git init "$work"
git init -b master "$work"
git -C "$work" config user.email "[email protected]"
git -C "$work" config user.name test

Expand Down
8 changes: 4 additions & 4 deletions test/black-box/git-scm-switch/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cleanup
# Prepare git repositories

pushd "$git_submod"
git init .
git init -b master .
git config user.email "[email protected]"
git config user.name test
echo sub > sub.txt
Expand All @@ -23,15 +23,15 @@ git commit -m import
popd

pushd "$git_dir1"
git init .
git init -b master .
git config user.email "[email protected]"
git config user.name test
echo "hello world" > test.txt
git add test.txt
git commit -m "initial commit"
git tag -a -m "Tag0" tag0
d1_c0=$(git rev-parse HEAD)
git submodule add "$git_submod" submod
git -c protocol.file.allow=always submodule add "$git_submod" submod
git commit -m "first commit"
git tag -a -m "First Tag" tag1
git checkout -b foobar
Expand All @@ -43,7 +43,7 @@ d1_c2=$(git rev-parse HEAD)
popd

pushd "$git_dir2"
git init .
git init -b master .
git config user.email "[email protected]"
git config user.name test
echo "hello bob" > bob.txt
Expand Down
2 changes: 1 addition & 1 deletion test/black-box/git-scm/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cp recipe1.yaml "$bob/recipes/t.yaml"
# Directory to play in
work=$dir/work
mkdir "$work"
git init "$work"
git init -b master "$work"
git -C "$work" config user.email "[email protected]"
git -C "$work" config user.name test

Expand Down
4 changes: 2 additions & 2 deletions test/black-box/nested-scms/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cleanup
# Prepare git repositories

pushd "$git_dir1"
git init .
git init -b master .
git config user.email "[email protected]"
git config user.name test
echo "commit-1" > git1.txt
Expand All @@ -25,7 +25,7 @@ git tag -a -m "Second Tag" tag2
popd

pushd "$git_dir2"
git init .
git init -b master .
git config user.email "[email protected]"
git config user.name test
echo "commit-1" > git2.txt
Expand Down
2 changes: 1 addition & 1 deletion test/black-box/status/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trap 'rm -rf "${gitDir}" "${urlDir}" "${svnDir}"' EXIT

# init a git - repo
pushd ${gitDir}
git init
git init -b master
git config user.email "[email protected]"
git config user.name test
echo "git" > test.dat
Expand Down
5 changes: 3 additions & 2 deletions test/integration/jenkins/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def testGitModule(jc):
with tempfile.TemporaryDirectory() as gitDir:
with open(os.path.join(gitDir, "result.txt"), "w") as f:
f.write("foo")
subprocess.run(["git", "init", gitDir], check=True)
subprocess.run(["git", "init", "-b", "master", gitDir], check=True)
subprocess.run(["git", "config", "user.email", "bob@test"], check=True, cwd=gitDir)
subprocess.run(["git", "config", "user.name", "bob"], check=True, cwd=gitDir)
subprocess.run(["git", "add", "result.txt"], check=True, cwd=gitDir)
Expand Down Expand Up @@ -322,7 +322,8 @@ def download(url, dest):
"-Djenkins.install.runSetupWizard=false",
"-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true",
"-Dcasc.jenkins.config=" + os.path.abspath("jenkins.yaml"),
"-jar", jenkins],
"-jar", jenkins,
"--enable-future-java" ],
env=env)
print("[TEST]:", "Jenkins running as pid", jenkinsProc.pid, "in", jenkinsHome)

Expand Down
17 changes: 14 additions & 3 deletions test/unit/test_input_gitscm.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ def setUpClass(cls):
with tempfile.TemporaryDirectory() as tmp:
cmds = "\n".join([
'git init .',
'git config --local protocol.file.allow always',
'git config user.email "[email protected]"',
'git config user.name test',
'git checkout -b master',
'echo "hello world" > test.txt',
'git add test.txt',
'git commit -m "first commit"',
Expand Down Expand Up @@ -416,6 +418,7 @@ def setUpClass(cls):
git init .
git config user.email "[email protected]"
git config user.name test
git checkout -b master
for i in $(seq 3) ; do
echo "#$i" > test.txt
Expand Down Expand Up @@ -520,6 +523,7 @@ def setUp(self):
git init .
git config user.email "[email protected]"
git config user.name test
git checkout -b master
echo subsub > subsub.txt
git add subsub.txt
git commit -m import
Expand All @@ -530,10 +534,12 @@ def setUp(self):
git init .
git config user.email "[email protected]"
git config user.name test
git checkout -b master
echo 1 > test.txt
git add test.txt
mkdir -p some/deep
git submodule add --name whatever ../subsub1 some/deep/path
git -c protocol.file.allow=always \
submodule add --name whatever ../subsub1 some/deep/path
git commit -m "commit 1"
echo 2 > test.txt
git commit -a -m "commit 2"
Expand All @@ -542,11 +548,13 @@ def setUp(self):
# setup main module and add first submodule
cd main
git init .
git checkout -b master
git config user.email "[email protected]"
git config user.name test
echo 1 > test.txt
git add test.txt
git submodule add ../sub1
git -c protocol.file.allow=always \
submodule add ../sub1
git commit -m "commit 1"
git tag -a -m 'Tag 1' tag1
cd ..
Expand Down Expand Up @@ -619,6 +627,7 @@ def addSub2(self):
cmds = """\
cd sub2
git init .
git checkout -b master
git config user.email "[email protected]"
git config user.name test
echo 2 > test.txt
Expand All @@ -627,7 +636,7 @@ def addSub2(self):
cd ..
cd main
git submodule add ../sub2
git -c protocol.file.allow=always submodule add ../sub2
git commit -m "commit 2"
cd ..
"""
Expand Down Expand Up @@ -882,6 +891,7 @@ def setUp(self):

cmds = """\
git init .
git checkout -b master
git config user.email "[email protected]"
git config user.name test
echo -n "hello world" > test.txt
Expand Down Expand Up @@ -1023,6 +1033,7 @@ def setUp(self):
git init .
git config user.email "[email protected]"
git config user.name test
git checkout -b master
echo -n "hello world" > test.txt
git add test.txt
git commit -m "first commit"
Expand Down
Loading

0 comments on commit c1146f8

Please sign in to comment.