Skip to content

Added optimized git clone script in config/rootfs/debos/scripts/git-operations.sh #2914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
46 changes: 46 additions & 0 deletions config/rootfs/debos/scripts/git-operations.sh
Original file line number Diff line number Diff line change
@@ -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 <repository_url> <target_dir> [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 <repo_url> <target_dir> [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
}
21 changes: 21 additions & 0 deletions doc/git_clone_optimization.md
Original file line number Diff line number Diff line change
@@ -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=<branch>] <repository_url> <target_dir>
# I can use it as
git_clone_optimized https://github.com/octocat/Hello-World.git hello-world-test

49 changes: 49 additions & 0 deletions test-git-clone.sh
Original file line number Diff line number Diff line change
@@ -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"