diff --git a/config/rootfs/debos/scripts/git-operations.sh b/config/rootfs/debos/scripts/git-operations.sh new file mode 100644 index 0000000000..9ff452169b --- /dev/null +++ b/config/rootfs/debos/scripts/git-operations.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# git-operations.sh - Standardized git operations for KernelCI rootfs builds + +# Optimized git clone function for CI environments +# Usage: git_clone_optimized [branch] [depth] +git_clone_optimized() { + local repo_url="$1" + local target_dir="$2" + local branch="${3:-}" + local depth="${4:-1}" + + if [ $# -lt 2 ]; then + echo "Usage: git_clone_optimized [branch] [depth]" + return 1 + fi + + echo "Cloning $repo_url (depth: $depth) to $target_dir" + + # If no branch specified, let git choose the default + if [ -z "$branch" ]; then + echo "No branch specified, using repository default" + git clone \ + --depth="$depth" \ + --single-branch \ + "$repo_url" \ + "$target_dir" + else + echo "Using specified branch: $branch" + git clone \ + --depth="$depth" \ + --single-branch \ + --branch="$branch" \ + "$repo_url" \ + "$target_dir" + fi +} + +# Wrapper for backward compatibility +git_clone() { + if [[ $# -eq 2 && -z "${3:-}" ]]; then + echo "Warning: Using deprecated git clone interface. Consider updating to git_clone_optimized" + git_clone_optimized "$1" "$2" + else + git_clone_optimized "$@" + fi +} diff --git a/doc/git_clone_optimization.md b/doc/git_clone_optimization.md new file mode 100644 index 0000000000..97593bbdcf --- /dev/null +++ b/doc/git_clone_optimization.md @@ -0,0 +1,21 @@ +## Overview + +This document establishes standardized git clone operations for KernelCI rootfs builder scripts to reduce network traffic and improve build performance in CI environments. + +## Problem Statement + +Rootfs builder scripts currently use inconsistent git clone approaches: + +```bash +# Found patterns across scripts: +git clone $BLKTEST_URL . # No optimization +git clone --depth 1 $GSTREAMER_URL . # Partial optimization +git clone --depth=1 $LIBCAMERA_URL . # Different syntax +git clone $DEQP_RUNNER_GIT_URL --single-branch --no-checkout # Mixed approach +git clone -b ${LTP_SHA} ${LTP_URL} # Branch-specific + +# Changed into format of this optimal git options +git clone --depth=1 --single-branch [--branch=] +# I can use it as +git_clone_optimized https://github.com/octocat/Hello-World.git hello-world-test + diff --git a/test-git-clone.sh b/test-git-clone.sh new file mode 100644 index 0000000000..c271d9f098 --- /dev/null +++ b/test-git-clone.sh @@ -0,0 +1,49 @@ +#!/bin/bash +set -e + +echo "=== Testing Git Clone Optimization ===" + +# Check if git-operations.sh exists +if [ ! -f "./config/rootfs/debos/scripts/git-operations.sh" ]; then + echo "Error: git-operations.sh not found!" + exit 1 +fi + +# Source our git operations function +source ./config/rootfs/debos/scripts/git-operations.sh + +# Test the function with a small repository +echo "Testing git_clone_optimized..." + +# Create a temporary directory for testing +TEMP_DIR="/tmp/git-test-$$" +mkdir -p "$TEMP_DIR" +cd "$TEMP_DIR" + +echo "Temp directory: $TEMP_DIR" + +# Test with a small repository (auto-detect branch) +echo "Cloning test repository (auto-detect default branch)..." +if git_clone_optimized https://github.com/octocat/Hello-World.git hello-world-test; then + echo "✓ Clone successful" + + if [ -d "hello-world-test" ]; then + cd hello-world-test + echo "Commit count: $(git rev-list --count HEAD)" + echo "Current branch: $(git branch --show-current)" + echo "All branches: $(git branch -a)" + echo "Repository size: $(du -sh . | cut -f1)" + cd .. + fi + + # Cleanup + rm -rf hello-world-test + echo "✓ Test completed successfully" +else + echo "✗ Clone failed" + exit 1 +fi + +# Cleanup temp directory +cd / +rm -rf "$TEMP_DIR"