Skip to content
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

Debian patchset against 0.4.9 release #639

Open
wants to merge 6 commits into
base: master
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
32 changes: 20 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL := bash
INSTALL ?= install

# Make sure we have git:
ifeq ($(shell which git),)
Expand All @@ -17,9 +18,11 @@ SHARE = share

# Install variables:
PREFIX ?= /usr/local
INSTALL_LIB ?= $(DESTDIR)$(shell git --exec-path)
INSTALL_BIN ?= $(PREFIX)/bin
INSTALL_LIB ?= $(PREFIX)/share/$(NAME)
INSTALL_EXT ?= $(INSTALL_LIB)/$(NAME).d
INSTALL_MAN1 ?= $(DESTDIR)$(PREFIX)/share/man/man1
INSTALL_MAN1 ?= $(PREFIX)/share/man/man1
LINK_REL_DIR := $(shell bash share/pnrelpath.sh $(INSTALL_BIN) $(INSTALL_LIB))

# Docker variables:
DOCKER_TAG ?= 0.0.6
Expand All @@ -46,6 +49,7 @@ help:

.PHONY: test
test:
@echo uname: '$(shell uname)'
prove $(prove) $(test)

test-all: test docker-tests
Expand All @@ -60,18 +64,22 @@ $(DOCKER_TESTS):

# Install support:
install:
install -d -m 0755 $(INSTALL_LIB)/
install -C -m 0755 $(LIB) $(INSTALL_LIB)/
install -d -m 0755 $(INSTALL_EXT)/
install -C -m 0644 $(EXTS) $(INSTALL_EXT)/
install -d -m 0755 $(INSTALL_MAN1)/
install -C -m 0644 $(MAN1)/$(NAME).1 $(INSTALL_MAN1)/
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_LIB)/
$(INSTALL) -C -m 0755 $(LIB) $(DESTDIR)$(INSTALL_LIB)/
sed -i 's!^SUBREPO_EXT_DIR=.*!SUBREPO_EXT_DIR=$(INSTALL_EXT)!' $(DESTDIR)$(INSTALL_LIB)/$(NAME)
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_BIN)
ln -s $(LINK_REL_DIR)/$(NAME) $(DESTDIR)$(INSTALL_BIN)/$(NAME)
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_EXT)/
$(INSTALL) -C -m 0644 $(EXTS) $(DESTDIR)$(INSTALL_EXT)/
$(INSTALL) -d -m 0755 $(DESTDIR)$(INSTALL_MAN1)/
$(INSTALL) -C -m 0644 $(MAN1)/$(NAME).1 $(DESTDIR)$(INSTALL_MAN1)/

# Uninstall support:
uninstall:
rm -f $(INSTALL_LIB)/$(NAME)
rm -fr $(INSTALL_EXT)
rm -f $(INSTALL_MAN1)/$(NAME).1
rm -f $(DESTDIR)$(INSTALL_BIN)/$(NAME)
rm -fr $(DESTDIR)$(INSTALL_EXT)
rm -fr $(DESTDIR)$(INSTALL_LIB)
rm -f $(DESTDIR)$(INSTALL_MAN1)/$(NAME).1

env:
@echo "export PATH=\"$$PWD/lib:\$$PATH\""
Expand Down Expand Up @@ -103,7 +111,7 @@ compgen: force
$(SHARE)/zsh-completion/_git-subrepo

clean:
rm -fr tmp test/tmp
rm -fr tmp test/tmp test/repo .gitconfig

define docker-make-test
docker run --rm \
Expand Down
21 changes: 4 additions & 17 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,8 @@ set -e
export FILTER_BRANCH_SQUELCH_WARNING=1

# Import Bash+ helper functions:
SOURCE=${BASH_SOURCE[0]}
while [[ -h $SOURCE ]]; do
DIR=$( cd -P "$( dirname "$SOURCE" )" && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
done
SOURCE_DIR=$(dirname "$SOURCE")

if [[ -z $GIT_SUBREPO_ROOT ]]; then
# If `make install` installation used:
source "${SOURCE_DIR}/git-subrepo.d/bash+.bash"
else
# If `source .rc` method used:
source "${SOURCE_DIR}/../ext/bashplus/lib/bash+.bash"
fi
SUBREPO_EXT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/git-subrepo.d" # replaced by `make install`
source "${SUBREPO_EXT_DIR}/bash+.bash"
bash+:import :std can version-check


Expand Down Expand Up @@ -396,7 +383,7 @@ command:config() {

# Launch the manpage viewer:
command:help() {
source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
source "${SUBREPO_EXT_DIR}/help-functions.bash"
local cmd=${command_arguments[0]}
if [[ $cmd ]]; then
if can "help:$cmd"; then
Expand Down Expand Up @@ -1992,7 +1979,7 @@ OK() {
usage-error() {
local msg="git-subrepo: $1" usage=
if [[ $GIT_SUBREPO_TEST_ERRORS != true ]]; then
source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
source "${SUBREPO_EXT_DIR}/help-functions.bash"
if can "help:$command"; then
msg=$'\n'"$msg"$'\n'"$("help:$command")"$'\n'
fi
Expand Down
25 changes: 25 additions & 0 deletions share/pnrelpath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
#
# from: https://unix.stackexchange.com/questions/573047/how-to-get-the-relative-path-between-two-directories
#
# Expects two parameters, source-dir and target-dir, both absolute canonicalized
# non-empty pathnames, either may be /-ended, neither need exist.
# Returns result in shell variable $REPLY as a relative path from source-dir
# to target-dir without trailing /, . if void.
#
# Algorithm is from a 2005 comp.unix.shell posting which has now ascended to
# archive.org.

pnrelpath() {
set -- "${1%/}/" "${2%/}/" '' ## '/'-end to avoid mismatch
while [ "$1" ] && [ "$2" = "${2#"$1"}" ] ## reduce $1 to shared path
do set -- "${1%/?*/}/" "$2" "../$3" ## source/.. target ../relpath
done
REPLY="${3}${2#"$1"}" ## build result
# unless root chomp trailing '/', replace '' with '.'
[ "${REPLY#/}" ] && REPLY="${REPLY%/}" || REPLY="${REPLY:-.}"
}

pnrelpath "$1" "$2"

echo $REPLY
55 changes: 55 additions & 0 deletions test/00-git-config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

set -e

source test/setup

use Test::More

note "Define project-wide GIT setup for all tests"

# Get git-subrepo project top directory
PROJ_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )

if [ -z "${PROJ_DIR}" ] || [ "${HOME}" != "${PROJ_DIR}" ]; then
is "${HOME}" "${PROJ_DIR}" \
"To define project-wide GIT setup for all tests: HOME '${HOME}' should equal PROJ_DIR '${PROJ_DIR}'"
else

# Real GIT configuration for tests is set here:
rm -f "${PROJ_DIR}/.gitconfig"
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 "${PROJ_DIR}"
git config --global --add safe.directory "${PROJ_DIR}/.git"
git config --list

test-exists "${PROJ_DIR}/.gitconfig"

# Running tests depends on the whole project being git initialized.
# So, git initialize the project, if necessary.
if [ ! -d "${PROJ_DIR}/.git" ]; then
cd "${PROJ_DIR}"
git init .
git add .
git commit -a -m"Initial commit"
cd -
fi

test-exists "${PROJ_DIR}/.git/"

# Running tests depends on the whole project not being in a GIT detached HEAD state.
if ! git symbolic-ref --short --quiet HEAD &> /dev/null; then
git checkout -b test
fi

ok "$(
git symbolic-ref --short --quiet HEAD &> /dev/null
)" "Whole project is not in a GIT detached HEAD state"

fi

done_testing

teardown
2 changes: 1 addition & 1 deletion test/clone.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clone-foo-and-bar

(
mkdir -p "$OWNER/empty"
git init "$OWNER/empty"
git init --initial-branch="${DEFAULTBRANCH}" "$OWNER/empty"
)

# Test that the repos look ok:
Expand Down
3 changes: 3 additions & 0 deletions test/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ gitrepo=$OWNER/init/doc/.gitrepo

(
cd "$OWNER/init"
git config user.email "ini@ini"
git config user.name "IniUser"
git config init.defaultBranch "${DEFAULTBRANCH}"
git subrepo init doc
) > /dev/null

Expand Down
31 changes: 31 additions & 0 deletions test/genbar
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -xe

if [ -z "${1}" ]; then
echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)"
exit 1
fi

REPO="bar"
NAME="Bar"
TARGET="${1}/$REPO"
TMPREPO="${1}/tmp/$REPO"

rm -rf "$TMPREPO"
mkdir -p "$TMPREPO"
cd "$TMPREPO"
git init --initial-branch=master .
git config user.name "${NAME}User"
git config user.email "${REPO}@${REPO}"
touch $NAME
git add $NAME
git commit -m"$NAME"
git tag A -m"$NAME"
mkdir -p bard
touch bard/Bard
git add bard
git commit -m"bard/Bard"
git config --bool core.bare true
cd -
mkdir -p "$1"
mv "$TMPREPO/.git" "$TARGET"
26 changes: 26 additions & 0 deletions test/genfoo
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -xe

if [ -z "${1}" ]; then
echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)"
exit 1
fi

REPO="foo"
NAME="Foo"
TARGET="${1}/$REPO"
TMPREPO="${1}/tmp/$REPO"

rm -rf "$TMPREPO"
mkdir -p "$TMPREPO"
cd "$TMPREPO"
git init --initial-branch=master .
git config user.name "${NAME}User"
git config user.email "${REPO}@${REPO}"
touch $NAME
git add $NAME
git commit -m"$NAME"
git config --bool core.bare true
cd -
mkdir -p "$1"
mv "${TMPREPO}/.git" "$TARGET"
60 changes: 60 additions & 0 deletions test/geninit
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
set -xe

if [ -z "${1}" ]; then
echo "${BASH_SOURCE[0]}: Single argument required (common test repos path)"
exit 1
fi

REPO="init"
NAME="Init"
TARGET="${1}/$REPO"
TMPREPO="${1}/tmp/$REPO"

rm -rf "$TMPREPO"
mkdir -p "$TMPREPO"
cd "$TMPREPO"
git init --initial-branch=master .
git config user.name "${NAME}User"
git config user.email "${REPO}@${REPO}"
cat <<EOF > ReadMe
This is a repo to test \`git subrepo init\`.

We will make a short history with a subdir, then we can turn that subdir into a
subrepo.
EOF
git add ReadMe
git commit -m"Initial commit"
mkdir -p doc
cat <<EOF > doc/init.swim
== Subrepo Init!

This is a file to test the \`git subrepo init\` command.
EOF
git add doc
git commit -m"Add a file in a subdir."
cat <<EOF >> ReadMe

This repo will go in the git-subrepo test suite.
EOF
git add ReadMe
git commit -m"Add a commit to the mainline."
cat <<EOF >> doc/init.swim

It lives under the doc directory which will become a subrepo.
EOF
git add doc/init.swim
git commit -m"Add a commit to the subdir."
cat <<EOF >> ReadMe

EOF
git add ReadMe
cat <<EOF >> doc/init.swim

EOF
git add doc/init.swim
git commit -m"Add a commit that affects both."
git config --bool core.bare true
cd -
mkdir -p "$1"
mv "${TMPREPO}/.git" "$TARGET"
6 changes: 6 additions & 0 deletions test/init.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ gitrepo=$OWNER/init/doc/.gitrepo

output=$(
cd "$OWNER/init"
git config user.email "ini@ini"
git config user.name "IniUser"
git config init.defaultBranch "${DEFAULTBRANCH}"
git subrepo init doc
)

Expand All @@ -48,6 +51,9 @@ rm -fr "$OWNER/init"
git clone "$UPSTREAM/init" "$OWNER/init" &>/dev/null
(
cd "$OWNER/init"
git config user.email "ini@ini"
git config user.name "IniUser"
git config init.defaultBranch "${DEFAULTBRANCH}"
git subrepo init doc -r git@github.com:user/repo -b foo -M rebase
) >/dev/null

Expand Down
16 changes: 11 additions & 5 deletions test/issue29.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ cd "$TMP"
# Make 3 new repos:
(
mkdir share main1 main2
git init share
git init main1
git init main2
git init --initial-branch="${DEFAULTBRANCH}" share
git init --initial-branch="${DEFAULTBRANCH}" main1
git init --initial-branch="${DEFAULTBRANCH}" main2
) > /dev/null

# Add an empty 'readme' to the share repo:
(
cd share
git config user.name "ShrUser"
git config user.email "shr@ma1"
echo '* text eol=lf' > .gitattributes
touch readme
git add readme .gitattributes
Expand All @@ -37,19 +39,23 @@ cd "$TMP"
# `subrepo clone` the share repo into main1:
(
cd main1
git config user.name "Ma1User"
git config user.email "ma1@ma1"
touch main1
git add main1
git commit -m "Initial main1"
git subrepo clone ../share share -b "$DEFAULTBRANCH"
git subrepo clone ../share share -b "${DEFAULTBRANCH}"
) > /dev/null

# `subrepo clone` the share repo into main2:
(
cd main2
git config user.name "Ma2User"
git config user.email "ma2@ma2"
touch main2
git add main2
git commit -m "Initial main2"
git subrepo clone ../share share -b "$DEFAULTBRANCH"
git subrepo clone ../share share -b "${DEFAULTBRANCH}"
) > /dev/null


Expand Down
Loading