Skip to content
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
9 changes: 6 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.1
- uses: actions/checkout@v4
with:
# For PRs from forks, checkout the merge commit to avoid branch name conflicts
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.1
45 changes: 30 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Test

on:
push:
branches: [ '*' ]
branches: ["*"]
pull_request:
branches: [ '*' ]
branches: ["*"]

jobs:
test:
Expand All @@ -14,16 +14,31 @@ jobs:
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v2
- if: startsWith(matrix.os, 'macos')
run: brew install bash
- run:
git config --global user.email "you@example.com";
git config --global user.name "Your Name";
git config --global init.defaultBranch "master";
git config --global --add safe.directory "$PWD";
git config --global --add safe.directory "$PWD.git";
- if: startsWith(matrix.os, 'macos')
run: make test
- if: startsWith(matrix.os, 'ubuntu')
run: make docker-tests
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Ensure we're on a proper branch
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
# For PRs, create a local branch from the HEAD
git checkout -b "pr-${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.ref }}"
elif git symbolic-ref -q HEAD >/dev/null; then
# Already on a branch, nothing to do
echo "Already on branch $(git branch --show-current)"
else
# Detached HEAD, create a branch
git checkout -b "workflow-$(date +%s)"
fi
- if: startsWith(matrix.os, 'macos')
run: brew install bash
- run: git config --global user.email "you@example.com";
git config --global user.name "Your Name";
git config --global init.defaultBranch "master";
git config --global --add safe.directory "$PWD";
git config --global --add safe.directory "$PWD.git";
- if: startsWith(matrix.os, 'macos')
run: make test
- if: startsWith(matrix.os, 'ubuntu')
run: make docker-tests
47 changes: 39 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ INSTALL_EXT ?= $(INSTALL_LIB)/$(NAME).d
INSTALL_MAN1 ?= $(DESTDIR)$(PREFIX)/share/man/man1

# Docker variables:
DOCKER_TAG ?= 0.0.7
DOCKER_IMAGE := ingy/bash-testing:$(DOCKER_TAG)
BASH_VERSIONS ?= 5.2 5.1 5.0 4.4 4.3 4.2 4.1 4.0
DOCKER_TESTS := $(BASH_VERSIONS:%=docker-test-%)
GIT_VERSIONS := 2.48 2.40 2.30 2.29 2.25 2.17 2.7
DOCKER_TAG ?= admorgan/git-subrepo-testing:1.0
DOCKER_IMAGE := $(DOCKER_TAG)
BASH_VERSIONS ?= 5.3 5.2 5.1 5.0 4.4 4.3 4.2 4.1 4.0
GIT_VERSIONS := 2.51 2.48 2.40 2.30 2.29 2.25 2.23

# Create matrix of all bash/git combinations for comprehensive testing
BASH_GIT_COMBINATIONS := $(foreach bash,$(BASH_VERSIONS),$(foreach git,$(GIT_VERSIONS),$(bash)-$(git)))
DOCKER_TESTS := $(BASH_GIT_COMBINATIONS:%=docker-test-%)
DOCKER_BASH_TESTS := $(BASH_VERSIONS:%=docker-bash-test-%)

prove ?=
test ?= test/
bash ?= 5.2
git ?= 2.48
bash ?= 5.3
git ?= 2.51

# Basic targets:
default: help
Expand All @@ -43,6 +47,16 @@ help:
@echo 'install Install $(NAME)'
@echo 'uninstall Uninstall $(NAME)'
@echo 'env Show environment variables to set'
@echo ''
@echo 'Docker testing:'
@echo 'docker-build Build Docker image with multiple bash/git versions'
@echo 'docker-tests Test ALL bash/git combinations (comprehensive)'
@echo 'docker-bash-tests Test all bash versions with default git (faster)'
@echo 'docker-test Test specific bash/git: make docker-test bash=5.1 git=2.25'
@echo ''
@echo 'Available bash versions: $(BASH_VERSIONS)'
@echo 'Available git versions: $(GIT_VERSIONS)'
@echo ''

.PHONY: test
test:
Expand All @@ -53,10 +67,26 @@ test-all: test docker-tests
docker-test:
$(call docker-make-test,$(bash),$(git))

docker-build:
docker build -t $(DOCKER_TAG) test/

# Test all bash/git combinations (comprehensive but slow)
docker-tests: $(DOCKER_TESTS)

# Test all bash versions with default git (faster option)
docker-bash-tests: $(DOCKER_BASH_TESTS)



# Parse bash-git combination from target name
$(DOCKER_TESTS):
$(call docker-make-test,$(@:docker-test-%=%),$(git))
$(eval BASH_VER := $(shell echo "$(@:docker-test-%=%)" | cut -d'-' -f1))
$(eval GIT_VER := $(shell echo "$(@:docker-test-%=%)" | cut -d'-' -f2))
$(call docker-make-test,$(BASH_VER),$(GIT_VER))

# Test specific bash version with default git
$(DOCKER_BASH_TESTS):
$(call docker-make-test,$(@:docker-bash-test-%=%),$(git))

# Install support:
install:
Expand Down Expand Up @@ -109,6 +139,7 @@ clean:

define docker-make-test
docker run --rm \
--user $(shell id -u):$(shell id -g) \
-v $(PWD):/git-subrepo \
-w /git-subrepo \
$(DOCKER_IMAGE) \
Expand Down
2 changes: 1 addition & 1 deletion Meta
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ author:

requires:
bash: 4.0.0
git: 2.7.0
git: 2.23.0
test:
cmd: make test
install: make install
Expand Down
2 changes: 1 addition & 1 deletion ReadMe.pod
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The best short answer is:

The complete "Installation Instructions" can be found below.

Note: git-subrepo needs a git version (> 2.7) that supports worktree:s.
Note: git-subrepo needs a git version >= 2.23) due to changes in --is-ansestor.

=head1 Commands

Expand Down
15 changes: 13 additions & 2 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bash+:import :std can version-check

VERSION=0.4.9
REQUIRED_BASH_VERSION=4.0
REQUIRED_GIT_VERSION=2.7.0
REQUIRED_GIT_VERSION=2.23.0
GIT_TMP=$(git rev-parse --git-common-dir 2> /dev/null || echo .git)/tmp

# `git rev-parse` turns this into a getopt parser and a command usage message:
Expand Down Expand Up @@ -212,7 +212,18 @@ command:clone() {
command:init() {
command-setup +subdir
local default_branch=
default_branch=$(git config --get --default=master init.defaultbranch)
# Check if Git supports init.defaultbranch (Git 2.28+)
local git_version
local git_major
local git_minor
git_version=$(git --version | sed 's/git version //' | sed 's/\..*//')
git_major=$(echo "$git_version" | cut -d. -f1)
git_minor=$(echo "$git_version" | cut -d. -f2)
if [[ $git_major -gt 2 ]] || [[ $git_major -eq 2 && $git_minor -ge 28 ]]; then
default_branch=$(git config --get init.defaultbranch 2>/dev/null || echo "master")
else
default_branch="master"
fi
local remote=${subrepo_remote:=none}
local branch=${subrepo_branch:=$default_branch}

Expand Down
Loading