From: alex Date: Tue, 21 Sep 2021 06:04:17 +0000 (-0700) Subject: major refactor X-Git-Tag: v1.0.0~1 X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=2236247b9692e717204c67e076b5a46dc4469ccd;p=git-extra major refactor refactored into shell script added scripts as tests removed old project in C removed autotools dependency added Makefile --- diff --git a/.gitignore b/.gitignore index b1eaae0..07d19e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,2 @@ -# autoconf/automake -Makefile -*.in -*.in~ -aclocal.m4 -autom4te.cache -autoscan.log -build-aux -config.log -config.status -configure -configure.scan -include/config.h -include/stamp-h1 -src/.deps -src/.dirstamp -test/unit/.deps - -# build objects -*.o -*.log -*.trs -*.tests -git-ex \ No newline at end of file +test/source.sh +test/.testdir diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 559c4cd..0000000 --- a/Dockerfile +++ /dev/null @@ -1,77 +0,0 @@ -FROM debian:latest as base - -RUN apt-get update -RUN apt-get install -y git autoconf automake gcc make vim - -FROM base as unit-tester - -RUN apt-get install -y gdb vim valgrind - -FROM base as core - -WORKDIR /build - -COPY Makefile.am . -COPY configure.ac . - -COPY README.md . -COPY templates templates/ - -COPY test test/ - -COPY include include/ -RUN autoreconf -vif - -COPY src src/ -RUN ./configure - -RUN make -RUN make distcheck -RUN make install - -FROM unit-tester - -WORKDIR /build -COPY --from=core /build /build - -COPY --from=core /usr/local/share/git-extra/templates/ /usr/local/share/git-extra/templates/ - -RUN ./configure -RUN make check || cat test/unit/test-suite.log - -FROM node:latest as integration-tester - -COPY --from=core /usr/local/bin/git-ex /usr/local/bin/git-ex -COPY --from=core /usr/local/share/git-extra/templates/ /usr/local/share/git-extra/templates/ - -USER node -WORKDIR /home/node - -COPY --from=core --chown=node:node /build/test/integration/index.js . -COPY --from=core --chown=node:node /build/test/integration/package.json . -COPY --from=core --chown=node:node /build/test/integration/package-lock.json . - -RUN npm install - -COPY --from=core --chown=node:node /build/test/integration/test/ test/ - -RUN npm test - -FROM core as final - -WORKDIR /root -RUN git init working - -# setup test repository; Docker image meant to be a sandbox -WORKDIR /root/working - -RUN echo "test" > test.txt -RUN git config --global core.editor vim - -RUN git config --local user.name "test" -RUN git config --local user.email "test@email" - -RUN git add -A -RUN git commit -a -m "..." - -ENTRYPOINT bash \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c36ab6c --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +PREFIX ?= /usr/local +BINDIR ?= $(PREFIX)/bin + +all: + @echo "git-extra is a shell script; nothing to make. Try 'make install' instead." + +check: + @head -n `grep -n "main()" git-extra | cut -f1 -d:` git-extra | head -n -1 > test/source.sh + @cd test && run-parts --exit-on-error --regex '.*\.tests\.sh' . + +clean: + @rm -vrf test/.testdir + +install: + @install -v -d "$(BINDIR)/" && install -m 0755 -v git-extra "$(BINDIR)/git-ex" + +uninstall: + @rm -vrf \ + $(BINDIR)/git-ex + +.PHONY: install uninstall check clean diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 6334348..0000000 --- a/Makefile.am +++ /dev/null @@ -1,76 +0,0 @@ -templatesdir=$(datadir)/git-extra/templates - -AM_CPPFLAGS = \ - -I$(top_builddir)/include/ \ - -I$(top_srcdir)/include/ \ - -DTEMPLATE_DIR='"$(templatesdir)"' - -bin_PROGRAMS = git-ex -git_ex_SOURCES = \ - src/add.c \ - src/branch.c \ - src/cat.c \ - src/commit.c \ - src/default.c \ - src/edit.c \ - src/editor.c \ - src/exec.c \ - src/git.c \ - src/hash.c \ - src/log.c \ - src/ls.c \ - src/main.c \ - src/prepend.c \ - src/templ.c -git_ex_SOURCES += \ - include/add.h \ - include/branch.h \ - include/cat.h \ - include/commit.h \ - include/default.h \ - include/edit.h \ - include/editor.h \ - include/exec.h \ - include/git.h \ - include/hash.h \ - include/log.h \ - include/ls.h \ - include/main.h \ - include/opt.h \ - include/prepend.h \ - include/templ.h - -dist_doc_DATA = $(top_srcdir)/README.md -dist_templates_DATA = \ - $(top_srcdir)/templates/bug.template - -SUBDIRS = test/integration test/unit - -if HAVE_DOCKER -IMAGE_NAME=git-extra -CONTAINER_NAME=git-extra-test -build: - docker build -t $(IMAGE_NAME) . - -run: build - docker run -d \ - --name $(CONTAINER_NAME) \ - --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \ - $(IMAGE_NAME) - -start: build - -docker run -it --rm \ - --cap-add=SYS_PTRACE --security-opt seccomp=unconfined \ - $(IMAGE_NAME) - -stop: - docker stop $(CONTAINER_NAME) - docker rm $(CONTAINER_NAME); -else -build: missing-local -run: missing-local -start: missing-local -stop: missing-local -missing-local: - @echo "docker not found" -endif \ No newline at end of file diff --git a/configure.ac b/configure.ac deleted file mode 100644 index bc6f3f6..0000000 --- a/configure.ac +++ /dev/null @@ -1,72 +0,0 @@ -AC_PREREQ([2.69]) -AC_INIT([git-extra], [0.0.0]) - -# Store build files not in main directory -AC_CONFIG_AUX_DIR([build-aux]) - -AM_INIT_AUTOMAKE([foreign subdir-objects nostdinc -Wall -Werror]) - -AC_CONFIG_SRCDIR([src/main.c]) -AC_CONFIG_HEADERS([include/config.h]) - -AC_ARG_ENABLE([memcheck], - [AS_HELP_STRING([--disable-memcheck], - [disable valgrind (enabled by default)])], - [enable_memcheck=$enableval], - [enable_memcheck=yes]) - -AC_PATH_PROG([GIT], [git]) -AM_CONDITIONAL([HAVE_GIT], [test -n "$GIT"]) -AM_COND_IF([HAVE_GIT],,[AC_MSG_ERROR([Please install git before trying to build git-extra])]) - -AC_PATH_PROG([DOCKER], [docker]) -AM_CONDITIONAL([HAVE_DOCKER], [test -n "$DOCKER"]) - -AC_PATH_PROG([NODE], [node]) -AM_CONDITIONAL([HAVE_NODE], [test -n "$NODE"]) - -AC_PATH_PROG([VALGRIND], [valgrind]) -AM_CONDITIONAL([HAVE_VALGRIND], [test -n "$VALGRIND"]) - -dnl disable memcheck if valgrind not found -if test "x$enable_memcheck" = "xyes"; then - if test -z "$VALGRIND"; then - enable_memcheck=no - fi -fi - -AC_MSG_CHECKING([if memcheck should be enabled]) -if test x$enable_memcheck != xno; then - AC_MSG_RESULT(yes) -else - AC_MSG_RESULT(no) -fi - -AM_CONDITIONAL([ENABLE_MEMCHECK],[test x$enable_memcheck = xyes]) - -# Checks for programs. -AC_PROG_CC -AC_PROG_INSTALL - -# Checks for libraries. - -# Checks for header files. -AC_CHECK_HEADERS([stddef.h stdlib.h string.h unistd.h]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_TYPE_OFF_T -AC_TYPE_PID_T -AC_TYPE_SIZE_T -AC_TYPE_SSIZE_T - -# Checks for library functions. -AC_FUNC_FORK -AC_FUNC_MALLOC -AC_CHECK_FUNCS([dup2 getcwd memset setenv]) - -AC_CONFIG_FILES([ - Makefile - test/integration/Makefile - test/unit/Makefile -]) -AC_OUTPUT diff --git a/git-extra b/git-extra new file mode 100644 index 0000000..f566e17 --- /dev/null +++ b/git-extra @@ -0,0 +1,310 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# Option variables +LOG_LEVEL=default +BRANCH=extra +EDITOR= +MESSAGE= +TEMPLATE= + +# helper variables +LONG_OUTPUT=false +POSITIONAL_ARGUMENTS= +PREFIX= +PREV_COMMIT= +UTILITY=ls +WORKING_BRANCH= + +detect_git() { + if [[ -z "`git --version`" ]]; then + log_err "git not found in path" + exit 1 + fi +} + +detect_commits() { + set +e + git rev-list --count HEAD > /dev/null 2>&1 + if [[ $? -ne 0 ]]; then + log_err "no commits found, create initial commit first" + exit 1 + fi + set -e +} + +log_info() { + if [[ "$LOG_LEVEL" == "info" ]]; then + log "$@" + fi +} + +log_err() { + echo -e "$@" +} + +log() { + if [[ "$LOG_LEVEL" != "error" ]]; then + echo -e "$@" + fi +} + +usage() { + log_err "Usage:" + log_err "" + log_err "\tgit extra [options] [add|cat|edit|ls] [path]" + log_err "" + log_err "Options:" + log_err "\t--branch, -b " + log_err "\t--editor, -e " + log_err "\t--long, -l" + log_err "\t--message, -m " + log_err "\t--quiet, -q" + log_err "\t--template, -t