Skip to content

Commit ddc25eb

Browse files
committed
Added doc for git clone optimizaton and script in config/rootfs/debos/scripts/git-operations.sh
1 parent 36c1ee6 commit ddc25eb

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
# git-operations.sh - Standardized git operations for KernelCI rootfs builds
3+
4+
# Optimized git clone function for CI environments
5+
# Usage: git_clone_optimized <repository_url> <target_dir> [branch] [depth]
6+
git_clone_optimized() {
7+
local repo_url="$1"
8+
local target_dir="$2"
9+
local branch="${3:-}"
10+
local depth="${4:-1}"
11+
12+
if [ $# -lt 2 ]; then
13+
echo "Usage: git_clone_optimized <repo_url> <target_dir> [branch] [depth]"
14+
return 1
15+
fi
16+
17+
echo "Cloning $repo_url (depth: $depth) to $target_dir"
18+
19+
# If no branch specified, let git choose the default
20+
if [ -z "$branch" ]; then
21+
echo "No branch specified, using repository default"
22+
git clone \
23+
--depth="$depth" \
24+
--single-branch \
25+
"$repo_url" \
26+
"$target_dir"
27+
else
28+
echo "Using specified branch: $branch"
29+
git clone \
30+
--depth="$depth" \
31+
--single-branch \
32+
--branch="$branch" \
33+
"$repo_url" \
34+
"$target_dir"
35+
fi
36+
}
37+
38+
# Wrapper for backward compatibility
39+
git_clone() {
40+
if [[ $# -eq 2 && -z "${3:-}" ]]; then
41+
echo "Warning: Using deprecated git clone interface. Consider updating to git_clone_optimized"
42+
git_clone_optimized "$1" "$2"
43+
else
44+
git_clone_optimized "$@"
45+
fi
46+
}

doc/git_clone_optimization.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Overview
2+
3+
This document establishes standardized git clone operations for KernelCI rootfs builder scripts to reduce network traffic and improve build performance in CI environments.
4+
5+
## Problem Statement
6+
7+
Rootfs builder scripts currently use inconsistent git clone approaches:
8+
9+
```bash
10+
# Found patterns across scripts:
11+
git clone $BLKTEST_URL . # No optimization
12+
git clone --depth 1 $GSTREAMER_URL . # Partial optimization
13+
git clone --depth=1 $LIBCAMERA_URL . # Different syntax
14+
git clone $DEQP_RUNNER_GIT_URL --single-branch --no-checkout # Mixed approach
15+
git clone -b ${LTP_SHA} ${LTP_URL} # Branch-specific
16+
17+
# Changed into format of this optimal git options
18+
git clone --depth=1 --single-branch [--branch=<branch>] <repository_url> <target_dir>
19+
# I can use it as
20+
git_clone_optimized https://github.com/octocat/Hello-World.git hello-world-test
21+

test-git-clone.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "=== Testing Git Clone Optimization ==="
5+
6+
# Check if git-operations.sh exists
7+
if [ ! -f "./config/rootfs/debos/scripts/git-operations.sh" ]; then
8+
echo "Error: git-operations.sh not found!"
9+
exit 1
10+
fi
11+
12+
# Source our git operations function
13+
source ./config/rootfs/debos/scripts/git-operations.sh
14+
15+
# Test the function with a small repository
16+
echo "Testing git_clone_optimized..."
17+
18+
# Create a temporary directory for testing
19+
TEMP_DIR="/tmp/git-test-$$"
20+
mkdir -p "$TEMP_DIR"
21+
cd "$TEMP_DIR"
22+
23+
echo "Temp directory: $TEMP_DIR"
24+
25+
# Test with a small repository (auto-detect branch)
26+
echo "Cloning test repository (auto-detect default branch)..."
27+
if git_clone_optimized https://github.com/octocat/Hello-World.git hello-world-test; then
28+
echo "✓ Clone successful"
29+
30+
if [ -d "hello-world-test" ]; then
31+
cd hello-world-test
32+
echo "Commit count: $(git rev-list --count HEAD)"
33+
echo "Current branch: $(git branch --show-current)"
34+
echo "All branches: $(git branch -a)"
35+
echo "Repository size: $(du -sh . | cut -f1)"
36+
cd ..
37+
fi
38+
39+
# Cleanup
40+
rm -rf hello-world-test
41+
echo "✓ Test completed successfully"
42+
else
43+
echo "✗ Clone failed"
44+
exit 1
45+
fi
46+
47+
# Cleanup temp directory
48+
cd /
49+
rm -rf "$TEMP_DIR"

0 commit comments

Comments
 (0)