summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/README4
-rw-r--r--contrib/buildsystems/CMakeLists.txt1139
-rw-r--r--contrib/buildsystems/Generators/Vcxproj.pm16
-rwxr-xr-xcontrib/buildsystems/engine.pl5
-rw-r--r--contrib/coccinelle/.gitignore2
-rw-r--r--contrib/coccinelle/README87
-rw-r--r--contrib/coccinelle/array.cocci97
-rw-r--r--contrib/coccinelle/commit.cocci20
-rw-r--r--contrib/coccinelle/config_fn_ctx.pending.cocci144
-rw-r--r--contrib/coccinelle/equals-null.cocci30
-rw-r--r--contrib/coccinelle/free.cocci27
-rw-r--r--contrib/coccinelle/git_config_number.cocci27
-rw-r--r--contrib/coccinelle/hashmap.cocci2
-rw-r--r--contrib/coccinelle/index-compatibility.cocci157
-rw-r--r--contrib/coccinelle/object_id.cocci44
-rw-r--r--contrib/coccinelle/preincr.cocci2
-rwxr-xr-xcontrib/coccinelle/spatchcache304
-rw-r--r--contrib/coccinelle/strbuf.cocci8
-rw-r--r--contrib/coccinelle/swap.cocci2
-rw-r--r--contrib/coccinelle/tests/free.c11
-rw-r--r--contrib/coccinelle/tests/free.res9
-rw-r--r--contrib/coccinelle/the_repository.cocci123
-rw-r--r--contrib/coccinelle/the_repository.pending.cocci144
-rw-r--r--contrib/coccinelle/xcalloc.cocci10
-rw-r--r--contrib/coccinelle/xopen.cocci19
-rw-r--r--contrib/coccinelle/xstrdup_or_null.cocci8
-rw-r--r--contrib/coccinelle/xstrncmpz.cocci28
-rw-r--r--contrib/completion/git-completion.bash1450
-rw-r--r--contrib/completion/git-completion.tcsh5
-rw-r--r--contrib/completion/git-completion.zsh146
-rw-r--r--contrib/completion/git-prompt.sh173
-rwxr-xr-xcontrib/coverage-diff.sh9
-rw-r--r--contrib/credential/gnome-keyring/.gitignore1
-rw-r--r--contrib/credential/gnome-keyring/Makefile25
-rw-r--r--contrib/credential/gnome-keyring/git-credential-gnome-keyring.c470
-rw-r--r--contrib/credential/libsecret/.gitignore1
-rw-r--r--contrib/credential/libsecret/git-credential-libsecret.c115
-rw-r--r--contrib/credential/netrc/.gitignore1
-rw-r--r--contrib/credential/netrc/Makefile26
-rwxr-xr-xcontrib/credential/netrc/git-credential-netrc.perl (renamed from contrib/credential/netrc/git-credential-netrc)7
-rwxr-xr-xcontrib/credential/netrc/t-git-credential-netrc.sh18
-rw-r--r--contrib/credential/osxkeychain/Makefile3
-rw-r--r--contrib/credential/osxkeychain/git-credential-osxkeychain.c390
-rw-r--r--contrib/credential/wincred/git-credential-wincred.c179
-rw-r--r--contrib/diff-highlight/DiffHighlight.pm4
-rwxr-xr-xcontrib/fast-import/import-tars.perl2
-rw-r--r--contrib/git-jump/README13
-rwxr-xr-xcontrib/git-jump/git-jump49
-rwxr-xr-xcontrib/git-resurrect.sh13
-rwxr-xr-xcontrib/hg-to-git/hg-to-git.py254
-rw-r--r--contrib/hg-to-git/hg-to-git.txt21
-rw-r--r--contrib/hooks/multimail/CHANGES285
-rw-r--r--contrib/hooks/multimail/CONTRIBUTING.rst60
-rw-r--r--contrib/hooks/multimail/README.Git12
-rw-r--r--contrib/hooks/multimail/README.migrate-from-post-receive-email145
-rw-r--r--contrib/hooks/multimail/README.rst774
-rw-r--r--contrib/hooks/multimail/doc/customizing-emails.rst56
-rw-r--r--contrib/hooks/multimail/doc/gerrit.rst56
-rw-r--r--contrib/hooks/multimail/doc/gitolite.rst118
-rw-r--r--contrib/hooks/multimail/doc/troubleshooting.rst78
-rwxr-xr-xcontrib/hooks/multimail/git_multimail.py4346
-rwxr-xr-xcontrib/hooks/multimail/migrate-mailhook-config274
-rwxr-xr-xcontrib/hooks/multimail/post-receive.example101
-rwxr-xr-xcontrib/hooks/post-receive-email2
-rwxr-xr-xcontrib/hooks/update-paranoid2
-rw-r--r--contrib/mw-to-git/.perlcriticrc2
-rw-r--r--contrib/mw-to-git/Git/Mediawiki.pm2
-rwxr-xr-xcontrib/mw-to-git/git-mw.perl2
-rwxr-xr-xcontrib/mw-to-git/git-remote-mediawiki.perl82
-rw-r--r--contrib/mw-to-git/git-remote-mediawiki.txt2
-rw-r--r--contrib/mw-to-git/t/.gitignore2
-rw-r--r--contrib/mw-to-git/t/README10
-rw-r--r--contrib/mw-to-git/t/install-wiki/.gitignore1
-rw-r--r--contrib/mw-to-git/t/install-wiki/LocalSettings.php129
-rw-r--r--contrib/mw-to-git/t/install-wiki/db_install.php120
-rwxr-xr-xcontrib/mw-to-git/t/t9360-mw-to-git-clone.sh12
-rwxr-xr-xcontrib/mw-to-git/t/t9362-mw-to-git-utf8.sh4
-rwxr-xr-xcontrib/mw-to-git/t/t9363-mw-to-git-export-import.sh11
-rwxr-xr-xcontrib/mw-to-git/t/t9365-continuing-queries.sh2
-rwxr-xr-xcontrib/mw-to-git/t/test-gitmw-lib.sh164
-rwxr-xr-xcontrib/mw-to-git/t/test-gitmw.pl22
-rw-r--r--contrib/mw-to-git/t/test.config23
-rwxr-xr-xcontrib/rerere-train.sh6
-rw-r--r--contrib/subtree/Makefile6
-rwxr-xr-xcontrib/subtree/git-subtree.sh805
-rw-r--r--contrib/subtree/git-subtree.txt200
-rw-r--r--contrib/subtree/t/Makefile7
-rwxr-xr-xcontrib/subtree/t/t7900-subtree.sh1536
-rw-r--r--contrib/subtree/todo6
-rw-r--r--contrib/svn-fe/.gitignore4
-rw-r--r--contrib/svn-fe/Makefile105
-rw-r--r--contrib/svn-fe/svn-fe.c18
-rw-r--r--contrib/svn-fe/svn-fe.txt71
-rwxr-xr-xcontrib/svn-fe/svnrdump_sim.py68
-rw-r--r--contrib/vscode/README.md6
-rwxr-xr-xcontrib/vscode/init.sh10
-rwxr-xr-xcontrib/workdir/git-new-workdir2
97 files changed, 5969 insertions, 9624 deletions
diff --git a/contrib/README b/contrib/README
index 05f291c..21d3d0e 100644
--- a/contrib/README
+++ b/contrib/README
@@ -23,7 +23,7 @@ This is the same way as how I have been treating gitk, and to a
lesser degree various foreign SCM interfaces, so you know the
drill.
-I expect that things that start their life in the contrib/ area
+I expect things that start their life in the contrib/ area
to graduate out of contrib/ once they mature, either by becoming
projects on their own, or moving to the toplevel directory. On
the other hand, I expect I'll be proposing removal of disused
@@ -31,7 +31,7 @@ and inactive ones from time to time.
If you have new things to add to this area, please first propose
it on the git mailing list, and after a list discussion proves
-there are some general interests (it does not have to be a
+there is general interest (it does not have to be a
list-wide consensus for a tool targeted to a relatively narrow
audience -- for example I do not work with projects whose
upstream is svn, so I have no use for git-svn myself, but it is
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
new file mode 100644
index 0000000..804629c
--- /dev/null
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -0,0 +1,1139 @@
+#
+# Copyright (c) 2020 Sibi Siddharthan
+#
+
+#[[
+
+Instructions how to use this in Visual Studio:
+
+Open the worktree as a folder. Visual Studio 2019 and later will detect
+the CMake configuration automatically and set everything up for you,
+ready to build. You can then run the tests in `t/` via a regular Git Bash.
+
+Note: Visual Studio also has the option of opening `CMakeLists.txt`
+directly; Using this option, Visual Studio will not find the source code,
+though, therefore the `File>Open>Folder...` option is preferred.
+
+Instructions to run CMake manually:
+
+ mkdir -p contrib/buildsystems/out
+ cd contrib/buildsystems/out
+ cmake ../ -DCMAKE_BUILD_TYPE=Release
+
+This will build the git binaries in contrib/buildsystems/out
+directory (our top-level .gitignore file knows to ignore contents of
+this directory).
+
+Possible build configurations(-DCMAKE_BUILD_TYPE) with corresponding
+compiler flags
+Debug : -g
+Release: -O3
+RelWithDebInfo : -O2 -g
+MinSizeRel : -Os
+empty(default) :
+
+NOTE: -DCMAKE_BUILD_TYPE is optional. For multi-config generators like Visual Studio
+this option is ignored
+
+This process generates a Makefile(Linux/*BSD/MacOS) , Visual Studio solution(Windows) by default.
+Run `make` to build Git on Linux/*BSD/MacOS.
+Open git.sln on Windows and build Git.
+
+NOTE: By default CMake uses Makefile as the build tool on Linux and Visual Studio in Windows,
+to use another tool say `ninja` add this to the command line when configuring.
+`-G Ninja`
+
+NOTE: By default CMake will install vcpkg locally to your source tree on configuration,
+to avoid this, add `-DNO_VCPKG=TRUE` to the command line when configuring.
+
+]]
+cmake_minimum_required(VERSION 3.14)
+
+#set the source directory to root of git
+set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
+
+option(USE_VCPKG "Whether or not to use vcpkg for obtaining dependencies. Only applicable to Windows platforms" ON)
+if(NOT WIN32)
+ set(USE_VCPKG OFF CACHE BOOL "" FORCE)
+endif()
+
+if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
+ set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
+endif()
+
+if(USE_VCPKG)
+ set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
+ if(NOT EXISTS ${VCPKG_DIR})
+ message("Initializing vcpkg and building the Git's dependencies (this will take a while...)")
+ execute_process(COMMAND ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg_install.bat)
+ endif()
+ list(APPEND CMAKE_PREFIX_PATH "${VCPKG_DIR}/installed/x64-windows")
+
+ # In the vcpkg edition, we need this to be able to link to libcurl
+ set(CURL_NO_CURL_CMAKE ON)
+
+ # Copy the necessary vcpkg DLLs (like iconv) to the install dir
+ set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
+ set(CMAKE_TOOLCHAIN_FILE ${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
+endif()
+
+find_program(SH_EXE sh PATHS "C:/Program Files/Git/bin" "$ENV{LOCALAPPDATA}/Programs/Git/bin")
+if(NOT SH_EXE)
+ message(FATAL_ERROR "sh: shell interpreter was not found in your path, please install one."
+ "On Windows, you can get it as part of 'Git for Windows' install at https://gitforwindows.org/")
+endif()
+
+#Create GIT-VERSION-FILE using GIT-VERSION-GEN
+if(NOT EXISTS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE)
+ message("Generating GIT-VERSION-FILE")
+ execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/GIT-VERSION-GEN
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+endif()
+
+#Parse GIT-VERSION-FILE to get the version
+file(STRINGS ${CMAKE_SOURCE_DIR}/GIT-VERSION-FILE git_version REGEX "GIT_VERSION = (.*)")
+string(REPLACE "GIT_VERSION = " "" git_version ${git_version})
+string(FIND ${git_version} "GIT" location)
+if(location EQUAL -1)
+ string(REGEX MATCH "[0-9]*\\.[0-9]*\\.[0-9]*" git_version ${git_version})
+else()
+ string(REGEX MATCH "[0-9]*\\.[0-9]*" git_version ${git_version})
+ string(APPEND git_version ".0") #for building from a snapshot
+endif()
+
+project(git
+ VERSION ${git_version}
+ LANGUAGES C)
+
+
+#TODO gitk git-gui gitweb
+#TODO Enable NLS on windows natively
+
+#macros for parsing the Makefile for sources and scripts
+macro(parse_makefile_for_sources list_var regex)
+ file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)")
+ string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
+ string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit.
+ string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
+ string(REPLACE ".o" ".c;" ${list_var} ${${list_var}}) #change .o to .c, ; is for converting the string into a list
+ list(TRANSFORM ${list_var} STRIP) #remove trailing/leading whitespaces for each element in list
+ list(REMOVE_ITEM ${list_var} "") #remove empty list elements
+endmacro()
+
+macro(parse_makefile_for_scripts list_var regex lang)
+ file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)")
+ string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
+ string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
+ string(REPLACE " " ";" ${list_var} ${${list_var}}) #convert string to a list
+ if(NOT ${lang}) #exclude for SCRIPT_LIB
+ list(TRANSFORM ${list_var} REPLACE "${lang}" "") #do the replacement
+ endif()
+endmacro()
+
+macro(parse_makefile_for_executables list_var regex)
+ file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+= git-(.*)")
+ string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
+ string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
+ string(REPLACE "git-" "" ${list_var} ${${list_var}}) #strip `git-` prefix
+ string(REPLACE "\$X" ";" ${list_var} ${${list_var}}) #strip $X, ; is for converting the string into a list
+ list(TRANSFORM ${list_var} STRIP) #remove trailing/leading whitespaces for each element in list
+ list(REMOVE_ITEM ${list_var} "") #remove empty list elements
+endmacro()
+
+include(CheckTypeSize)
+include(CheckCSourceRuns)
+include(CheckCSourceCompiles)
+include(CheckIncludeFile)
+include(CheckFunctionExists)
+include(CheckSymbolExists)
+include(CheckStructHasMember)
+include(CTest)
+
+find_package(ZLIB REQUIRED)
+find_package(CURL)
+find_package(EXPAT)
+find_package(Iconv)
+
+#Don't use libintl on Windows Visual Studio and Clang builds
+if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")))
+ find_package(Intl)
+endif()
+
+find_package(PkgConfig)
+if(PkgConfig_FOUND)
+ pkg_check_modules(PCRE2 libpcre2-8)
+ if(PCRE2_FOUND)
+ add_compile_definitions(USE_LIBPCRE2)
+ endif()
+endif()
+
+if(NOT Intl_FOUND)
+ add_compile_definitions(NO_GETTEXT)
+ if(NOT Iconv_FOUND)
+ add_compile_definitions(NO_ICONV)
+ endif()
+endif()
+
+include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
+if(CURL_FOUND)
+ include_directories(SYSTEM ${CURL_INCLUDE_DIRS})
+endif()
+if(EXPAT_FOUND)
+ include_directories(SYSTEM ${EXPAT_INCLUDE_DIRS})
+endif()
+if(Iconv_FOUND)
+ include_directories(SYSTEM ${Iconv_INCLUDE_DIRS})
+endif()
+if(Intl_FOUND)
+ include_directories(SYSTEM ${Intl_INCLUDE_DIRS})
+endif()
+if(PCRE2_FOUND)
+ include_directories(SYSTEM ${PCRE2_INCLUDE_DIRS})
+endif()
+
+
+if(WIN32 AND NOT MSVC)#not required for visual studio builds
+ find_program(WINDRES_EXE windres)
+ if(NOT WINDRES_EXE)
+ message(FATAL_ERROR "Install windres on Windows for resource files")
+ endif()
+endif()
+
+if(NO_GETTEXT)
+ message(STATUS "msgfmt not used under NO_GETTEXT")
+else()
+ find_program(MSGFMT_EXE msgfmt)
+ if(NOT MSGFMT_EXE)
+ if(USE_VCPKG)
+ set(MSGFMT_EXE ${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg/downloads/tools/msys2/msys64/usr/bin/msgfmt.exe)
+ endif()
+ if(NOT EXISTS ${MSGFMT_EXE})
+ message(WARNING "Text Translations won't be built")
+ unset(MSGFMT_EXE)
+ endif()
+ endif()
+endif()
+
+#Force all visual studio outputs to CMAKE_BINARY_DIR
+if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR})
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR})
+ add_compile_options(/MP /std:c11)
+endif()
+
+#default behaviour
+include_directories(${CMAKE_SOURCE_DIR})
+add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
+add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
+add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
+ SHA1DC_INIT_SAFE_HASH_DEFAULT=0
+ SHA1DC_CUSTOM_INCLUDE_SHA1_C="git-compat-util.h"
+ SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" )
+list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c)
+
+
+add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c"
+ GIT_EXEC_PATH="libexec/git-core"
+ GIT_LOCALE_PATH="share/locale"
+ GIT_MAN_PATH="share/man"
+ GIT_INFO_PATH="share/info"
+ GIT_HTML_PATH="share/doc/git-doc"
+ DEFAULT_HELP_FORMAT="html"
+ DEFAULT_GIT_TEMPLATE_DIR="share/git-core/templates"
+ GIT_VERSION="${PROJECT_VERSION}.GIT"
+ GIT_USER_AGENT="git/${PROJECT_VERSION}.GIT"
+ BINDIR="bin"
+ GIT_BUILT_FROM_COMMIT="")
+
+if(WIN32)
+ set(FALLBACK_RUNTIME_PREFIX /mingw64)
+ # Move system config into top-level /etc/
+ add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}"
+ ETC_GITATTRIBUTES="../etc/gitattributes"
+ ETC_GITCONFIG="../etc/gitconfig")
+else()
+ set(FALLBACK_RUNTIME_PREFIX /home/$ENV{USER})
+ add_compile_definitions(FALLBACK_RUNTIME_PREFIX="${FALLBACK_RUNTIME_PREFIX}"
+ ETC_GITATTRIBUTES="etc/gitattributes"
+ ETC_GITCONFIG="etc/gitconfig")
+endif()
+
+
+#Platform Specific
+if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ include_directories(${CMAKE_SOURCE_DIR}/compat/vcbuild/include)
+ add_compile_definitions(_CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE)
+ endif()
+ include_directories(${CMAKE_SOURCE_DIR}/compat/win32)
+ add_compile_definitions(HAVE_ALLOCA_H NO_POSIX_GOODIES NATIVE_CRLF NO_UNIX_SOCKETS WIN32
+ _CONSOLE DETECT_MSYS_TTY STRIP_EXTENSION=".exe" NO_SYMLINK_HEAD UNRELIABLE_FSTAT
+ NOGDI OBJECT_CREATION_MODE=1 __USE_MINGW_ANSI_STDIO=0
+ USE_NED_ALLOCATOR OVERRIDE_STRDUP MMAP_PREVENTS_DELETE USE_WIN32_MMAP
+ HAVE_WPGMPTR ENSURE_MSYSTEM_IS_SET HAVE_RTLGENRANDOM)
+ list(APPEND compat_SOURCES
+ compat/mingw.c
+ compat/winansi.c
+ compat/win32/flush.c
+ compat/win32/path-utils.c
+ compat/win32/pthread.c
+ compat/win32mmap.c
+ compat/win32/syslog.c
+ compat/win32/trace2_win32_process_info.c
+ compat/win32/dirent.c
+ compat/nedmalloc/nedmalloc.c
+ compat/strdup.c)
+ set(NO_UNIX_SOCKETS 1)
+
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ add_compile_definitions(PROCFS_EXECUTABLE_PATH="/proc/self/exe" HAVE_DEV_TTY )
+ list(APPEND compat_SOURCES unix-socket.c unix-stream-server.c compat/linux/procinfo.c)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-win32.c)
+ add_compile_definitions(SUPPORTS_SIMPLE_IPC)
+ set(SUPPORTS_SIMPLE_IPC 1)
+else()
+ # Simple IPC requires both Unix sockets and pthreads on Unix-based systems.
+ if(NOT NO_UNIX_SOCKETS AND NOT NO_PTHREADS)
+ list(APPEND compat_SOURCES compat/simple-ipc/ipc-shared.c compat/simple-ipc/ipc-unix-socket.c)
+ add_compile_definitions(SUPPORTS_SIMPLE_IPC)
+ set(SUPPORTS_SIMPLE_IPC 1)
+ endif()
+endif()
+
+if(SUPPORTS_SIMPLE_IPC)
+ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
+ add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-win32.c)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-win32.c)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-win32.c)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-win32.c)
+
+ add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-win32.c)
+ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ add_compile_definitions(HAVE_FSMONITOR_DAEMON_BACKEND)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-listen-darwin.c)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-health-darwin.c)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-ipc-darwin.c)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-path-utils-darwin.c)
+
+ add_compile_definitions(HAVE_FSMONITOR_OS_SETTINGS)
+ list(APPEND compat_SOURCES compat/fsmonitor/fsm-settings-darwin.c)
+ endif()
+endif()
+
+set(EXE_EXTENSION ${CMAKE_EXECUTABLE_SUFFIX})
+
+#header checks
+check_include_file(libgen.h HAVE_LIBGEN_H)
+if(NOT HAVE_LIBGEN_H)
+ add_compile_definitions(NO_LIBGEN_H)
+ list(APPEND compat_SOURCES compat/basename.c)
+endif()
+
+check_include_file(sys/sysinfo.h HAVE_SYSINFO)
+if(HAVE_SYSINFO)
+ add_compile_definitions(HAVE_SYSINFO)
+endif()
+
+check_c_source_compiles("
+#include <alloca.h>
+
+int main(void)
+{
+ char *p = (char *) alloca(2 * sizeof(int));
+
+ if (p)
+ return 0;
+ return 0;
+}"
+HAVE_ALLOCA_H)
+if(HAVE_ALLOCA_H)
+ add_compile_definitions(HAVE_ALLOCA_H)
+endif()
+
+check_include_file(strings.h HAVE_STRINGS_H)
+if(HAVE_STRINGS_H)
+ add_compile_definitions(HAVE_STRINGS_H)
+endif()
+
+check_include_file(sys/select.h HAVE_SYS_SELECT_H)
+if(NOT HAVE_SYS_SELECT_H)
+ add_compile_definitions(NO_SYS_SELECT_H)
+endif()
+
+check_include_file(sys/poll.h HAVE_SYS_POLL_H)
+if(NOT HAVE_SYS_POLL_H)
+ add_compile_definitions(NO_SYS_POLL_H)
+endif()
+
+check_include_file(poll.h HAVE_POLL_H)
+if(NOT HAVE_POLL_H)
+ add_compile_definitions(NO_POLL_H)
+endif()
+
+check_include_file(inttypes.h HAVE_INTTYPES_H)
+if(NOT HAVE_INTTYPES_H)
+ add_compile_definitions(NO_INTTYPES_H)
+endif()
+
+check_include_file(paths.h HAVE_PATHS_H)
+if(HAVE_PATHS_H)
+ add_compile_definitions(HAVE_PATHS_H)
+endif()
+
+#function checks
+set(function_checks
+ strcasestr memmem strlcpy strtoimax strtoumax strtoull
+ setenv mkdtemp poll pread memmem)
+
+#unsetenv,hstrerror are incompatible with windows build
+if(NOT WIN32)
+ list(APPEND function_checks unsetenv hstrerror)
+endif()
+
+foreach(f ${function_checks})
+ string(TOUPPER ${f} uf)
+ check_function_exists(${f} HAVE_${uf})
+ if(NOT HAVE_${uf})
+ add_compile_definitions(NO_${uf})
+ endif()
+endforeach()
+
+if(NOT HAVE_POLL_H OR NOT HAVE_SYS_POLL_H OR NOT HAVE_POLL)
+ include_directories(${CMAKE_SOURCE_DIR}/compat/poll)
+ add_compile_definitions(NO_POLL)
+ list(APPEND compat_SOURCES compat/poll/poll.c)
+endif()
+
+if(NOT HAVE_STRCASESTR)
+ list(APPEND compat_SOURCES compat/strcasestr.c)
+endif()
+
+if(NOT HAVE_STRLCPY)
+ list(APPEND compat_SOURCES compat/strlcpy.c)
+endif()
+
+if(NOT HAVE_STRTOUMAX)
+ list(APPEND compat_SOURCES compat/strtoumax.c compat/strtoimax.c)
+endif()
+
+if(NOT HAVE_SETENV)
+ list(APPEND compat_SOURCES compat/setenv.c)
+endif()
+
+if(NOT HAVE_MKDTEMP)
+ list(APPEND compat_SOURCES compat/mkdtemp.c)
+endif()
+
+if(NOT HAVE_PREAD)
+ list(APPEND compat_SOURCES compat/pread.c)
+endif()
+
+if(NOT HAVE_MEMMEM)
+ list(APPEND compat_SOURCES compat/memmem.c)
+endif()
+
+if(NOT WIN32)
+ if(NOT HAVE_UNSETENV)
+ list(APPEND compat_SOURCES compat/unsetenv.c)
+ endif()
+
+ if(NOT HAVE_HSTRERROR)
+ list(APPEND compat_SOURCES compat/hstrerror.c)
+ endif()
+endif()
+
+check_function_exists(getdelim HAVE_GETDELIM)
+if(HAVE_GETDELIM)
+ add_compile_definitions(HAVE_GETDELIM)
+endif()
+
+check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
+check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_CLOCK_MONOTONIC)
+if(HAVE_CLOCK_GETTIME)
+ add_compile_definitions(HAVE_CLOCK_GETTIME)
+endif()
+if(HAVE_CLOCK_MONOTONIC)
+ add_compile_definitions(HAVE_CLOCK_MONOTONIC)
+endif()
+
+#check for st_blocks in struct stat
+check_struct_has_member("struct stat" st_blocks "sys/stat.h" STRUCT_STAT_HAS_ST_BLOCKS)
+if(NOT STRUCT_STAT_HAS_ST_BLOCKS)
+ add_compile_definitions(NO_ST_BLOCKS_IN_STRUCT_STAT)
+endif()
+
+#compile checks
+check_c_source_runs("
+#include<stdio.h>
+#include<stdarg.h>
+#include<string.h>
+#include<stdlib.h>
+
+int test_vsnprintf(char *str, size_t maxsize, const char *format, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, format);
+ ret = vsnprintf(str, maxsize, format, ap);
+ va_end(ap);
+ return ret;
+}
+
+int main(void)
+{
+ char buf[6];
+
+ if (test_vsnprintf(buf, 3, \"%s\", \"12345\") != 5
+ || strcmp(buf, \"12\"))
+ return 1;
+ if (snprintf(buf, 3, \"%s\", \"12345\") != 5
+ || strcmp(buf, \"12\"))
+ return 1;
+ return 0;
+}"
+SNPRINTF_OK)
+if(NOT SNPRINTF_OK)
+ add_compile_definitions(SNPRINTF_RETURNS_BOGUS)
+ list(APPEND compat_SOURCES compat/snprintf.c)
+endif()
+
+check_c_source_runs("
+#include<stdio.h>
+
+int main(void)
+{
+ FILE *f = fopen(\".\", \"r\");
+
+ return f != NULL;
+}"
+FREAD_READS_DIRECTORIES_NO)
+if(NOT FREAD_READS_DIRECTORIES_NO)
+ add_compile_definitions(FREAD_READS_DIRECTORIES)
+ list(APPEND compat_SOURCES compat/fopen.c)
+endif()
+
+check_c_source_compiles("
+#include <regex.h>
+#ifndef REG_STARTEND
+#error oops we dont have it
+#endif
+
+int main(void)
+{
+ return 0;
+}"
+HAVE_REGEX)
+if(NOT HAVE_REGEX)
+ include_directories(${CMAKE_SOURCE_DIR}/compat/regex)
+ list(APPEND compat_SOURCES compat/regex/regex.c )
+ add_compile_definitions(NO_REGEX NO_MBSUPPORT GAWK)
+endif()
+
+
+check_c_source_compiles("
+#include <stddef.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+int main(void)
+{
+ int val, mib[2];
+ size_t len;
+
+ mib[0] = CTL_HW;
+ mib[1] = 1;
+ len = sizeof(val);
+ return sysctl(mib, 2, &val, &len, NULL, 0) ? 1 : 0;
+}"
+HAVE_BSD_SYSCTL)
+if(HAVE_BSD_SYSCTL)
+ add_compile_definitions(HAVE_BSD_SYSCTL)
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES ${Iconv_LIBRARIES})
+set(CMAKE_REQUIRED_INCLUDES ${Iconv_INCLUDE_DIRS})
+
+check_c_source_compiles("
+#include <iconv.h>
+
+extern size_t iconv(iconv_t cd,
+ char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft);
+
+int main(void)
+{
+ return 0;
+}"
+HAVE_NEW_ICONV)
+if(HAVE_NEW_ICONV)
+ set(HAVE_OLD_ICONV 0)
+else()
+ set(HAVE_OLD_ICONV 1)
+endif()
+
+check_c_source_runs("
+#include <iconv.h>
+#if ${HAVE_OLD_ICONV}
+typedef const char *iconv_ibp;
+#else
+typedef char *iconv_ibp;
+#endif
+
+int main(void)
+{
+ int v;
+ iconv_t conv;
+ char in[] = \"a\";
+ iconv_ibp pin = in;
+ char out[20] = \"\";
+ char *pout = out;
+ size_t isz = sizeof(in);
+ size_t osz = sizeof(out);
+
+ conv = iconv_open(\"UTF-16\", \"UTF-8\");
+ iconv(conv, &pin, &isz, &pout, &osz);
+ iconv_close(conv);
+ v = (unsigned char)(out[0]) + (unsigned char)(out[1]);
+ return v != 0xfe + 0xff;
+}"
+ICONV_DOESNOT_OMIT_BOM)
+if(NOT ICONV_DOESNOT_OMIT_BOM)
+ add_compile_definitions(ICONV_OMITS_BOM)
+endif()
+
+unset(CMAKE_REQUIRED_LIBRARIES)
+unset(CMAKE_REQUIRED_INCLUDES)
+
+
+#programs
+set(PROGRAMS_BUILT
+ git git-daemon git-http-backend git-sh-i18n--envsubst
+ git-shell scalar)
+
+if(NOT CURL_FOUND)
+ list(APPEND excluded_progs git-http-fetch git-http-push)
+ add_compile_definitions(NO_CURL)
+ message(WARNING "git-http-push and git-http-fetch will not be built")
+else()
+ list(APPEND PROGRAMS_BUILT git-http-fetch git-http-push git-imap-send git-remote-http)
+ if(CURL_VERSION_STRING VERSION_GREATER_EQUAL 7.34.0)
+ add_compile_definitions(USE_CURL_FOR_IMAP_SEND)
+ endif()
+endif()
+
+if(NOT EXPAT_FOUND)
+ list(APPEND excluded_progs git-http-push)
+ add_compile_definitions(NO_EXPAT)
+else()
+ list(APPEND PROGRAMS_BUILT git-http-push)
+ if(EXPAT_VERSION_STRING VERSION_LESS_EQUAL 1.2)
+ add_compile_definitions(EXPAT_NEEDS_XMLPARSE_H)
+ endif()
+endif()
+
+list(REMOVE_DUPLICATES excluded_progs)
+list(REMOVE_DUPLICATES PROGRAMS_BUILT)
+
+
+foreach(p ${excluded_progs})
+ list(APPEND EXCLUSION_PROGS --exclude-program ${p} )
+endforeach()
+
+#for comparing null values
+list(APPEND EXCLUSION_PROGS empty)
+set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" FORCE)
+
+if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS)
+ list(REMOVE_ITEM EXCLUSION_PROGS empty)
+ message("Generating command-list.h")
+ execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} command-list.txt
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_FILE ${CMAKE_BINARY_DIR}/command-list.h)
+endif()
+
+if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h)
+ message("Generating config-list.h")
+ execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h)
+endif()
+
+if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h)
+ message("Generating hook-list.h")
+ execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h)
+endif()
+
+include_directories(${CMAKE_BINARY_DIR})
+
+#build
+#libgit
+parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS")
+
+list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+add_library(libgit ${libgit_SOURCES} ${compat_SOURCES})
+
+#libxdiff
+parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
+
+list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+add_library(xdiff STATIC ${libxdiff_SOURCES})
+
+#reftable
+parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS")
+
+list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+add_library(reftable STATIC ${reftable_SOURCES})
+
+if(WIN32)
+ if(NOT MSVC)#use windres when compiling with gcc and clang
+ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
+ COMMAND ${WINDRES_EXE} -O coff -DMAJOR=${PROJECT_VERSION_MAJOR} -DMINOR=${PROJECT_VERSION_MINOR}
+ -DMICRO=${PROJECT_VERSION_PATCH} -DPATCHLEVEL=0 -DGIT_VERSION="\\\"${PROJECT_VERSION}.GIT\\\""
+ -i ${CMAKE_SOURCE_DIR}/git.rc -o ${CMAKE_BINARY_DIR}/git.res
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ VERBATIM)
+ else()#MSVC use rc
+ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/git.res
+ COMMAND ${CMAKE_RC_COMPILER} /d MAJOR=${PROJECT_VERSION_MAJOR} /d MINOR=${PROJECT_VERSION_MINOR}
+ /d MICRO=${PROJECT_VERSION_PATCH} /d PATCHLEVEL=0 /d GIT_VERSION="${PROJECT_VERSION}.GIT"
+ /fo ${CMAKE_BINARY_DIR}/git.res ${CMAKE_SOURCE_DIR}/git.rc
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ VERBATIM)
+ endif()
+ add_custom_target(git-rc DEPENDS ${CMAKE_BINARY_DIR}/git.res)
+endif()
+
+#link all required libraries to common-main
+add_library(common-main OBJECT ${CMAKE_SOURCE_DIR}/common-main.c)
+
+target_link_libraries(common-main libgit xdiff reftable ${ZLIB_LIBRARIES})
+if(Intl_FOUND)
+ target_link_libraries(common-main ${Intl_LIBRARIES})
+endif()
+if(Iconv_FOUND)
+ target_link_libraries(common-main ${Iconv_LIBRARIES})
+endif()
+if(PCRE2_FOUND)
+ target_link_libraries(common-main ${PCRE2_LIBRARIES})
+ target_link_directories(common-main PUBLIC ${PCRE2_LIBRARY_DIRS})
+endif()
+if(WIN32)
+ target_link_libraries(common-main ws2_32 ntdll ${CMAKE_BINARY_DIR}/git.res)
+ add_dependencies(common-main git-rc)
+ if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ target_link_options(common-main PUBLIC -municode -Wl,--nxcompat -Wl,--dynamicbase -Wl,--pic-executable,-e,mainCRTStartup)
+ elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ target_link_options(common-main PUBLIC -municode -Wl,-nxcompat -Wl,-dynamicbase -Wl,-entry:wmainCRTStartup -Wl,invalidcontinue.obj)
+ elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
+ target_link_options(common-main PUBLIC /IGNORE:4217 /IGNORE:4049 /NOLOGO /ENTRY:wmainCRTStartup /SUBSYSTEM:CONSOLE invalidcontinue.obj)
+ else()
+ message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
+ endif()
+
+ add_executable(headless-git ${CMAKE_SOURCE_DIR}/compat/win32/headless.c)
+ if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ target_link_options(headless-git PUBLIC -municode -Wl,-subsystem,windows)
+ elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
+ target_link_options(headless-git PUBLIC /NOLOGO /ENTRY:wWinMainCRTStartup /SUBSYSTEM:WINDOWS)
+ else()
+ message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
+ endif()
+elseif(UNIX)
+ target_link_libraries(common-main pthread rt)
+endif()
+
+#git
+parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS")
+
+list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
+target_link_libraries(git common-main)
+
+add_executable(git-daemon ${CMAKE_SOURCE_DIR}/daemon.c)
+target_link_libraries(git-daemon common-main)
+
+add_executable(git-http-backend ${CMAKE_SOURCE_DIR}/http-backend.c)
+target_link_libraries(git-http-backend common-main)
+
+add_executable(git-sh-i18n--envsubst ${CMAKE_SOURCE_DIR}/sh-i18n--envsubst.c)
+target_link_libraries(git-sh-i18n--envsubst common-main)
+
+add_executable(git-shell ${CMAKE_SOURCE_DIR}/shell.c)
+target_link_libraries(git-shell common-main)
+
+add_executable(scalar ${CMAKE_SOURCE_DIR}/scalar.c)
+target_link_libraries(scalar common-main)
+
+if(CURL_FOUND)
+ add_library(http_obj OBJECT ${CMAKE_SOURCE_DIR}/http.c)
+
+ add_executable(git-imap-send ${CMAKE_SOURCE_DIR}/imap-send.c)
+ target_link_libraries(git-imap-send http_obj common-main ${CURL_LIBRARIES})
+
+ add_executable(git-http-fetch ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/http-fetch.c)
+ target_link_libraries(git-http-fetch http_obj common-main ${CURL_LIBRARIES})
+
+ add_executable(git-remote-http ${CMAKE_SOURCE_DIR}/http-walker.c ${CMAKE_SOURCE_DIR}/remote-curl.c)
+ target_link_libraries(git-remote-http http_obj common-main ${CURL_LIBRARIES} )
+
+ if(EXPAT_FOUND)
+ add_executable(git-http-push ${CMAKE_SOURCE_DIR}/http-push.c)
+ target_link_libraries(git-http-push http_obj common-main ${CURL_LIBRARIES} ${EXPAT_LIBRARIES})
+ endif()
+endif()
+
+parse_makefile_for_executables(git_builtin_extra "BUILT_INS")
+
+option(SKIP_DASHED_BUILT_INS "Skip hardlinking the dashed versions of the built-ins")
+
+#Creating hardlinks
+if(NOT SKIP_DASHED_BUILT_INS)
+foreach(s ${git_SOURCES} ${git_builtin_extra})
+ string(REPLACE "${CMAKE_SOURCE_DIR}/builtin/" "" s ${s})
+ string(REPLACE ".c" "" s ${s})
+ file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git${EXE_EXTENSION} git-${s}${EXE_EXTENSION})\n")
+ list(APPEND git_links ${CMAKE_BINARY_DIR}/git-${s}${EXE_EXTENSION})
+endforeach()
+endif()
+
+if(CURL_FOUND)
+ set(remote_exes
+ git-remote-https git-remote-ftp git-remote-ftps)
+ foreach(s ${remote_exes})
+ file(APPEND ${CMAKE_BINARY_DIR}/CreateLinks.cmake "file(CREATE_LINK git-remote-http${EXE_EXTENSION} ${s}${EXE_EXTENSION})\n")
+ list(APPEND git_http_links ${CMAKE_BINARY_DIR}/${s}${EXE_EXTENSION})
+ endforeach()
+endif()
+
+add_custom_command(OUTPUT ${git_links} ${git_http_links}
+ COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/CreateLinks.cmake
+ DEPENDS git git-remote-http)
+add_custom_target(git-links ALL DEPENDS ${git_links} ${git_http_links})
+
+
+#creating required scripts
+set(SHELL_PATH /bin/sh)
+set(PERL_PATH /usr/bin/perl)
+set(LOCALEDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
+set(GITWEBDIR ${FALLBACK_RUNTIME_PREFIX}/share/locale)
+set(INSTLIBDIR ${FALLBACK_RUNTIME_PREFIX}/share/perl5)
+
+#shell scripts
+parse_makefile_for_scripts(git_sh_scripts "SCRIPT_SH" ".sh")
+parse_makefile_for_scripts(git_shlib_scripts "SCRIPT_LIB" "")
+set(git_shell_scripts
+ ${git_sh_scripts} ${git_shlib_scripts} git-instaweb)
+
+foreach(script ${git_shell_scripts})
+ file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.sh content NEWLINE_CONSUME)
+ string(REPLACE "@SHELL_PATH@" "${SHELL_PATH}" content "${content}")
+ string(REPLACE "@@DIFF@@" "diff" content "${content}")
+ string(REPLACE "@LOCALEDIR@" "${LOCALEDIR}" content "${content}")
+ string(REPLACE "@GITWEBDIR@" "${GITWEBDIR}" content "${content}")
+ string(REPLACE "@@NO_CURL@@" "" content "${content}")
+ string(REPLACE "@@USE_GETTEXT_SCHEME@@" "" content "${content}")
+ string(REPLACE "# @@BROKEN_PATH_FIX@@" "" content "${content}")
+ string(REPLACE "@@PERL@@" "${PERL_PATH}" content "${content}")
+ string(REPLACE "@@PAGER_ENV@@" "LESS=FRX LV=-c" content "${content}")
+ file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
+endforeach()
+
+#perl scripts
+parse_makefile_for_scripts(git_perl_scripts "SCRIPT_PERL" ".perl")
+
+#create perl header
+file(STRINGS ${CMAKE_SOURCE_DIR}/perl/header_templates/fixed_prefix.template.pl perl_header )
+string(REPLACE "@@PATHSEP@@" ":" perl_header "${perl_header}")
+string(REPLACE "@@INSTLIBDIR@@" "${INSTLIBDIR}" perl_header "${perl_header}")
+
+foreach(script ${git_perl_scripts})
+ file(STRINGS ${CMAKE_SOURCE_DIR}/${script}.perl content NEWLINE_CONSUME)
+ string(REPLACE "#!/usr/bin/perl" "#!/usr/bin/perl\n${perl_header}\n" content "${content}")
+ string(REPLACE "@@GIT_VERSION@@" "${PROJECT_VERSION}" content "${content}")
+ file(WRITE ${CMAKE_BINARY_DIR}/${script} ${content})
+endforeach()
+
+#python script
+file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)
+string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}")
+file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})
+
+#perl modules
+file(GLOB_RECURSE perl_modules "${CMAKE_SOURCE_DIR}/perl/*.pm")
+
+foreach(pm ${perl_modules})
+ string(REPLACE "${CMAKE_SOURCE_DIR}/perl/" "" file_path ${pm})
+ file(STRINGS ${pm} content NEWLINE_CONSUME)
+ string(REPLACE "@@LOCALEDIR@@" "${LOCALEDIR}" content "${content}")
+ string(REPLACE "@@NO_PERL_CPAN_FALLBACKS@@" "" content "${content}")
+ file(WRITE ${CMAKE_BINARY_DIR}/perl/build/lib/${file_path} ${content})
+#test-lib.sh requires perl/build/lib to be the build directory of perl modules
+endforeach()
+
+
+#templates
+file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*")
+list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "")
+list(REMOVE_ITEM templates ".gitignore")
+list(REMOVE_ITEM templates "Makefile")
+list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds
+
+list(REMOVE_ITEM templates "branches--")
+file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches
+
+#templates have @.*@ replacement so use configure_file instead
+foreach(tm ${templates})
+ string(REPLACE "--" "/" blt_tm ${tm})
+ string(REPLACE "this" "" blt_tm ${blt_tm})# for this--
+ configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY)
+endforeach()
+
+
+#translations
+if(MSGFMT_EXE)
+ file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po")
+ list(TRANSFORM po_files REPLACE "${CMAKE_SOURCE_DIR}/po/" "")
+ list(TRANSFORM po_files REPLACE ".po" "")
+ foreach(po ${po_files})
+ file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES)
+ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo
+ COMMAND ${MSGFMT_EXE} --check --statistics -o ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo ${CMAKE_SOURCE_DIR}/po/${po}.po)
+ list(APPEND po_gen ${CMAKE_BINARY_DIR}/po/build/locale/${po}/LC_MESSAGES/git.mo)
+ endforeach()
+ add_custom_target(po-gen ALL DEPENDS ${po_gen})
+endif()
+
+
+#to help with the install
+list(TRANSFORM git_shell_scripts PREPEND "${CMAKE_BINARY_DIR}/")
+list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
+
+#install
+foreach(program ${PROGRAMS_BUILT})
+if(program MATCHES "^(git|git-shell|scalar)$")
+install(TARGETS ${program}
+ RUNTIME DESTINATION bin)
+else()
+install(TARGETS ${program}
+ RUNTIME DESTINATION libexec/git-core)
+endif()
+endforeach()
+
+install(PROGRAMS ${CMAKE_BINARY_DIR}/git-cvsserver
+ DESTINATION bin)
+
+set(bin_links
+ git-receive-pack git-upload-archive git-upload-pack)
+
+foreach(b ${bin_links})
+install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/bin/${b}${EXE_EXTENSION})")
+endforeach()
+
+install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git${EXE_EXTENSION})")
+install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git-shell${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-shell${EXE_EXTENSION})")
+
+foreach(b ${git_links})
+ string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
+ install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/bin/git${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})")
+endforeach()
+
+foreach(b ${git_http_links})
+ string(REPLACE "${CMAKE_BINARY_DIR}" "" b ${b})
+ install(CODE "file(CREATE_LINK ${CMAKE_INSTALL_PREFIX}/libexec/git-core/git-remote-http${EXE_EXTENSION} ${CMAKE_INSTALL_PREFIX}/libexec/git-core/${b})")
+endforeach()
+
+install(PROGRAMS ${git_shell_scripts} ${git_perl_scripts} ${CMAKE_BINARY_DIR}/git-p4
+ DESTINATION libexec/git-core)
+
+install(DIRECTORY ${CMAKE_SOURCE_DIR}/mergetools DESTINATION libexec/git-core)
+install(DIRECTORY ${CMAKE_BINARY_DIR}/perl/build/lib/ DESTINATION share/perl5
+ FILES_MATCHING PATTERN "*.pm")
+install(DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/ DESTINATION share/git-core/templates)
+
+if(MSGFMT_EXE)
+ install(DIRECTORY ${CMAKE_BINARY_DIR}/po/build/locale DESTINATION share)
+endif()
+
+
+if(BUILD_TESTING)
+
+#tests-helpers
+add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
+target_link_libraries(test-fake-ssh common-main)
+
+#reftable-tests
+parse_makefile_for_sources(test-reftable_SOURCES "REFTABLE_TEST_OBJS")
+list(TRANSFORM test-reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
+
+#unit-tests
+add_library(unit-test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
+
+parse_makefile_for_scripts(unit_test_PROGRAMS "UNIT_TEST_PROGRAMS" "")
+foreach(unit_test ${unit_test_PROGRAMS})
+ add_executable("${unit_test}" "${CMAKE_SOURCE_DIR}/t/unit-tests/${unit_test}.c")
+ target_link_libraries("${unit_test}" unit-test-lib common-main)
+ set_target_properties("${unit_test}"
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+ if(MSVC)
+ set_target_properties("${unit_test}"
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+ set_target_properties("${unit_test}"
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/unit-tests/bin)
+ endif()
+ list(APPEND PROGRAMS_BUILT "${unit_test}")
+
+ # t-basic intentionally fails tests, to validate the unit-test infrastructure.
+ # Therefore, it should only be run as part of t0080, which verifies that it
+ # fails only in the expected ways.
+ #
+ # All other unit tests should be run.
+ if(NOT ${unit_test} STREQUAL "t-basic")
+ add_test(NAME "t.unit-tests.${unit_test}"
+ COMMAND "./${unit_test}"
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t/unit-tests/bin)
+ endif()
+endforeach()
+
+#test-tool
+parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
+
+list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
+add_executable(test-tool ${CMAKE_SOURCE_DIR}/t/helper/test-tool.c ${test-tool_SOURCES} ${test-reftable_SOURCES})
+target_link_libraries(test-tool common-main)
+
+set_target_properties(test-fake-ssh test-tool
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/t/helper)
+
+if(MSVC)
+ set_target_properties(test-fake-ssh test-tool
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/t/helper)
+ set_target_properties(test-fake-ssh test-tool
+ PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/t/helper)
+endif()
+
+#wrapper scripts
+set(wrapper_scripts
+ git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext scalar)
+
+set(wrapper_test_scripts
+ test-fake-ssh test-tool)
+
+
+foreach(script ${wrapper_scripts})
+ file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
+ string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
+ string(REPLACE "@@PROG@@" "${script}${EXE_EXTENSION}" content "${content}")
+ file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
+endforeach()
+
+foreach(script ${wrapper_test_scripts})
+ file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
+ string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
+ string(REPLACE "@@PROG@@" "t/helper/${script}${EXE_EXTENSION}" content "${content}")
+ file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/${script} ${content})
+endforeach()
+
+file(STRINGS ${CMAKE_SOURCE_DIR}/wrap-for-bin.sh content NEWLINE_CONSUME)
+string(REPLACE "@@BUILD_DIR@@" "${CMAKE_BINARY_DIR}" content "${content}")
+string(REPLACE "@@PROG@@" "git-cvsserver" content "${content}")
+file(WRITE ${CMAKE_BINARY_DIR}/bin-wrappers/git-cvsserver ${content})
+
+#options for configuring test options
+option(PERL_TESTS "Perform tests that use perl" ON)
+option(PYTHON_TESTS "Perform tests that use python" ON)
+
+#GIT-BUILD-OPTIONS
+set(TEST_SHELL_PATH ${SHELL_PATH})
+set(DIFF diff)
+set(PYTHON_PATH /usr/bin/python)
+set(TAR tar)
+set(NO_CURL )
+set(NO_EXPAT )
+set(USE_LIBPCRE2 )
+set(NO_PERL )
+set(NO_PTHREADS )
+set(NO_PYTHON )
+set(PAGER_ENV "LESS=FRX LV=-c")
+set(RUNTIME_PREFIX true)
+set(NO_GETTEXT )
+
+if(NOT CURL_FOUND)
+ set(NO_CURL 1)
+endif()
+
+if(NOT EXPAT_FOUND)
+ set(NO_EXPAT 1)
+endif()
+
+if(NOT Intl_FOUND)
+ set(NO_GETTEXT 1)
+endif()
+
+if(NOT PERL_TESTS)
+ set(NO_PERL 1)
+endif()
+
+if(NOT PYTHON_TESTS)
+ set(NO_PYTHON 1)
+endif()
+
+file(WRITE ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SHELL_PATH='${SHELL_PATH}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TEST_SHELL_PATH='${TEST_SHELL_PATH}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PERL_PATH='${PERL_PATH}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "DIFF='${DIFF}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PYTHON_PATH='${PYTHON_PATH}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TAR='${TAR}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_CURL='${NO_CURL}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_EXPAT='${NO_EXPAT}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PAGER_ENV='${PAGER_ENV}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "X='${EXE_EXTENSION}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_GETTEXT='${NO_GETTEXT}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "RUNTIME_PREFIX='${RUNTIME_PREFIX}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PYTHON='${NO_PYTHON}'\n")
+file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "SUPPORTS_SIMPLE_IPC='${SUPPORTS_SIMPLE_IPC}'\n")
+if(USE_VCPKG)
+ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PATH=\"$PATH:$TEST_DIRECTORY/../compat/vcbuild/vcpkg/installed/x64-windows/bin\"\n")
+endif()
+
+#Make the tests work when building out of the source tree
+get_filename_component(CACHE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../CMakeCache.txt ABSOLUTE)
+if(NOT ${CMAKE_BINARY_DIR}/CMakeCache.txt STREQUAL ${CACHE_PATH})
+ #Setting the build directory in test-lib.sh before running tests
+ file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
+ "file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \"${CMAKE_BINARY_DIR}\")")
+ #misc copies
+ file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.pl DESTINATION ${CMAKE_BINARY_DIR}/t/)
+ file(COPY ${CMAKE_SOURCE_DIR}/po/is.po DESTINATION ${CMAKE_BINARY_DIR}/po/)
+ file(GLOB mergetools "${CMAKE_SOURCE_DIR}/mergetools/*")
+ file(COPY ${mergetools} DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)
+ file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-prompt.sh DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
+ file(COPY ${CMAKE_SOURCE_DIR}/contrib/completion/git-completion.bash DESTINATION ${CMAKE_BINARY_DIR}/contrib/completion/)
+endif()
+
+file(GLOB test_scripts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
+
+#test
+foreach(tsh ${test_scripts})
+ string(REGEX REPLACE ".*/(.*)\\.sh" "\\1" test_name ${tsh})
+ add_test(NAME "t.suite.${test_name}"
+ COMMAND ${SH_EXE} ${tsh} --no-bin-wrappers --no-chain-lint -vx
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/t)
+endforeach()
+
+# This test script takes an extremely long time and is known to time out even
+# on fast machines because it requires in excess of one hour to run
+set_tests_properties("t.suite.t7112-reset-submodule" PROPERTIES TIMEOUT 4000)
+
+endif()#BUILD_TESTING
diff --git a/contrib/buildsystems/Generators/Vcxproj.pm b/contrib/buildsystems/Generators/Vcxproj.pm
index 5c666f9..b2e68a1 100644
--- a/contrib/buildsystems/Generators/Vcxproj.pm
+++ b/contrib/buildsystems/Generators/Vcxproj.pm
@@ -76,10 +76,11 @@ sub createProject {
my $libs_release = "\n ";
my $libs_debug = "\n ";
- if (!$static_library) {
- $libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}}));
+ if (!$static_library && $name ne 'headless-git') {
+ $libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib|reftable\/libreftable\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}}));
$libs_debug = $libs_release;
$libs_debug =~ s/zlib\.lib/zlibd\.lib/g;
+ $libs_debug =~ s/libexpat\.lib/libexpatd\.lib/g;
$libs_debug =~ s/libcurl\.lib/libcurl-d\.lib/g;
}
@@ -229,8 +230,9 @@ EOM
print F << "EOM";
</ItemGroup>
EOM
- if (!$static_library || $target =~ 'vcs-svn' || $target =~ 'xdiff') {
+ if ((!$static_library || $target =~ 'vcs-svn' || $target =~ 'xdiff') && !($name =~ /headless-git/)) {
my $uuid_libgit = $$build_structure{"LIBS_libgit_GUID"};
+ my $uuid_libreftable = $$build_structure{"LIBS_reftable/libreftable_GUID"};
my $uuid_xdiff_lib = $$build_structure{"LIBS_xdiff/lib_GUID"};
print F << "EOM";
@@ -240,6 +242,14 @@ EOM
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
EOM
+ if (!($name =~ /xdiff|libreftable/)) {
+ print F << "EOM";
+ <ProjectReference Include="$cdup\\reftable\\libreftable\\libreftable.vcxproj">
+ <Project>$uuid_libreftable</Project>
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+ </ProjectReference>
+EOM
+ }
if (!($name =~ 'xdiff')) {
print F << "EOM";
<ProjectReference Include="$cdup\\xdiff\\lib\\xdiff_lib.vcxproj">
diff --git a/contrib/buildsystems/engine.pl b/contrib/buildsystems/engine.pl
index 0709785..069be7e 100755
--- a/contrib/buildsystems/engine.pl
+++ b/contrib/buildsystems/engine.pl
@@ -349,9 +349,9 @@ sub handleLinkLine
} elsif ("$part" eq "-lcurl") {
push(@libs, "libcurl.lib");
} elsif ("$part" eq "-lexpat") {
- push(@libs, "expat.lib");
+ push(@libs, "libexpat.lib");
} elsif ("$part" eq "-liconv") {
- push(@libs, "libiconv.lib");
+ push(@libs, "iconv.lib");
} elsif ($part =~ /^[-\/]/) {
push(@lflags, $part);
} elsif ($part =~ /\.(a|lib)$/) {
@@ -371,6 +371,7 @@ sub handleLinkLine
# exit(1);
foreach (@objfiles) {
my $sourcefile = $_;
+ $sourcefile =~ s/^headless-git\.o$/compat\/win32\/headless.c/;
$sourcefile =~ s/\.o$/.c/;
push(@sources, $sourcefile);
push(@cflags, @{$compile_options{"${sourcefile}_CFLAGS"}});
diff --git a/contrib/coccinelle/.gitignore b/contrib/coccinelle/.gitignore
index d3f2964..1d45c0a 100644
--- a/contrib/coccinelle/.gitignore
+++ b/contrib/coccinelle/.gitignore
@@ -1 +1 @@
-*.patch*
+*.patch
diff --git a/contrib/coccinelle/README b/contrib/coccinelle/README
index f0e80bd..055ad0e 100644
--- a/contrib/coccinelle/README
+++ b/contrib/coccinelle/README
@@ -1,7 +1,9 @@
-This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
-semantic patches that might be useful to developers.
+= coccinelle
-There are two types of semantic patches:
+This directory provides Coccinelle (http://coccinelle.lip6.fr/) semantic patches
+that might be useful to developers.
+
+== Types of semantic patches
* Using the semantic transformation to check for bad patterns in the code;
The target 'make coccicheck' is designed to check for these patterns and
@@ -41,3 +43,82 @@ There are two types of semantic patches:
This allows to expose plans of pending large scale refactorings without
impacting the bad pattern checks.
+
+== Git-specific tips & things to know about how we run "spatch":
+
+ * The "make coccicheck" will piggy-back on
+ "COMPUTE_HEADER_DEPENDENCIES". If you've built a given object file
+ the "coccicheck" target will consider its depednency to decide if
+ it needs to re-run on the corresponding source file.
+
+ This means that a "make coccicheck" will re-compile object files
+ before running. This might be unexpected, but speeds up the run in
+ the common case, as e.g. a change to "column.h" won't require all
+ coccinelle rules to be re-run against "grep.c" (or another file
+ that happens not to use "column.h").
+
+ To disable this behavior use the "SPATCH_USE_O_DEPENDENCIES=NoThanks"
+ flag.
+
+ * To speed up our rules the "make coccicheck" target will by default
+ concatenate all of the *.cocci files here into an "ALL.cocci", and
+ apply it to each source file.
+
+ This makes the run faster, as we don't need to run each rule
+ against each source file. See the Makefile for further discussion,
+ this behavior can be disabled with "SPATCH_CONCAT_COCCI=".
+
+ But since they're concatenated any <id> in the <rulname> (e.g. "@
+ my_name", v.s. anonymous "@@") needs to be unique across all our
+ *.cocci files. You should only need to name rules if other rules
+ depend on them (currently only one rule is named).
+
+ * To speed up incremental runs even more use the "spatchcache" tool
+ in this directory as your "SPATCH". It aimns to be a "ccache" for
+ coccinelle, and piggy-backs on "COMPUTE_HEADER_DEPENDENCIES".
+
+ It caches in Redis by default, see it source for a how-to.
+
+ In one setup with a primed cache "make coccicheck" followed by a
+ "make clean && make" takes around 10s to run, but 2m30s with the
+ default of "SPATCH_CONCAT_COCCI=Y".
+
+ With "SPATCH_CONCAT_COCCI=" the total runtime is around ~6m, sped
+ up to ~1m with "spatchcache".
+
+ Most of the 10s (or ~1m) being spent on re-running "spatch" on
+ files we couldn't cache, as we didn't compile them (in contrib/*
+ and compat/* mostly).
+
+ The absolute times will differ for you, but the relative speedup
+ from caching should be on that order.
+
+== Authoring and reviewing coccinelle changes
+
+* When a .cocci is made, both the Git changes and .cocci file should be
+ reviewed. When reviewing such a change, do your best to understand the .cocci
+ changes (e.g. by asking the author to explain the change) and be explicit
+ about your understanding of the changes. This helps us decide whether input
+ from coccinelle experts is needed or not. If you aren't sure of the cocci
+ changes, indicate what changes you actively endorse and leave an Acked-by
+ (instead of Reviewed-by).
+
+* Authors should consider that reviewers may not be coccinelle experts, thus the
+ the .cocci changes may not be self-evident. A plain text description of the
+ changes is strongly encouraged, especially when using more esoteric features
+ of the language.
+
+* .cocci rules should target only the problem it is trying to solve; "collateral
+ damage" is not allowed. Reviewers should look out and flag overly-broad rules.
+
+* Consider the cost-benefit ratio of .cocci changes. In particular, consider the
+ effect on the runtime of "make coccicheck", and how often your .cocci check
+ will catch something valuable. As a rule of thumb, rules that can bail early
+ if a file doesn't have a particular token will have a small impact on runtime,
+ and vice-versa.
+
+* .cocci files used for refactoring should be temporarily kept in-tree to aid
+ the refactoring of out-of-tree code (e.g. in-flight topics). Periodically
+ evaluate the cost-benefit ratio to determine when the file should be removed.
+ For example, consider how many out-of-tree users are left and how much this
+ slows down "make coccicheck".
diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci
index 46b8d2e..27a3b47 100644
--- a/contrib/coccinelle/array.cocci
+++ b/contrib/coccinelle/array.cocci
@@ -1,60 +1,58 @@
@@
-expression dst, src, n, E;
+type T;
+T *dst_ptr;
+T *src_ptr;
+expression n;
@@
- memcpy(dst, src, n * sizeof(
-- E[...]
-+ *(E)
- ))
+- memcpy(dst_ptr, src_ptr, (n) * \( sizeof(T)
+- \| sizeof(*(dst_ptr))
+- \| sizeof(*(src_ptr))
+- \| sizeof(dst_ptr[...])
+- \| sizeof(src_ptr[...])
+- \) )
++ COPY_ARRAY(dst_ptr, src_ptr, n)
@@
type T;
-T *ptr;
-T[] arr;
-expression E, n;
+T *dst_ptr;
+T[] src_arr;
+expression n;
@@
-(
- memcpy(ptr, E,
-- n * sizeof(*(ptr))
-+ n * sizeof(T)
- )
-|
- memcpy(arr, E,
-- n * sizeof(*(arr))
-+ n * sizeof(T)
- )
-|
- memcpy(E, ptr,
-- n * sizeof(*(ptr))
-+ n * sizeof(T)
- )
-|
- memcpy(E, arr,
-- n * sizeof(*(arr))
-+ n * sizeof(T)
- )
-)
+- memcpy(dst_ptr, src_arr, (n) * \( sizeof(T)
+- \| sizeof(*(dst_ptr))
+- \| sizeof(*(src_arr))
+- \| sizeof(dst_ptr[...])
+- \| sizeof(src_arr[...])
+- \) )
++ COPY_ARRAY(dst_ptr, src_arr, n)
@@
type T;
-T *dst_ptr;
+T[] dst_arr;
T *src_ptr;
+expression n;
+@@
+- memcpy(dst_arr, src_ptr, (n) * \( sizeof(T)
+- \| sizeof(*(dst_arr))
+- \| sizeof(*(src_ptr))
+- \| sizeof(dst_arr[...])
+- \| sizeof(src_ptr[...])
+- \) )
++ COPY_ARRAY(dst_arr, src_ptr, n)
+
+@@
+type T;
T[] dst_arr;
T[] src_arr;
expression n;
@@
-(
-- memcpy(dst_ptr, src_ptr, (n) * sizeof(T))
-+ COPY_ARRAY(dst_ptr, src_ptr, n)
-|
-- memcpy(dst_ptr, src_arr, (n) * sizeof(T))
-+ COPY_ARRAY(dst_ptr, src_arr, n)
-|
-- memcpy(dst_arr, src_ptr, (n) * sizeof(T))
-+ COPY_ARRAY(dst_arr, src_ptr, n)
-|
-- memcpy(dst_arr, src_arr, (n) * sizeof(T))
+- memcpy(dst_arr, src_arr, (n) * \( sizeof(T)
+- \| sizeof(*(dst_arr))
+- \| sizeof(*(src_arr))
+- \| sizeof(dst_arr[...])
+- \| sizeof(src_arr[...])
+- \) )
+ COPY_ARRAY(dst_arr, src_arr, n)
-)
@@
type T;
@@ -88,3 +86,18 @@ expression n;
@@
- ptr = xmalloc((n) * sizeof(T));
+ ALLOC_ARRAY(ptr, n);
+
+@@
+type T;
+T *ptr;
+expression n != 1;
+@@
+- ptr = xcalloc(n, \( sizeof(*ptr) \| sizeof(T) \) )
++ CALLOC_ARRAY(ptr, n)
+
+@@
+expression dst, src, n;
+@@
+-ALLOC_ARRAY(dst, n);
+-COPY_ARRAY(dst, src, n);
++DUP_ARRAY(dst, src, n);
diff --git a/contrib/coccinelle/commit.cocci b/contrib/coccinelle/commit.cocci
index d034533..af6dd4c 100644
--- a/contrib/coccinelle/commit.cocci
+++ b/contrib/coccinelle/commit.cocci
@@ -20,7 +20,7 @@ expression s;
+ set_commit_tree(c, s)
...>}
-// These excluded functions must access c->maybe_tree direcly.
+// These excluded functions must access c->maybe_tree directly.
// Note that if c->maybe_tree is written somewhere outside of these
// functions, then the recommended transformation will be bogus with
// repo_get_commit_tree() on the LHS.
@@ -32,3 +32,21 @@ expression c;
- c->maybe_tree
+ repo_get_commit_tree(specify_the_right_repo_here, c)
...>}
+
+@@
+struct commit *c;
+expression E;
+@@
+(
+- c->generation = E;
++ commit_graph_data_at(c)->generation = E;
+|
+- c->graph_pos = E;
++ commit_graph_data_at(c)->graph_pos = E;
+|
+- c->generation
++ commit_graph_generation(c)
+|
+- c->graph_pos
++ commit_graph_position(c)
+)
diff --git a/contrib/coccinelle/config_fn_ctx.pending.cocci b/contrib/coccinelle/config_fn_ctx.pending.cocci
new file mode 100644
index 0000000..6d3d100
--- /dev/null
+++ b/contrib/coccinelle/config_fn_ctx.pending.cocci
@@ -0,0 +1,144 @@
+@ get_fn @
+identifier fn, R;
+@@
+(
+(
+git_config_from_file
+|
+git_config_from_file_with_options
+|
+git_config_from_mem
+|
+git_config_from_blob_oid
+|
+read_early_config
+|
+read_very_early_config
+|
+config_with_options
+|
+git_config
+|
+git_protected_config
+|
+config_from_gitmodules
+)
+ (fn, ...)
+|
+repo_config(R, fn, ...)
+)
+
+@ extends get_fn @
+identifier C1, C2, D;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D);
+
+@ extends get_fn @
+@@
+int fn(const char *, const char *,
++ const struct config_context *,
+ void *);
+
+@ extends get_fn @
+// Don't change fns that look like callback fns but aren't
+identifier fn2 != tar_filter_config && != git_diff_heuristic_config &&
+ != git_default_submodule_config && != git_color_config &&
+ != bundle_list_update && != parse_object_filter_config;
+identifier C1, C2, D1, D2, S;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D1) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
+
+@ extends get_fn@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int fn(const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+
+// The previous rules don't catch all callbacks, especially if they're defined
+// in a separate file from the git_config() call. Fix these manually.
+@@
+identifier C1, C2, D;
+attribute name UNUSED;
+@@
+int
+(
+git_ident_config
+|
+urlmatch_collect_fn
+|
+write_one_config
+|
+forbid_remote_url
+|
+credential_config_callback
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx UNUSED,
+ void *D) {...}
+
+@@
+identifier C1, C2, D, D2, S, fn2;
+@@
+int
+(
+http_options
+|
+git_status_config
+|
+git_commit_config
+|
+git_default_core_config
+|
+grep_config
+)
+ (const char *C1, const char *C2,
++ const struct config_context *ctx,
+ void *D) {
+<+...
+(
+fn2(C1, C2
++ , ctx
+, D2);
+|
+if(fn2(C1, C2
++ , ctx
+, D2) < 0) { ... }
+|
+return fn2(C1, C2
++ , ctx
+, D2);
+|
+S = fn2(C1, C2
++ , ctx
+, D2);
+)
+...+>
+ }
diff --git a/contrib/coccinelle/equals-null.cocci b/contrib/coccinelle/equals-null.cocci
new file mode 100644
index 0000000..92c7054
--- /dev/null
+++ b/contrib/coccinelle/equals-null.cocci
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+@@
+expression e;
+statement s;
+@@
+if (
+(
+!e
+|
+- e == NULL
++ !e
+)
+ )
+ {...}
+else s
+
+@@
+expression e;
+statement s;
+@@
+if (
+(
+e
+|
+- e != NULL
++ e
+)
+ )
+ {...}
+else s
diff --git a/contrib/coccinelle/free.cocci b/contrib/coccinelle/free.cocci
index 4490069..6fb9eb6 100644
--- a/contrib/coccinelle/free.cocci
+++ b/contrib/coccinelle/free.cocci
@@ -2,13 +2,21 @@
expression E;
@@
- if (E)
+(
free(E);
+|
+ free_commit_list(E);
+)
@@
expression E;
@@
- if (!E)
+(
free(E);
+|
+ free_commit_list(E);
+)
@@
expression E;
@@ -16,3 +24,22 @@ expression E;
- free(E);
+ FREE_AND_NULL(E);
- E = NULL;
+
+@@
+expression E;
+@@
+- if (E)
+- {
+ free_commit_list(E);
+ E = NULL;
+- }
+
+@@
+expression E;
+statement S;
+@@
+- if (E) {
++ if (E)
+ S
+ free_commit_list(E);
+- }
diff --git a/contrib/coccinelle/git_config_number.cocci b/contrib/coccinelle/git_config_number.cocci
new file mode 100644
index 0000000..7b57dce
--- /dev/null
+++ b/contrib/coccinelle/git_config_number.cocci
@@ -0,0 +1,27 @@
+@@
+identifier C1, C2, C3;
+@@
+(
+(
+git_config_int
+|
+git_config_int64
+|
+git_config_ulong
+|
+git_config_ssize_t
+)
+ (C1, C2
++ , ctx->kvi
+ )
+|
+(
+git_configset_get_value
+|
+git_config_bool_or_int
+)
+ (C1, C2
++ , ctx->kvi
+ , C3
+ )
+)
diff --git a/contrib/coccinelle/hashmap.cocci b/contrib/coccinelle/hashmap.cocci
index d69e120..c5dbb45 100644
--- a/contrib/coccinelle/hashmap.cocci
+++ b/contrib/coccinelle/hashmap.cocci
@@ -1,4 +1,4 @@
-@ hashmap_entry_init_usage @
+@@
expression E;
struct hashmap_entry HME;
@@
diff --git a/contrib/coccinelle/index-compatibility.cocci b/contrib/coccinelle/index-compatibility.cocci
new file mode 100644
index 0000000..31e36cf
--- /dev/null
+++ b/contrib/coccinelle/index-compatibility.cocci
@@ -0,0 +1,157 @@
+// the_index.* variables
+@@
+identifier AC = active_cache;
+identifier AN = active_nr;
+identifier ACC = active_cache_changed;
+identifier ACT = active_cache_tree;
+@@
+(
+- AC
++ the_index.cache
+|
+- AN
++ the_index.cache_nr
+|
+- ACC
++ the_index.cache_changed
+|
+- ACT
++ the_index.cache_tree
+)
+
+// "the_repository" simple cases
+@@
+@@
+(
+- read_cache
++ repo_read_index
+|
+- read_cache_unmerged
++ repo_read_index_unmerged
+|
+- hold_locked_index
++ repo_hold_locked_index
+)
+ (
++ the_repository,
+ ...)
+
+// "the_repository" special-cases
+@@
+@@
+(
+- read_cache_preload
++ repo_read_index_preload
+)
+ (
++ the_repository,
+ ...
++ , 0
+ )
+
+// "the_index" simple cases
+@@
+@@
+(
+- is_cache_unborn
++ is_index_unborn
+|
+- unmerged_cache
++ unmerged_index
+|
+- rename_cache_entry_at
++ rename_index_entry_at
+|
+- chmod_cache_entry
++ chmod_index_entry
+|
+- cache_file_exists
++ index_file_exists
+|
+- cache_name_is_other
++ index_name_is_other
+|
+- unmerge_cache_entry_at
++ unmerge_index_entry_at
+|
+- add_to_cache
++ add_to_index
+|
+- add_file_to_cache
++ add_file_to_index
+|
+- add_cache_entry
++ add_index_entry
+|
+- remove_file_from_cache
++ remove_file_from_index
+|
+- ce_match_stat
++ ie_match_stat
+|
+- ce_modified
++ ie_modified
+|
+- resolve_undo_clear
++ resolve_undo_clear_index
+|
+- cache_name_pos
++ index_name_pos
+|
+- update_main_cache_tree
++ cache_tree_update
+|
+- discard_cache
++ discard_index
+)
+ (
++ &the_index,
+ ...)
+
+@@
+@@
+(
+- refresh_and_write_cache
++ repo_refresh_and_write_index
+)
+ (
++ the_repository,
+ ...
++ , NULL, NULL, NULL
+ )
+
+// "the_index" special-cases
+@@
+@@
+(
+- read_cache_from
++ read_index_from
+)
+ (
++ &the_index,
+ ...
++ , get_git_dir()
+ )
+
+@@
+@@
+(
+- refresh_cache
++ refresh_index
+)
+ (
++ &the_index,
+ ...
++ , NULL, NULL, NULL
+ )
+
+@@
+expression O;
+@@
+- write_cache_as_tree
++ write_index_as_tree
+ (
+- O,
++ O, &the_index, get_index_file(),
+ ...
+ )
diff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci
index 3e536a9..01f8d69 100644
--- a/contrib/coccinelle/object_id.cocci
+++ b/contrib/coccinelle/object_id.cocci
@@ -1,50 +1,6 @@
@@
struct object_id OID;
@@
-- is_null_sha1(OID.hash)
-+ is_null_oid(&OID)
-
-@@
-struct object_id *OIDPTR;
-@@
-- is_null_sha1(OIDPTR->hash)
-+ is_null_oid(OIDPTR)
-
-@@
-struct object_id OID;
-@@
-- sha1_to_hex(OID.hash)
-+ oid_to_hex(&OID)
-
-@@
-identifier f != oid_to_hex;
-struct object_id *OIDPTR;
-@@
- f(...) {<...
-- sha1_to_hex(OIDPTR->hash)
-+ oid_to_hex(OIDPTR)
- ...>}
-
-@@
-expression E;
-struct object_id OID;
-@@
-- sha1_to_hex_r(E, OID.hash)
-+ oid_to_hex_r(E, &OID)
-
-@@
-identifier f != oid_to_hex_r;
-expression E;
-struct object_id *OIDPTR;
-@@
- f(...) {<...
-- sha1_to_hex_r(E, OIDPTR->hash)
-+ oid_to_hex_r(E, OIDPTR)
- ...>}
-
-@@
-struct object_id OID;
-@@
- hashclr(OID.hash)
+ oidclr(&OID)
diff --git a/contrib/coccinelle/preincr.cocci b/contrib/coccinelle/preincr.cocci
index 7fe1e8d..ae42cb0 100644
--- a/contrib/coccinelle/preincr.cocci
+++ b/contrib/coccinelle/preincr.cocci
@@ -1,4 +1,4 @@
-@ preincrement @
+@@
identifier i;
@@
- ++i > 1
diff --git a/contrib/coccinelle/spatchcache b/contrib/coccinelle/spatchcache
new file mode 100755
index 0000000..29e9352
--- /dev/null
+++ b/contrib/coccinelle/spatchcache
@@ -0,0 +1,304 @@
+#!/bin/sh
+#
+# spatchcache: a poor-man's "ccache"-alike for "spatch" in git.git
+#
+# This caching command relies on the peculiarities of the Makefile
+# driving "spatch" in git.git, in particular if we invoke:
+#
+# make
+# # See "spatchCache.cacheWhenStderr" for why "--very-quiet" is
+# # used
+# make coccicheck SPATCH_FLAGS=--very-quiet
+#
+# We can with COMPUTE_HEADER_DEPENDENCIES (auto-detected as true with
+# "gcc" and "clang") write e.g. a .depend/grep.o.d for grep.c, when we
+# compile grep.o.
+#
+# The .depend/grep.o.d will have the full header dependency tree of
+# grep.c, and we can thus cache the output of "spatch" by:
+#
+# 1. Hashing all of those files
+# 2. Hashing our source file, and the *.cocci rule we're
+# applying
+# 3. Running spatch, if suggests no changes (by far the common
+# case) we invoke "spatchCache.getCmd" and
+# "spatchCache.setCmd" with a hash SHA-256 to ask "does this
+# ID have no changes" or "say that ID had no changes>
+# 4. If no "spatchCache.{set,get}Cmd" is specified we'll use
+# "redis-cli" and maintain a SET called "spatch-cache". Set
+# appropriate redis memory policies to keep it from growing
+# out of control.
+#
+# This along with the general incremental "make" support for
+# "contrib/coccinelle" makes it viable to (re-)run coccicheck
+# e.g. when merging integration branches.
+#
+# Note that the "--very-quiet" flag is currently critical. The cache
+# will refuse to cache anything that has output on STDERR (which might
+# be errors from spatch), but see spatchCache.cacheWhenStderr below.
+#
+# The STDERR (and exit code) could in principle be cached (as with
+# ccache), but then the simple structure in the Redis cache would need
+# to change, so just supply "--very-quiet" for now.
+#
+# To use this, simply set SPATCH to
+# contrib/coccinelle/spatchcache. Then optionally set:
+#
+# [spatchCache]
+# # Optional: path to a custom spatch
+# spatch = ~/g/coccicheck/spatch.opt
+#
+# As well as this trace config (debug implies trace):
+#
+# cacheWhenStderr = true
+# trace = false
+# debug = false
+#
+# The ".depend/grep.o.d" can also be customized, as a string that will
+# be eval'd, it has access to a "$dirname" and "$basename":
+#
+# [spatchCache]
+# dependFormat = "$dirname/.depend/${basename%.c}.o.d"
+#
+# Setting "trace" to "true" allows for seeing when we have a cache HIT
+# or MISS. To debug whether the cache is working do that, and run e.g.:
+#
+# redis-cli FLUSHALL
+# <make && make coccicheck, as above>
+# grep -hore HIT -e MISS -e SET -e NOCACHE -e CANTCACHE .build/contrib/coccinelle | sort | uniq -c
+# 600 CANTCACHE
+# 7365 MISS
+# 7365 SET
+#
+# A subsequent "make cocciclean && make coccicheck" should then have
+# all "HIT"'s and "CANTCACHE"'s.
+#
+# The "spatchCache.cacheWhenStderr" option is critical when using
+# spatchCache.{trace,debug} to debug whether something is set in the
+# cache, as we'll write to the spatch logs in .build/* we'd otherwise
+# always emit a NOCACHE.
+#
+# Reading the config can make the command much slower, to work around
+# this the config can be set in the environment, with environment
+# variable name corresponding to the config key. "default" can be used
+# to use whatever's the script default, e.g. setting
+# spatchCache.cacheWhenStderr=true and deferring to the defaults for
+# the rest is:
+#
+# export GIT_CONTRIB_SPATCHCACHE_DEBUG=default
+# export GIT_CONTRIB_SPATCHCACHE_TRACE=default
+# export GIT_CONTRIB_SPATCHCACHE_CACHEWHENSTDERR=true
+# export GIT_CONTRIB_SPATCHCACHE_SPATCH=default
+# export GIT_CONTRIB_SPATCHCACHE_DEPENDFORMAT=default
+# export GIT_CONTRIB_SPATCHCACHE_SETCMD=default
+# export GIT_CONTRIB_SPATCHCACHE_GETCMD=default
+
+set -e
+
+env_or_config () {
+ env="$1"
+ shift
+ if test "$env" = "default"
+ then
+ # Avoid expensive "git config" invocation
+ return
+ elif test -n "$env"
+ then
+ echo "$env"
+ else
+ git config $@ || :
+ fi
+}
+
+## Our own configuration & options
+debug=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_DEBUG" --bool "spatchCache.debug")
+if test "$debug" != "true"
+then
+ debug=
+fi
+if test -n "$debug"
+then
+ set -x
+fi
+
+trace=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_TRACE" --bool "spatchCache.trace")
+if test "$trace" != "true"
+then
+ trace=
+fi
+if test -n "$debug"
+then
+ # debug implies trace
+ trace=true
+fi
+
+cacheWhenStderr=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_CACHEWHENSTDERR" --bool "spatchCache.cacheWhenStderr")
+if test "$cacheWhenStderr" != "true"
+then
+ cacheWhenStderr=
+fi
+
+trace_it () {
+ if test -z "$trace"
+ then
+ return
+ fi
+ echo "$@" >&2
+}
+
+spatch=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_SPATCH" --path "spatchCache.spatch")
+if test -n "$spatch"
+then
+ if test -n "$debug"
+ then
+ trace_it "custom spatchCache.spatch='$spatch'"
+ fi
+else
+ spatch=spatch
+fi
+
+dependFormat='$dirname/.depend/${basename%.c}.o.d'
+dependFormatCfg=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_DEPENDFORMAT" "spatchCache.dependFormat")
+if test -n "$dependFormatCfg"
+then
+ dependFormat="$dependFormatCfg"
+fi
+
+set=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_SETCMD" "spatchCache.setCmd")
+get=$(env_or_config "$GIT_CONTRIB_SPATCHCACHE_GETCMD" "spatchCache.getCmd")
+
+## Parse spatch()-like command-line for caching info
+arg_sp=
+arg_file=
+args="$@"
+spatch_opts() {
+ while test $# != 0
+ do
+ arg_file="$1"
+ case "$1" in
+ --sp-file)
+ arg_sp="$2"
+ ;;
+ esac
+ shift
+ done
+}
+spatch_opts "$@"
+if ! test -f "$arg_file"
+then
+ arg_file=
+fi
+
+hash_for_cache() {
+ # Parameters that should affect the cache
+ echo "args=$args"
+ echo "config spatchCache.spatch=$spatch"
+ echo "config spatchCache.debug=$debug"
+ echo "config spatchCache.trace=$trace"
+ echo "config spatchCache.cacheWhenStderr=$cacheWhenStderr"
+ echo
+
+ # Our target file and its dependencies
+ git hash-object "$1" "$2" $(grep -E -o '^[^:]+:$' "$3" | tr -d ':')
+}
+
+# Sanity checks
+if ! test -f "$arg_sp" && ! test -f "$arg_file"
+then
+ echo $0: no idea how to cache "$@" >&2
+ exit 128
+fi
+
+# Main logic
+dirname=$(dirname "$arg_file")
+basename=$(basename "$arg_file")
+eval "dep=$dependFormat"
+
+if ! test -f "$dep"
+then
+ trace_it "$0: CANTCACHE have no '$dep' for '$arg_file'!"
+ exec "$spatch" "$@"
+fi
+
+if test -n "$debug"
+then
+ trace_it "$0: The full cache input for '$arg_sp' '$arg_file' '$dep'"
+ hash_for_cache "$arg_sp" "$arg_file" "$dep" >&2
+fi
+sum=$(hash_for_cache "$arg_sp" "$arg_file" "$dep" | git hash-object --stdin)
+
+trace_it "$0: processing '$arg_file' with '$arg_sp' rule, and got hash '$sum' for it + '$dep'"
+
+getret=
+if test -z "$get"
+then
+ if test $(redis-cli SISMEMBER spatch-cache "$sum") = 1
+ then
+ getret=0
+ else
+ getret=1
+ fi
+else
+ $set "$sum"
+ getret=$?
+fi
+
+if test "$getret" = 0
+then
+ trace_it "$0: HIT for '$arg_file' with '$arg_sp'"
+ exit 0
+else
+ trace_it "$0: MISS: for '$arg_file' with '$arg_sp'"
+fi
+
+out="$(mktemp)"
+err="$(mktemp)"
+
+set +e
+"$spatch" "$@" >"$out" 2>>"$err"
+ret=$?
+cat "$out"
+cat "$err" >&2
+set -e
+
+nocache=
+if test $ret != 0
+then
+ nocache="exited non-zero: $ret"
+elif test -s "$out"
+then
+ nocache="had patch output"
+elif test -z "$cacheWhenStderr" && test -s "$err"
+then
+ nocache="had stderr (use --very-quiet or spatchCache.cacheWhenStderr=true?)"
+fi
+
+if test -n "$nocache"
+then
+ trace_it "$0: NOCACHE ($nocache): for '$arg_file' with '$arg_sp'"
+ exit "$ret"
+fi
+
+trace_it "$0: SET: for '$arg_file' with '$arg_sp'"
+
+setret=
+if test -z "$set"
+then
+ if test $(redis-cli SADD spatch-cache "$sum") = 1
+ then
+ setret=0
+ else
+ setret=1
+ fi
+else
+ "$set" "$sum"
+ setret=$?
+fi
+
+if test "$setret" != 0
+then
+ echo "FAILED to set '$sum' in cache!" >&2
+ exit 128
+fi
+
+exit "$ret"
diff --git a/contrib/coccinelle/strbuf.cocci b/contrib/coccinelle/strbuf.cocci
index d9ada69..5f06105 100644
--- a/contrib/coccinelle/strbuf.cocci
+++ b/contrib/coccinelle/strbuf.cocci
@@ -1,4 +1,4 @@
-@ strbuf_addf_with_format_only @
+@@
expression E;
constant fmt !~ "%";
@@
@@ -15,7 +15,7 @@ constant fmt !~ "%";
@@
expression E;
struct strbuf SB;
-format F =~ "s";
+format F =~ "^s$";
@@
- strbuf_addf(E, "%@F@", SB.buf);
+ strbuf_addbuf(E, &SB);
@@ -23,7 +23,7 @@ format F =~ "s";
@@
expression E;
struct strbuf *SBP;
-format F =~ "s";
+format F =~ "^s$";
@@
- strbuf_addf(E, "%@F@", SBP->buf);
+ strbuf_addbuf(E, SBP);
@@ -44,7 +44,7 @@ struct strbuf *SBP;
@@
expression E1, E2;
-format F =~ "s";
+format F =~ "^s$";
@@
- strbuf_addf(E1, "%@F@", E2);
+ strbuf_addstr(E1, E2);
diff --git a/contrib/coccinelle/swap.cocci b/contrib/coccinelle/swap.cocci
index a0934d1..522177a 100644
--- a/contrib/coccinelle/swap.cocci
+++ b/contrib/coccinelle/swap.cocci
@@ -1,4 +1,4 @@
-@ swap_with_declaration @
+@@
type T;
identifier tmp;
T a, b;
diff --git a/contrib/coccinelle/tests/free.c b/contrib/coccinelle/tests/free.c
new file mode 100644
index 0000000..96d4abc
--- /dev/null
+++ b/contrib/coccinelle/tests/free.c
@@ -0,0 +1,11 @@
+int use_FREE_AND_NULL(int *v)
+{
+ free(*v);
+ *v = NULL;
+}
+
+int need_no_if(int *v)
+{
+ if (v)
+ free(v);
+}
diff --git a/contrib/coccinelle/tests/free.res b/contrib/coccinelle/tests/free.res
new file mode 100644
index 0000000..f90fd9f
--- /dev/null
+++ b/contrib/coccinelle/tests/free.res
@@ -0,0 +1,9 @@
+int use_FREE_AND_NULL(int *v)
+{
+ FREE_AND_NULL(*v);
+}
+
+int need_no_if(int *v)
+{
+ free(v);
+}
diff --git a/contrib/coccinelle/the_repository.cocci b/contrib/coccinelle/the_repository.cocci
new file mode 100644
index 0000000..765ad68
--- /dev/null
+++ b/contrib/coccinelle/the_repository.cocci
@@ -0,0 +1,123 @@
+// Fully migrated "the_repository" additions
+@@
+@@
+(
+// cache.h
+- get_oid
++ repo_get_oid
+|
+- get_oid_commit
++ repo_get_oid_commit
+|
+- get_oid_committish
++ repo_get_oid_committish
+|
+- get_oid_tree
++ repo_get_oid_tree
+|
+- get_oid_treeish
++ repo_get_oid_treeish
+|
+- get_oid_blob
++ repo_get_oid_blob
+|
+- get_oid_mb
++ repo_get_oid_mb
+|
+- find_unique_abbrev
++ repo_find_unique_abbrev
+|
+- find_unique_abbrev_r
++ repo_find_unique_abbrev_r
+|
+- for_each_abbrev
++ repo_for_each_abbrev
+|
+- interpret_branch_name
++ repo_interpret_branch_name
+|
+- peel_to_type
++ repo_peel_to_type
+// commit-reach.h
+|
+- get_merge_bases
++ repo_get_merge_bases
+|
+- get_merge_bases_many
++ repo_get_merge_bases_many
+|
+- get_merge_bases_many_dirty
++ repo_get_merge_bases_many_dirty
+|
+- in_merge_bases
++ repo_in_merge_bases
+|
+- in_merge_bases_many
++ repo_in_merge_bases_many
+// commit.h
+|
+- parse_commit_internal
++ repo_parse_commit_internal
+|
+- parse_commit
++ repo_parse_commit
+|
+- get_commit_buffer
++ repo_get_commit_buffer
+|
+- unuse_commit_buffer
++ repo_unuse_commit_buffer
+|
+- logmsg_reencode
++ repo_logmsg_reencode
+|
+- get_commit_tree
++ repo_get_commit_tree
+// diff.h
+|
+- diff_setup
++ repo_diff_setup
+// object-store.h
+|
+- read_object_file
++ repo_read_object_file
+|
+- has_object_file
++ repo_has_object_file
+|
+- has_object_file_with_flags
++ repo_has_object_file_with_flags
+// pretty.h
+|
+- format_commit_message
++ repo_format_commit_message
+// packfile.h
+|
+- approximate_object_count
++ repo_approximate_object_count
+// promisor-remote.h
+|
+- promisor_remote_reinit
++ repo_promisor_remote_reinit
+|
+- promisor_remote_find
++ repo_promisor_remote_find
+|
+- has_promisor_remote
++ repo_has_promisor_remote
+// refs.h
+|
+- dwim_ref
++ repo_dwim_ref
+// rerere.h
+|
+- rerere
++ repo_rerere
+// revision.h
+|
+- init_revisions
++ repo_init_revisions
+)
+ (
++ the_repository,
+ ...)
diff --git a/contrib/coccinelle/the_repository.pending.cocci b/contrib/coccinelle/the_repository.pending.cocci
deleted file mode 100644
index 2ee702e..0000000
--- a/contrib/coccinelle/the_repository.pending.cocci
+++ /dev/null
@@ -1,144 +0,0 @@
-// This file is used for the ongoing refactoring of
-// bringing the index or repository struct in all of
-// our code base.
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- read_object_file(
-+ repo_read_object_file(the_repository,
- E, F, G)
-
-@@
-expression E;
-@@
-- has_sha1_file(
-+ repo_has_sha1_file(the_repository,
- E)
-
-@@
-expression E;
-expression F;
-@@
-- has_sha1_file_with_flags(
-+ repo_has_sha1_file_with_flags(the_repository,
- E)
-
-@@
-expression E;
-@@
-- has_object_file(
-+ repo_has_object_file(the_repository,
- E)
-
-@@
-expression E;
-expression F;
-@@
-- has_object_file_with_flags(
-+ repo_has_object_file_with_flags(the_repository,
- E)
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- parse_commit_internal(
-+ repo_parse_commit_internal(the_repository,
- E, F, G)
-
-@@
-expression E;
-expression F;
-@@
-- parse_commit_gently(
-+ repo_parse_commit_gently(the_repository,
- E, F)
-
-@@
-expression E;
-@@
-- parse_commit(
-+ repo_parse_commit(the_repository,
- E)
-
-@@
-expression E;
-expression F;
-@@
-- get_merge_bases(
-+ repo_get_merge_bases(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- get_merge_bases_many(
-+ repo_get_merge_bases_many(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- get_merge_bases_many_dirty(
-+ repo_get_merge_bases_many_dirty(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-@@
-- in_merge_bases(
-+ repo_in_merge_bases(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- in_merge_bases_many(
-+ repo_in_merge_bases_many(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-@@
-- get_commit_buffer(
-+ repo_get_commit_buffer(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-@@
-- unuse_commit_buffer(
-+ repo_unuse_commit_buffer(the_repository,
- E, F);
-
-@@
-expression E;
-expression F;
-expression G;
-@@
-- logmsg_reencode(
-+ repo_logmsg_reencode(the_repository,
- E, F, G);
-
-@@
-expression E;
-expression F;
-expression G;
-expression H;
-@@
-- format_commit_message(
-+ repo_format_commit_message(the_repository,
- E, F, G, H);
diff --git a/contrib/coccinelle/xcalloc.cocci b/contrib/coccinelle/xcalloc.cocci
new file mode 100644
index 0000000..c291011
--- /dev/null
+++ b/contrib/coccinelle/xcalloc.cocci
@@ -0,0 +1,10 @@
+@@
+type T;
+T *ptr;
+expression n;
+@@
+ xcalloc(
++ n,
+ \( sizeof(T) \| sizeof(*ptr) \)
+- , n
+ )
diff --git a/contrib/coccinelle/xopen.cocci b/contrib/coccinelle/xopen.cocci
new file mode 100644
index 0000000..b71db67
--- /dev/null
+++ b/contrib/coccinelle/xopen.cocci
@@ -0,0 +1,19 @@
+@@
+identifier fd;
+identifier die_fn =~ "^(die|die_errno)$";
+@@
+ int fd =
+- open
++ xopen
+ (...);
+- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); }
+
+@@
+expression fd;
+identifier die_fn =~ "^(die|die_errno)$";
+@@
+ fd =
+- open
++ xopen
+ (...);
+- if ( \( fd < 0 \| fd == -1 \) ) { die_fn(...); }
diff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/contrib/coccinelle/xstrdup_or_null.cocci
index 8e05d1c..9c1d293 100644
--- a/contrib/coccinelle/xstrdup_or_null.cocci
+++ b/contrib/coccinelle/xstrdup_or_null.cocci
@@ -1,13 +1,5 @@
@@
expression E;
-expression V;
-@@
-- if (E)
-- V = xstrdup(E);
-+ V = xstrdup_or_null(E);
-
-@@
-expression E;
@@
- xstrdup(absolute_path(E))
+ absolute_pathdup(E)
diff --git a/contrib/coccinelle/xstrncmpz.cocci b/contrib/coccinelle/xstrncmpz.cocci
new file mode 100644
index 0000000..ccb39e2
--- /dev/null
+++ b/contrib/coccinelle/xstrncmpz.cocci
@@ -0,0 +1,28 @@
+@@
+expression S, T, L;
+@@
+(
+- strncmp(S, T, L) || S[L]
++ !!xstrncmpz(S, T, L)
+|
+- strncmp(S, T, L) || S[L] != '\0'
++ !!xstrncmpz(S, T, L)
+|
+- strncmp(S, T, L) || T[L]
++ !!xstrncmpz(T, S, L)
+|
+- strncmp(S, T, L) || T[L] != '\0'
++ !!xstrncmpz(T, S, L)
+|
+- !strncmp(S, T, L) && !S[L]
++ !xstrncmpz(S, T, L)
+|
+- !strncmp(S, T, L) && S[L] == '\0'
++ !xstrncmpz(S, T, L)
+|
+- !strncmp(S, T, L) && !T[L]
++ !xstrncmpz(T, S, L)
+|
+- !strncmp(S, T, L) && T[L] == '\0'
++ !xstrncmpz(T, S, L)
+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 00fbe6c..75193de 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -28,6 +28,17 @@
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
+# Note that "git" is optional --- '!f() { : commit; ...}; f' would complete
+# just like the 'git commit' command.
+#
+# If you have a command that is not part of git, but you would still
+# like completion, you can use __git_complete:
+#
+# __git_complete gl git_log
+#
+# Or if it's a main command (i.e. git or gitk):
+#
+# __git_complete gk gitk
#
# Compatible with bash 3.2.57.
#
@@ -39,6 +50,22 @@
# When set to "1", do not include "DWIM" suggestions in git-checkout
# and git-switch completion (e.g., completing "foo" when "origin/foo"
# exists).
+#
+# GIT_COMPLETION_SHOW_ALL_COMMANDS
+#
+# When set to "1" suggest all commands, including plumbing commands
+# which are hidden by default (e.g. "cat-file" on "git ca<TAB>").
+#
+# GIT_COMPLETION_SHOW_ALL
+#
+# When set to "1" suggest all options, including options which are
+# typically hidden (e.g. '--allow-empty' for 'git commit').
+#
+# GIT_COMPLETION_IGNORE_CASE
+#
+# When set, uses for-each-ref '--ignore-case' to find refs that match
+# case insensitively, even on systems with case sensitive file systems
+# (e.g., completing tag name "FOO" on "git checkout f<TAB>").
case "$COMP_WORDBREAKS" in
*:*) : great ;;
@@ -50,7 +77,7 @@ esac
# variable.
__git_find_repo_path ()
{
- if [ -n "$__git_repo_path" ]; then
+ if [ -n "${__git_repo_path-}" ]; then
# we already know where it is
return
fi
@@ -63,7 +90,7 @@ __git_find_repo_path ()
test -d "$__git_dir" &&
__git_repo_path="$__git_dir"
elif [ -n "${GIT_DIR-}" ]; then
- test -d "${GIT_DIR-}" &&
+ test -d "$GIT_DIR" &&
__git_repo_path="$GIT_DIR"
elif [ -d .git ]; then
__git_repo_path=.git
@@ -95,6 +122,40 @@ __git ()
${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null
}
+# Helper function to read the first line of a file into a variable.
+# __git_eread requires 2 arguments, the file path and the name of the
+# variable, in that order.
+#
+# This is taken from git-prompt.sh.
+__git_eread ()
+{
+ test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1"
+}
+
+# Runs git in $__git_repo_path to determine whether a pseudoref exists.
+# 1: The pseudo-ref to search
+__git_pseudoref_exists ()
+{
+ local ref=$1
+ local head
+
+ __git_find_repo_path
+
+ # If the reftable is in use, we have to shell out to 'git rev-parse'
+ # to determine whether the ref exists instead of looking directly in
+ # the filesystem to determine whether the ref exists. Otherwise, use
+ # Bash builtins since executing Git commands are expensive on some
+ # platforms.
+ if __git_eread "$__git_repo_path/HEAD" head; then
+ if [ "$head" == "ref: refs/heads/.invalid" ]; then
+ __git show-ref --exists "$ref"
+ return $?
+ fi
+ fi
+
+ [ -f "$__git_repo_path/$ref" ]
+}
+
# Removes backslash escaping, single quotes and double quotes from a word,
# stores the result in the variable $dequoted_word.
# 1: The word to dequote.
@@ -301,6 +362,19 @@ __gitcomp_direct ()
COMPREPLY=($1)
}
+# Similar to __gitcomp_direct, but appends to COMPREPLY instead.
+# Callers must take care of providing only words that match the current word
+# to be completed and adding any prefix and/or suffix (trailing space!), if
+# necessary.
+# 1: List of newline-separated matching completion words, complete with
+# prefix and suffix.
+__gitcomp_direct_append ()
+{
+ local IFS=$'\n'
+
+ COMPREPLY+=($1)
+}
+
__gitcompappend ()
{
local x i=${#COMPREPLY[@]}
@@ -329,7 +403,7 @@ __gitcomp ()
local cur_="${3-$cur}"
case "$cur_" in
- --*=)
+ *=)
;;
--no-*)
local c i=0 IFS=$' \t\n'
@@ -373,35 +447,43 @@ __gitcomp ()
# Clear the variables caching builtins' options when (re-)sourcing
# the completion script.
if [[ -n ${ZSH_VERSION-} ]]; then
- unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null
+ unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null
else
unset $(compgen -v __gitcomp_builtin_)
fi
# This function is equivalent to
#
-# __gitcomp "$(git xxx --git-completion-helper) ..."
+# ___git_resolved_builtins=$(git xxx --git-completion-helper)
#
-# except that the output is cached. Accept 1-3 arguments:
+# except that the result of the execution is cached.
+#
+# Accept 1-3 arguments:
# 1: the git command to execute, this is also the cache key
+# (use "_" when the command contains spaces, e.g. "remote add"
+# becomes "remote_add")
# 2: extra options to be added on top (e.g. negative forms)
# 3: options to be excluded
-__gitcomp_builtin ()
+__git_resolve_builtins ()
{
- # spaces must be replaced with underscore for multi-word
- # commands, e.g. "git remote add" becomes remote_add.
local cmd="$1"
- local incl="$2"
- local excl="$3"
+ local incl="${2-}"
+ local excl="${3-}"
- local var=__gitcomp_builtin_"${cmd/-/_}"
+ local var=__gitcomp_builtin_"${cmd//-/_}"
local options
- eval "options=\$$var"
+ eval "options=\${$var-}"
if [ -z "$options" ]; then
+ local completion_helper
+ if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
+ completion_helper="--git-completion-helper-all"
+ else
+ completion_helper="--git-completion-helper"
+ fi
# leading and trailing spaces are significant to make
# option removal work correctly.
- options=" $incl $(__git ${cmd/_/ } --git-completion-helper) " || return
+ options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return
for i in $excl; do
options="${options/ $i / }"
@@ -409,7 +491,24 @@ __gitcomp_builtin ()
eval "$var=\"$options\""
fi
- __gitcomp "$options"
+ ___git_resolved_builtins="$options"
+}
+
+# This function is equivalent to
+#
+# __gitcomp "$(git xxx --git-completion-helper) ..."
+#
+# except that the output is cached. Accept 1-3 arguments:
+# 1: the git command to execute, this is also the cache key
+# (use "_" when the command contains spaces, e.g. "remote add"
+# becomes "remote_add")
+# 2: extra options to be added on top (e.g. negative forms)
+# 3: options to be excluded
+__gitcomp_builtin ()
+{
+ __git_resolve_builtins "$1" "$2" "$3"
+
+ __gitcomp "$___git_resolved_builtins"
}
# Variation of __gitcomp_nl () that appends to the existing list of
@@ -476,13 +575,33 @@ __gitcomp_file ()
true
}
+# Find the current subcommand for commands that follow the syntax:
+#
+# git <command> <subcommand>
+#
+# 1: List of possible subcommands.
+# 2: Optional subcommand to return when none is found.
+__git_find_subcommand ()
+{
+ local subcommand subcommands="$1" default_subcommand="$2"
+
+ for subcommand in $subcommands; do
+ if [ "$subcommand" = "${words[__git_cmd_idx+1]}" ]; then
+ echo $subcommand
+ return
+ fi
+ done
+
+ echo $default_subcommand
+}
+
# Execute 'git ls-files', unless the --committable option is specified, in
# which case it runs 'git diff-index' to find out the files that can be
# committed. It return paths relative to the directory specified in the first
# argument, and using the options specified in the second argument.
__git_ls_files_helper ()
{
- if [ "$2" == "--committable" ]; then
+ if [ "$2" = "--committable" ]; then
__git -C "$1" -c core.quotePath=false diff-index \
--name-only --relative HEAD -- "${3//\\/\\\\}*"
else
@@ -504,7 +623,7 @@ __git_index_files ()
{
local root="$2" match="$3"
- __git_ls_files_helper "$root" "$1" "$match" |
+ __git_ls_files_helper "$root" "$1" "${match:-?}" |
awk -F / -v pfx="${2//\\/\\\\}" '{
paths[$1] = 1
}
@@ -550,7 +669,7 @@ __git_index_files ()
esc_idx, 1)
} else if (esc == "n") {
# Uh-oh, a newline character.
- # We cant reliably put a pathname
+ # We cannot reliably put a pathname
# containing a newline into COMPREPLY,
# and the newline would create a mess.
# Skip this path.
@@ -565,7 +684,7 @@ __git_index_files ()
}
}
# Drop closing double quote, if there is one.
- # (There isnt any if this is a directory, as it was
+ # (There is not any if this is a directory, as it was
# already stripped with the trailing path components.)
if (substr(p, length(p), 1) == "\"")
out = out substr(p, 1, length(p) - 1)
@@ -608,9 +727,24 @@ __git_heads ()
local pfx="${1-}" cur_="${2-}" sfx="${3-}"
__git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
"refs/heads/$cur_*" "refs/heads/$cur_*/**"
}
+# Lists branches from remote repositories.
+# 1: A prefix to be added to each listed branch (optional).
+# 2: List only branches matching this word (optional; list all branches if
+# unset or empty).
+# 3: A suffix to be appended to each listed branch (optional).
+__git_remote_heads ()
+{
+ local pfx="${1-}" cur_="${2-}" sfx="${3-}"
+
+ __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
+ "refs/remotes/$cur_*" "refs/remotes/$cur_*/**"
+}
+
# Lists tags from the local repository.
# Accepts the same positional parameters as __git_heads() above.
__git_tags ()
@@ -618,9 +752,31 @@ __git_tags ()
local pfx="${1-}" cur_="${2-}" sfx="${3-}"
__git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
"refs/tags/$cur_*" "refs/tags/$cur_*/**"
}
+# List unique branches from refs/remotes used for 'git checkout' and 'git
+# switch' tracking DWIMery.
+# 1: A prefix to be added to each listed branch (optional)
+# 2: List only branches matching this word (optional; list all branches if
+# unset or empty).
+# 3: A suffix to be appended to each listed branch (optional).
+__git_dwim_remote_heads ()
+{
+ local pfx="${1-}" cur_="${2-}" sfx="${3-}"
+ local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
+
+ # employ the heuristic used by git checkout and git switch
+ # Try to find a remote branch that cur_es the completion word
+ # but only output if the branch name is unique
+ __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
+ --sort="refname:strip=3" \
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
+ "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \
+ uniq -u
+}
+
# Lists refs from the local (by default) or from a remote repository.
# It accepts 0, 1 or 2 arguments:
# 1: The remote to list refs from (optional; ignored, if set but empty).
@@ -641,6 +797,7 @@ __git_refs ()
local format refs
local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}"
local match="${4-}"
+ local umatch="${4-}"
local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers
__git_find_repo_path
@@ -664,12 +821,19 @@ __git_refs ()
fi
fi
+ if test "${GIT_COMPLETION_IGNORE_CASE:+1}" = "1"
+ then
+ # uppercase with tr instead of ${match,^^} for bash 3.2 compatibility
+ umatch=$(echo "$match" | tr a-z A-Z 2>/dev/null || echo "$match")
+ fi
+
if [ "$list_refs_from" = path ]; then
if [[ "$cur_" == ^* ]]; then
pfx="$pfx^"
fer_pfx="$fer_pfx^"
cur_=${cur_#^}
match=${match#^}
+ umatch=${umatch#^}
fi
case "$cur_" in
refs|refs/*)
@@ -678,9 +842,9 @@ __git_refs ()
track=""
;;
*)
- for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
+ for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_HEAD AUTO_MERGE; do
case "$i" in
- $match*)
+ $match*|$umatch*)
if [ -e "$dir/$i" ]; then
echo "$pfx$i$sfx"
fi
@@ -694,15 +858,10 @@ __git_refs ()
;;
esac
__git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
"${refs[@]}"
if [ -n "$track" ]; then
- # employ the heuristic used by git checkout
- # Try to find a remote branch that matches the completion word
- # but only output if the branch name is unique
- __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
- --sort="refname:strip=3" \
- "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \
- uniq -u
+ __git_dwim_remote_heads "$pfx" "$match" "$sfx"
fi
return
fi
@@ -719,15 +878,16 @@ __git_refs ()
*)
if [ "$list_refs_from" = remote ]; then
case "HEAD" in
- $match*) echo "${pfx}HEAD$sfx" ;;
+ $match*|$umatch*) echo "${pfx}HEAD$sfx" ;;
esac
__git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \
+ ${GIT_COMPLETION_IGNORE_CASE+--ignore-case} \
"refs/remotes/$remote/$match*" \
"refs/remotes/$remote/$match*/**"
else
local query_symref
case "HEAD" in
- $match*) query_symref="HEAD" ;;
+ $match*|$umatch*) query_symref="HEAD" ;;
esac
__git ls-remote "$remote" $query_symref \
"refs/tags/$match*" "refs/heads/$match*" \
@@ -749,29 +909,51 @@ __git_refs ()
# Usage: __git_complete_refs [<option>]...
# --remote=<remote>: The remote to list refs from, can be the name of a
# configured remote, a path, or a URL.
-# --track: List unique remote branches for 'git checkout's tracking DWIMery.
+# --dwim: List unique remote branches for 'git switch's tracking DWIMery.
# --pfx=<prefix>: A prefix to be added to each ref.
# --cur=<word>: The current ref to be completed. Defaults to the current
# word to be completed.
# --sfx=<suffix>: A suffix to be appended to each ref instead of the default
# space.
+# --mode=<mode>: What set of refs to complete, one of 'refs' (the default) to
+# complete all refs, 'heads' to complete only branches, or
+# 'remote-heads' to complete only remote branches. Note that
+# --remote is only compatible with --mode=refs.
__git_complete_refs ()
{
- local remote track pfx cur_="$cur" sfx=" "
+ local remote= dwim= pfx= cur_="$cur" sfx=" " mode="refs"
while test $# != 0; do
case "$1" in
--remote=*) remote="${1##--remote=}" ;;
- --track) track="yes" ;;
+ --dwim) dwim="yes" ;;
+ # --track is an old spelling of --dwim
+ --track) dwim="yes" ;;
--pfx=*) pfx="${1##--pfx=}" ;;
--cur=*) cur_="${1##--cur=}" ;;
--sfx=*) sfx="${1##--sfx=}" ;;
+ --mode=*) mode="${1##--mode=}" ;;
*) return 1 ;;
esac
shift
done
- __gitcomp_direct "$(__git_refs "$remote" "$track" "$pfx" "$cur_" "$sfx")"
+ # complete references based on the specified mode
+ case "$mode" in
+ refs)
+ __gitcomp_direct "$(__git_refs "$remote" "" "$pfx" "$cur_" "$sfx")" ;;
+ heads)
+ __gitcomp_direct "$(__git_heads "$pfx" "$cur_" "$sfx")" ;;
+ remote-heads)
+ __gitcomp_direct "$(__git_remote_heads "$pfx" "$cur_" "$sfx")" ;;
+ *)
+ return 1 ;;
+ esac
+
+ # Append DWIM remote branch names if requested
+ if [ "$dwim" = "yes" ]; then
+ __gitcomp_direct_append "$(__git_dwim_remote_heads "$pfx" "$cur_" "$sfx")"
+ fi
}
# __git_refs2 requires 1 argument (to pass to __git_refs)
@@ -924,8 +1106,8 @@ __git_complete_revlist ()
__git_complete_remote_or_refspec ()
{
- local cur_="$cur" cmd="${words[1]}"
- local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
+ local cur_="$cur" cmd="${words[__git_cmd_idx]}"
+ local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
if [ "$cmd" = "remote" ]; then
((c++))
fi
@@ -1047,37 +1229,72 @@ __git_pretty_aliases ()
# __git_aliased_command requires 1 argument
__git_aliased_command ()
{
- local word cmdline=$(__git config --get "alias.$1")
- for word in $cmdline; do
- case "$word" in
- \!gitk|gitk)
- echo "gitk"
- return
- ;;
- \!*) : shell command alias ;;
- -*) : option ;;
- *=*) : setting env ;;
- git) : git itself ;;
- \(\)) : skip parens of shell function definition ;;
- {) : skip start of shell helper function ;;
- :) : skip null command ;;
- \'*) : skip opening quote after sh -c ;;
- *)
- echo "$word"
+ local cur=$1 last list= word cmdline
+
+ while [[ -n "$cur" ]]; do
+ if [[ "$list" == *" $cur "* ]]; then
+ # loop detected
return
- esac
+ fi
+
+ cmdline=$(__git config --get "alias.$cur")
+ list=" $cur $list"
+ last=$cur
+ cur=
+
+ for word in $cmdline; do
+ case "$word" in
+ \!gitk|gitk)
+ cur="gitk"
+ break
+ ;;
+ \!*) : shell command alias ;;
+ -*) : option ;;
+ *=*) : setting env ;;
+ git) : git itself ;;
+ \(\)) : skip parens of shell function definition ;;
+ {) : skip start of shell helper function ;;
+ :) : skip null command ;;
+ \'*) : skip opening quote after sh -c ;;
+ *)
+ cur="${word%;}"
+ break
+ esac
+ done
done
+
+ cur=$last
+ if [[ "$cur" != "$1" ]]; then
+ echo "$cur"
+ fi
}
-# __git_find_on_cmdline requires 1 argument
+# Check whether one of the given words is present on the command line,
+# and print the first word found.
+#
+# Usage: __git_find_on_cmdline [<option>]... "<wordlist>"
+# --show-idx: Optionally show the index of the found word in the $words array.
__git_find_on_cmdline ()
{
- local word subcommand c=1
+ local word c="$__git_cmd_idx" show_idx
+
+ while test $# -gt 1; do
+ case "$1" in
+ --show-idx) show_idx=y ;;
+ *) return 1 ;;
+ esac
+ shift
+ done
+ local wordlist="$1"
+
while [ $c -lt $cword ]; do
- word="${words[c]}"
- for subcommand in $1; do
- if [ "$subcommand" = "$word" ]; then
- echo "$subcommand"
+ for word in $wordlist; do
+ if [ "$word" = "${words[c]}" ]; then
+ if [ -n "${show_idx-}" ]; then
+ echo "$c $word"
+ else
+ echo "$word"
+ fi
return
fi
done
@@ -1085,6 +1302,40 @@ __git_find_on_cmdline ()
done
}
+# Similar to __git_find_on_cmdline, except that it loops backwards and thus
+# prints the *last* word found. Useful for finding which of two options that
+# supersede each other came last, such as "--guess" and "--no-guess".
+#
+# Usage: __git_find_last_on_cmdline [<option>]... "<wordlist>"
+# --show-idx: Optionally show the index of the found word in the $words array.
+__git_find_last_on_cmdline ()
+{
+ local word c=$cword show_idx
+
+ while test $# -gt 1; do
+ case "$1" in
+ --show-idx) show_idx=y ;;
+ *) return 1 ;;
+ esac
+ shift
+ done
+ local wordlist="$1"
+
+ while [ $c -gt "$__git_cmd_idx" ]; do
+ ((c--))
+ for word in $wordlist; do
+ if [ "$word" = "${words[c]}" ]; then
+ if [ -n "$show_idx" ]; then
+ echo "$c $word"
+ else
+ echo "$word"
+ fi
+ return
+ fi
+ done
+ done
+}
+
# Echo the value of an option set on the command line or config
#
# $1: short option name
@@ -1155,7 +1406,7 @@ __git_count_arguments ()
local word i c=0
# Skip "git" (first argument)
- for ((i=1; i < ${#words[@]}; i++)); do
+ for ((i=$__git_cmd_idx; i < ${#words[@]}; i++)); do
word="${words[i]}"
case "$word" in
@@ -1180,7 +1431,9 @@ __git_count_arguments ()
__git_whitespacelist="nowarn warn error error-all fix"
__git_patchformat="mbox stgit stgit-series hg mboxrd"
+__git_showcurrentpatch="diff raw"
__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
+__git_quoted_cr="nowarn warn strip"
_git_am ()
{
@@ -1198,6 +1451,14 @@ _git_am ()
__gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
return
;;
+ --show-current-patch=*)
+ __gitcomp "$__git_showcurrentpatch" "" "${cur##--show-current-patch=}"
+ return
+ ;;
+ --quoted-cr=*)
+ __gitcomp "$__git_quoted_cr" "" "${cur##--quoted-cr=}"
+ return
+ ;;
--*)
__gitcomp_builtin am "" \
"$__git_am_inprogress_options"
@@ -1261,12 +1522,32 @@ _git_bisect ()
{
__git_has_doubledash && return
- local subcommands="start bad good skip reset visualize replay log run"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ __git_find_repo_path
+
+ # If a bisection is in progress get the terms being used.
+ local term_bad term_good
+ if [ -f "$__git_repo_path"/BISECT_TERMS ]; then
+ term_bad=$(__git bisect terms --term-bad)
+ term_good=$(__git bisect terms --term-good)
+ fi
+
+ # We will complete any custom terms, but still always complete the
+ # more usual bad/new/good/old because git bisect gives a good error
+ # message if these are given when not in use, and that's better than
+ # silent refusal to complete if the user is confused.
+ #
+ # We want to recognize 'view' but not complete it, because it overlaps
+ # with 'visualize' too much and is just an alias for it.
+ #
+ local completable_subcommands="start bad new $term_bad good old $term_good terms skip reset visualize replay log run help"
+ local all_subcommands="$completable_subcommands view"
+
+ local subcommand="$(__git_find_on_cmdline "$all_subcommands")"
+
if [ -z "$subcommand" ]; then
__git_find_repo_path
if [ -f "$__git_repo_path"/BISECT_START ]; then
- __gitcomp "$subcommands"
+ __gitcomp "$completable_subcommands"
else
__gitcomp "replay start"
fi
@@ -1274,7 +1555,26 @@ _git_bisect ()
fi
case "$subcommand" in
- bad|good|reset|skip|start)
+ start)
+ case "$cur" in
+ --*)
+ __gitcomp "--first-parent --no-checkout --term-new --term-bad --term-old --term-good"
+ return
+ ;;
+ *)
+ __git_complete_refs
+ ;;
+ esac
+ ;;
+ terms)
+ __gitcomp "--term-good --term-old --term-bad --term-new"
+ return
+ ;;
+ visualize|view)
+ __git_complete_log_opts
+ return
+ ;;
+ bad|new|"$term_bad"|good|old|"$term_good"|reset|skip)
__git_complete_refs
;;
*)
@@ -1286,13 +1586,15 @@ __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD
_git_branch ()
{
- local i c=1 only_local_ref="n" has_r="n"
+ local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
- -d|--delete|-m|--move) only_local_ref="y" ;;
- -r|--remotes) has_r="y" ;;
+ -d|-D|--delete|-m|-M|--move|-c|-C|--copy)
+ only_local_ref="y" ;;
+ -r|--remotes)
+ has_r="y" ;;
esac
((c++))
done
@@ -1316,12 +1618,12 @@ _git_branch ()
_git_bundle ()
{
- local cmd="${words[2]}"
+ local cmd="${words[__git_cmd_idx+1]}"
case "$cword" in
- 2)
+ $((__git_cmd_idx+1)))
__gitcomp "create list-heads verify unbundle"
;;
- 3)
+ $((__git_cmd_idx+2)))
# looking for a file
;;
*)
@@ -1334,26 +1636,96 @@ _git_bundle ()
esac
}
+# Helper function to decide whether or not we should enable DWIM logic for
+# git-switch and git-checkout.
+#
+# To decide between the following rules in decreasing priority order:
+# - the last provided of "--guess" or "--no-guess" explicitly enable or
+# disable completion of DWIM logic respectively.
+# - If checkout.guess is false, disable completion of DWIM logic.
+# - If the --no-track option is provided, take this as a hint to disable the
+# DWIM completion logic
+# - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion
+# logic, as requested by the user.
+# - Enable DWIM logic otherwise.
+#
+__git_checkout_default_dwim_mode ()
+{
+ local last_option dwim_opt="--dwim"
+
+ if [ "${GIT_COMPLETION_CHECKOUT_NO_GUESS-}" = "1" ]; then
+ dwim_opt=""
+ fi
+
+ # --no-track disables DWIM, but with lower priority than
+ # --guess/--no-guess/checkout.guess
+ if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then
+ dwim_opt=""
+ fi
+
+ # checkout.guess = false disables DWIM, but with lower priority than
+ # --guess/--no-guess
+ if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then
+ dwim_opt=""
+ fi
+
+ # Find the last provided --guess or --no-guess
+ last_option="$(__git_find_last_on_cmdline "--guess --no-guess")"
+ case "$last_option" in
+ --guess)
+ dwim_opt="--dwim"
+ ;;
+ --no-guess)
+ dwim_opt=""
+ ;;
+ esac
+
+ echo "$dwim_opt"
+}
+
_git_checkout ()
{
__git_has_doubledash && return
+ local dwim_opt="$(__git_checkout_default_dwim_mode)"
+
+ case "$prev" in
+ -b|-B|--orphan)
+ # Complete local branches (and DWIM branch
+ # remote branch names) for an option argument
+ # specifying a new branch name. This is for
+ # convenience, assuming new branches are
+ # possibly based on pre-existing branch names.
+ __git_complete_refs $dwim_opt --mode="heads"
+ return
+ ;;
+ *)
+ ;;
+ esac
+
case "$cur" in
--conflict=*)
- __gitcomp "diff3 merge" "" "${cur##--conflict=}"
+ __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
;;
--*)
__gitcomp_builtin checkout
;;
*)
- # check if --track, --no-track, or --no-guess was specified
- # if so, disable DWIM mode
- local flags="--track --no-track --no-guess" track_opt="--track"
- if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
- [ -n "$(__git_find_on_cmdline "$flags")" ]; then
- track_opt=''
+ # At this point, we've already handled special completion for
+ # the arguments to -b/-B, and --orphan. There are 3 main
+ # things left we can possibly complete:
+ # 1) a start-point for -b/-B, -d/--detach, or --orphan
+ # 2) a remote head, for --track
+ # 3) an arbitrary reference, possibly including DWIM names
+ #
+
+ if [ -n "$(__git_find_on_cmdline "-b -B -d --detach --orphan")" ]; then
+ __git_complete_refs --mode="refs"
+ elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
+ __git_complete_refs --mode="remote-heads"
+ else
+ __git_complete_refs $dwim_opt --mode="refs"
fi
- __git_complete_refs $track_opt
;;
esac
}
@@ -1364,8 +1736,7 @@ __git_cherry_pick_inprogress_options=$__git_sequencer_inprogress_options
_git_cherry_pick ()
{
- __git_find_repo_path
- if [ -f "$__git_repo_path"/CHERRY_PICK_HEAD ]; then
+ if __git_pseudoref_exists CHERRY_PICK_HEAD; then
__gitcomp "$__git_cherry_pick_inprogress_options"
return
fi
@@ -1419,6 +1790,11 @@ _git_clone ()
__git_untracked_file_modes="all no normal"
+__git_trailer_tokens ()
+{
+ __git config --name-only --get-regexp '^trailer\..*\.key$' | cut -d. -f 2- | rev | cut -d. -f2- | rev
+}
+
_git_commit ()
{
case "$prev" in
@@ -1443,6 +1819,10 @@ _git_commit ()
__gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
return
;;
+ --trailer=*)
+ __gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":"
+ return
+ ;;
--*)
__gitcomp_builtin commit
return
@@ -1470,26 +1850,51 @@ __git_diff_algorithms="myers minimal patience histogram"
__git_diff_submodule_formats="diff log short"
+__git_color_moved_opts="no default plain blocks zebra dimmed-zebra"
+
+__git_color_moved_ws_opts="no ignore-space-at-eol ignore-space-change
+ ignore-all-space allow-indentation-change"
+
+__git_ws_error_highlight_opts="context old new all default"
+
+# Options for the diff machinery (diff, log, show, stash, range-diff, ...)
__git_diff_common_options="--stat --numstat --shortstat --summary
--patch-with-stat --name-only --name-status --color
--no-color --color-words --no-renames --check
+ --color-moved --color-moved= --no-color-moved
+ --color-moved-ws= --no-color-moved-ws
--full-index --binary --abbrev --diff-filter=
+ --find-copies --find-object --find-renames
+ --no-relative --relative
--find-copies-harder --ignore-cr-at-eol
--text --ignore-space-at-eol --ignore-space-change
--ignore-all-space --ignore-blank-lines --exit-code
- --quiet --ext-diff --no-ext-diff
+ --quiet --ext-diff --no-ext-diff --unified=
--no-prefix --src-prefix= --dst-prefix=
- --inter-hunk-context=
+ --inter-hunk-context= --function-context
--patience --histogram --minimal
--raw --word-diff --word-diff-regex=
--dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative
- --diff-algorithm=
+ --diff-algorithm= --default-prefix
--submodule --submodule= --ignore-submodules
--indent-heuristic --no-indent-heuristic
- --textconv --no-textconv
+ --textconv --no-textconv --break-rewrites
+ --patch --no-patch --cc --combined-all-paths
+ --anchored= --compact-summary --ignore-matching-lines=
+ --irreversible-delete --line-prefix --no-stat
+ --output= --output-indicator-context=
+ --output-indicator-new= --output-indicator-old=
+ --ws-error-highlight=
+ --pickaxe-all --pickaxe-regex --patch-with-raw
"
+# Options for diff/difftool
+__git_diff_difftool_options="--cached --staged
+ --base --ours --theirs --no-index --merge-base
+ --ita-invisible-in-index --ita-visible-in-index
+ $__git_diff_common_options"
+
_git_diff ()
{
__git_has_doubledash && return
@@ -1503,11 +1908,20 @@ _git_diff ()
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
+ --color-moved=*)
+ __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
+ return
+ ;;
+ --color-moved-ws=*)
+ __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
+ return
+ ;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
--*)
- __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
- --base --ours --theirs --no-index
- $__git_diff_common_options
- "
+ __gitcomp "$__git_diff_difftool_options"
return
;;
esac
@@ -1515,8 +1929,8 @@ _git_diff ()
}
__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
- tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc
- codecompare smerge
+ tkdiff vimdiff nvimdiff gvimdiff xxdiff araxis p4merge
+ bc codecompare smerge
"
_git_difftool ()
@@ -1529,11 +1943,7 @@ _git_difftool ()
return
;;
--*)
- __gitcomp_builtin difftool "$__git_diff_common_options
- --base --cached --ours --theirs
- --pickaxe-all --pickaxe-regex
- --relative --staged
- "
+ __gitcomp_builtin difftool "$__git_diff_difftool_options"
return
;;
esac
@@ -1575,6 +1985,10 @@ _git_format_patch ()
" "" "${cur##--thread=}"
return
;;
+ --base=*|--interdiff=*|--range-diff=*)
+ __git_complete_refs --cur="${cur#--*=}"
+ return
+ ;;
--*)
__gitcomp_builtin format-patch "$__git_format_patch_extra_options"
return
@@ -1595,7 +2009,7 @@ _git_fsck ()
_git_gitk ()
{
- _gitk
+ __gitk_main
}
# Lists matching symbol names from a tag (as in ctags) file.
@@ -1649,7 +2063,7 @@ _git_grep ()
esac
case "$cword,$prev" in
- 2,*|*,-*)
+ $((__git_cmd_idx+1)),*|*,-*)
__git_complete_symbol && return
;;
esac
@@ -1665,7 +2079,7 @@ _git_help ()
return
;;
esac
- if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
+ if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
then
__gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
else
@@ -1736,6 +2150,16 @@ __git_log_common_options="
--min-age= --until= --before=
--min-parents= --max-parents=
--no-min-parents --no-max-parents
+ --alternate-refs --ancestry-path
+ --author-date-order --basic-regexp
+ --bisect --boundary --exclude-first-parent-only
+ --exclude-hidden --extended-regexp
+ --fixed-strings --grep-reflog
+ --ignore-missing --left-only --perl-regexp
+ --reflog --regexp-ignore-case --remove-empty
+ --right-only --show-linear-break
+ --show-notes-by-default --show-pulls
+ --since-as-filter --single-worktree
"
# Options that go well for log and gitk (not shortlog)
__git_log_gitk_options="
@@ -1748,17 +2172,26 @@ __git_log_shortlog_options="
--author= --committer= --grep=
--all-match --invert-grep
"
+# Options accepted by log and show
+__git_log_show_options="
+ --diff-merges --diff-merges= --no-diff-merges --dd --remerge-diff
+ --encoding=
+"
-__git_log_pretty_formats="oneline short medium full fuller email raw format: mboxrd"
-__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
+__git_diff_merges_opts="off none on first-parent 1 separate m combined c dense-combined cc remerge r"
-_git_log ()
+__git_log_pretty_formats="oneline short medium full fuller reference email raw format: tformat: mboxrd"
+__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default human raw unix auto: format:"
+
+# Complete porcelain (i.e. not git-rev-list) options and at least some
+# option arguments accepted by git-log. Note that this same set of options
+# are also accepted by some other git commands besides git-log.
+__git_complete_log_opts ()
{
- __git_has_doubledash && return
- __git_find_repo_path
+ COMPREPLY=()
local merge=""
- if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
+ if __git_pseudoref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$prev,$cur" in
@@ -1796,15 +2229,24 @@ _git_log ()
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
--no-walk=*)
__gitcomp "sorted unsorted" "" "${cur##--no-walk=}"
return
;;
+ --diff-merges=*)
+ __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
+ return
+ ;;
--*)
__gitcomp "
$__git_log_common_options
$__git_log_shortlog_options
$__git_log_gitk_options
+ $__git_log_show_options
--root --topo-order --date-order --reverse
--follow --full-diff
--abbrev-commit --no-abbrev-commit --abbrev=
@@ -1819,10 +2261,10 @@ _git_log ()
--no-walk --no-walk= --do-walk
--parents --children
--expand-tabs --expand-tabs= --no-expand-tabs
- --patch
+ --clear-decorations --decorate-refs=
+ --decorate-refs-exclude=
$merge
$__git_diff_common_options
- --pickaxe-all --pickaxe-regex
"
return
;;
@@ -1842,6 +2284,16 @@ _git_log ()
return
;;
esac
+}
+
+_git_log ()
+{
+ __git_has_doubledash && return
+ __git_find_repo_path
+
+ __git_complete_log_opts
+ [ ${#COMPREPLY[@]} -eq 0 ] || return
+
__git_complete_revlist
}
@@ -2043,6 +2495,10 @@ _git_rebase ()
__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
return
;;
+ --onto=*)
+ __git_complete_refs --cur="${cur##--onto=}"
+ return
+ ;;
--*)
__gitcomp_builtin rebase "" \
"$__git_rebase_interactive_inprogress_options"
@@ -2054,13 +2510,30 @@ _git_rebase ()
_git_reflog ()
{
- local subcommands="show delete expire"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ local subcommands subcommand
- if [ -z "$subcommand" ]; then
- __gitcomp "$subcommands"
- else
- __git_complete_refs
+ __git_resolve_builtins "reflog"
+
+ subcommands="$___git_resolved_builtins"
+ subcommand="$(__git_find_subcommand "$subcommands" "show")"
+
+ case "$subcommand,$cur" in
+ show,--*)
+ __gitcomp "
+ $__git_log_common_options
+ "
+ return
+ ;;
+ $subcommand,--*)
+ __gitcomp_builtin "reflog_$subcommand"
+ return
+ ;;
+ esac
+
+ __git_complete_refs
+
+ if [ $((cword - __git_cmd_idx)) -eq 1 ]; then
+ __gitcompappend "$subcommands" "" "$cur" " "
fi
}
@@ -2105,16 +2578,7 @@ _git_send_email ()
return
;;
--*)
- __gitcomp_builtin send-email "--annotate --bcc --cc --cc-cmd --chain-reply-to
- --compose --confirm= --dry-run --envelope-sender
- --from --identity
- --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
- --no-suppress-from --no-thread --quiet --reply-to
- --signed-off-by-cc --smtp-pass --smtp-server
- --smtp-server-port --smtp-encryption= --smtp-user
- --subject --suppress-cc= --suppress-from --thread --to
- --validate --no-validate
- $__git_format_patch_extra_options"
+ __gitcomp_builtin send-email "$__git_format_patch_extra_options"
return
;;
esac
@@ -2174,37 +2638,50 @@ _git_status ()
_git_switch ()
{
+ local dwim_opt="$(__git_checkout_default_dwim_mode)"
+
+ case "$prev" in
+ -c|-C|--orphan)
+ # Complete local branches (and DWIM branch
+ # remote branch names) for an option argument
+ # specifying a new branch name. This is for
+ # convenience, assuming new branches are
+ # possibly based on pre-existing branch names.
+ __git_complete_refs $dwim_opt --mode="heads"
+ return
+ ;;
+ *)
+ ;;
+ esac
+
case "$cur" in
--conflict=*)
- __gitcomp "diff3 merge" "" "${cur##--conflict=}"
+ __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
;;
--*)
__gitcomp_builtin switch
;;
*)
- # check if --track, --no-track, or --no-guess was specified
- # if so, disable DWIM mode
- local track_opt="--track" only_local_ref=n
- if [ "$GIT_COMPLETION_CHECKOUT_NO_GUESS" = "1" ] ||
- [ -n "$(__git_find_on_cmdline "--track --no-track --no-guess")" ]; then
- track_opt=''
- fi
- # explicit --guess enables DWIM mode regardless of
- # $GIT_COMPLETION_CHECKOUT_NO_GUESS
- if [ -n "$(__git_find_on_cmdline "--guess")" ]; then
- track_opt='--track'
- fi
- if [ -z "$(__git_find_on_cmdline "-d --detach")" ]; then
- only_local_ref=y
- else
- # --guess --detach is invalid combination, no
- # dwim will be done when --detach is specified
- track_opt=
+ # Unlike in git checkout, git switch --orphan does not take
+ # a start point. Thus we really have nothing to complete after
+ # the branch name.
+ if [ -n "$(__git_find_on_cmdline "--orphan")" ]; then
+ return
fi
- if [ $only_local_ref = y -a -z "$track_opt" ]; then
- __gitcomp_direct "$(__git_heads "" "$cur" " ")"
+
+ # At this point, we've already handled special completion for
+ # -c/-C, and --orphan. There are 3 main things left to
+ # complete:
+ # 1) a start-point for -c/-C or -d/--detach
+ # 2) a remote head, for --track
+ # 3) a branch name, possibly including DWIM remote branches
+
+ if [ -n "$(__git_find_on_cmdline "-c -C -d --detach")" ]; then
+ __git_complete_refs --mode="refs"
+ elif [ -n "$(__git_find_on_cmdline "-t --track")" ]; then
+ __git_complete_refs --mode="remote-heads"
else
- __git_complete_refs $track_opt
+ __git_complete_refs $dwim_opt --mode="heads"
fi
;;
esac
@@ -2213,7 +2690,7 @@ _git_switch ()
__git_config_get_set_variables ()
{
local prevword word config_file= c=$cword
- while [ $c -gt 1 ]; do
+ while [ $c -gt "$__git_cmd_idx" ]; do
word="${words[c]}"
case "$word" in
--system|--global|--local|--file=*)
@@ -2236,7 +2713,41 @@ __git_config_vars=
__git_compute_config_vars ()
{
test -n "$__git_config_vars" ||
- __git_config_vars="$(git help --config-for-completion | sort -u)"
+ __git_config_vars="$(git help --config-for-completion)"
+}
+
+__git_config_vars_all=
+__git_compute_config_vars_all ()
+{
+ test -n "$__git_config_vars_all" ||
+ __git_config_vars_all="$(git --no-pager help --config)"
+}
+
+__git_compute_first_level_config_vars_for_section ()
+{
+ local section="$1"
+ __git_compute_config_vars
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ test -n "${!this_section}" ||
+ printf -v "__git_first_level_config_vars_for_section_${section}" %s \
+ "$(echo "$__git_config_vars" | awk -F. "/^${section}\.[a-z]/ { print \$2 }")"
+}
+
+__git_compute_second_level_config_vars_for_section ()
+{
+ local section="$1"
+ __git_compute_config_vars_all
+ local this_section="__git_second_level_config_vars_for_section_${section}"
+ test -n "${!this_section}" ||
+ printf -v "__git_second_level_config_vars_for_section_${section}" %s \
+ "$(echo "$__git_config_vars_all" | awk -F. "/^${section}\.</ { print \$3 }")"
+}
+
+__git_config_sections=
+__git_compute_config_sections ()
+{
+ test -n "$__git_config_sections" ||
+ __git_config_sections="$(git help --config-sections-for-completion)"
}
# Completes possible values of various configuration variables.
@@ -2276,7 +2787,7 @@ __git_complete_config_variable_value ()
return
;;
branch.*.rebase)
- __gitcomp "false true merges preserve interactive" "" "$cur_"
+ __gitcomp "false true merges interactive" "" "$cur_"
return
;;
remote.pushdefault)
@@ -2376,73 +2887,50 @@ __git_complete_config_variable_name ()
done
case "$cur_" in
- branch.*.*)
+ branch.*.*|guitool.*.*|difftool.*.*|man.*.*|mergetool.*.*|remote.*.*|submodule.*.*|url.*.*)
local pfx="${cur_%.*}."
cur_="${cur_##*.}"
- __gitcomp "remote pushRemote merge mergeOptions rebase" "$pfx" "$cur_" "$sfx"
+ local section="${pfx%.*.}"
+ __git_compute_second_level_config_vars_for_section "${section}"
+ local this_section="__git_second_level_config_vars_for_section_${section}"
+ __gitcomp "${!this_section}" "$pfx" "$cur_" "$sfx"
return
;;
branch.*)
- local pfx="${cur%.*}."
- cur_="${cur#*.}"
- __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
- __gitcomp_nl_append $'autoSetupMerge\nautoSetupRebase\n' "$pfx" "$cur_" "$sfx"
- return
- ;;
- guitool.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "
- argPrompt cmd confirm needsFile noConsole noRescan
- prompt revPrompt revUnmerged title
- " "$pfx" "$cur_" "$sfx"
- return
- ;;
- difftool.*.*)
local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
- return
- ;;
- man.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "cmd path" "$pfx" "$cur_" "$sfx"
- return
- ;;
- mergetool.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" "$sfx"
+ cur_="${cur_#*.}"
+ local section="${pfx%.}"
+ __gitcomp_direct "$(__git_heads "$pfx" "$cur_" ".")"
+ __git_compute_first_level_config_vars_for_section "${section}"
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
return
;;
pager.*)
local pfx="${cur_%.*}."
cur_="${cur_#*.}"
__git_compute_all_commands
- __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "$sfx"
- return
- ;;
- remote.*.*)
- local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "
- url proxy fetch push mirror skipDefaultUpdate
- receivepack uploadpack tagOpt pushurl
- " "$pfx" "$cur_" "$sfx"
+ __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" "${sfx:- }"
return
;;
remote.*)
local pfx="${cur_%.*}."
cur_="${cur_#*.}"
+ local section="${pfx%.}"
__gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
- __gitcomp_nl_append "pushDefault" "$pfx" "$cur_" "$sfx"
+ __git_compute_first_level_config_vars_for_section "${section}"
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
return
;;
- url.*.*)
+ submodule.*)
local pfx="${cur_%.*}."
- cur_="${cur_##*.}"
- __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" "$sfx"
+ cur_="${cur_#*.}"
+ local section="${pfx%.}"
+ __gitcomp_nl "$(__git config -f "$(__git rev-parse --show-toplevel)/.gitmodules" --get-regexp 'submodule.*.path' | awk -F. '{print $2}')" "$pfx" "$cur_" "."
+ __git_compute_first_level_config_vars_for_section "${section}"
+ local this_section="__git_first_level_config_vars_for_section_${section}"
+ __gitcomp_nl_append "${!this_section}" "$pfx" "$cur_" "${sfx:- }"
return
;;
*.*)
@@ -2450,16 +2938,8 @@ __git_complete_config_variable_name ()
__gitcomp "$__git_config_vars" "" "$cur_" "$sfx"
;;
*)
- __git_compute_config_vars
- __gitcomp "$(echo "$__git_config_vars" |
- awk -F . '{
- sections[$1] = 1
- }
- END {
- for (s in sections)
- print s "."
- }
- ')" "" "$cur_"
+ __git_compute_config_sections
+ __gitcomp "$__git_config_sections" "" "$cur_" "."
;;
esac
}
@@ -2611,9 +3091,16 @@ _git_reset ()
_git_restore ()
{
+ case "$prev" in
+ -s)
+ __git_complete_refs
+ return
+ ;;
+ esac
+
case "$cur" in
--conflict=*)
- __gitcomp "diff3 merge" "" "${cur##--conflict=}"
+ __gitcomp "diff3 merge zdiff3" "" "${cur##--conflict=}"
;;
--source=*)
__git_complete_refs --cur="${cur##--source=}"
@@ -2621,6 +3108,10 @@ _git_restore ()
--*)
__gitcomp_builtin restore
;;
+ *)
+ if __git_pseudoref_exists HEAD; then
+ __git_complete_index_file "--modified"
+ fi
esac
}
@@ -2628,8 +3119,7 @@ __git_revert_inprogress_options=$__git_sequencer_inprogress_options
_git_revert ()
{
- __git_find_repo_path
- if [ -f "$__git_repo_path"/REVERT_HEAD ]; then
+ if __git_pseudoref_exists REVERT_HEAD; then
__gitcomp "$__git_revert_inprogress_options"
return
fi
@@ -2691,10 +3181,27 @@ _git_show ()
__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
return
;;
+ --color-moved=*)
+ __gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
+ return
+ ;;
+ --color-moved-ws=*)
+ __gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
+ return
+ ;;
+ --ws-error-highlight=*)
+ __gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
+ return
+ ;;
+ --diff-merges=*)
+ __gitcomp "$__git_diff_merges_opts" "" "${cur##--diff-merges=}"
+ return
+ ;;
--*)
__gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit
- --oneline --show-signature --patch
+ --oneline --show-signature
--expand-tabs --expand-tabs= --no-expand-tabs
+ $__git_log_show_options
$__git_diff_common_options
"
return
@@ -2714,72 +3221,223 @@ _git_show_branch ()
__git_complete_revlist
}
+__gitcomp_directories ()
+{
+ local _tmp_dir _tmp_completions _found=0
+
+ # Get the directory of the current token; this differs from dirname
+ # in that it keeps up to the final trailing slash. If no slash found
+ # that's fine too.
+ [[ "$cur" =~ .*/ ]]
+ _tmp_dir=$BASH_REMATCH
+
+ # Find possible directory completions, adding trailing '/' characters,
+ # de-quoting, and handling unusual characters.
+ while IFS= read -r -d $'\0' c ; do
+ # If there are directory completions, find ones that start
+ # with "$cur", the current token, and put those in COMPREPLY
+ if [[ $c == "$cur"* ]]; then
+ COMPREPLY+=("$c/")
+ _found=1
+ fi
+ done < <(__git ls-tree -z -d --name-only HEAD $_tmp_dir)
+
+ if [[ $_found == 0 ]] && [[ "$cur" =~ /$ ]]; then
+ # No possible further completions any deeper, so assume we're at
+ # a leaf directory and just consider it complete
+ __gitcomp_direct_append "$cur "
+ elif [[ $_found == 0 ]]; then
+ # No possible completions found. Avoid falling back to
+ # bash's default file and directory completion, because all
+ # valid completions have already been searched and the
+ # fallbacks can do nothing but mislead. In fact, they can
+ # mislead in three different ways:
+ # 1) Fallback file completion makes no sense when asking
+ # for directory completions, as this function does.
+ # 2) Fallback directory completion is bad because
+ # e.g. "/pro" is invalid and should NOT complete to
+ # "/proc".
+ # 3) Fallback file/directory completion only completes
+ # on paths that exist in the current working tree,
+ # i.e. which are *already* part of their
+ # sparse-checkout. Thus, normal file and directory
+ # completion is always useless for "git
+ # sparse-checkout add" and is also probelmatic for
+ # "git sparse-checkout set" unless using it to
+ # strictly narrow the checkout.
+ COMPREPLY=( "" )
+ fi
+}
+
+# In non-cone mode, the arguments to {set,add} are supposed to be
+# patterns, relative to the toplevel directory. These can be any kind
+# of general pattern, like 'subdir/*.c' and we can't complete on all
+# of those. However, if the user presses Tab to get tab completion, we
+# presume that they are trying to provide a pattern that names a specific
+# path.
+__gitcomp_slash_leading_paths ()
+{
+ local dequoted_word pfx="" cur_ toplevel
+
+ # Since we are dealing with a sparse-checkout, subdirectories may not
+ # exist in the local working copy. Therefore, we want to run all
+ # ls-files commands relative to the repository toplevel.
+ toplevel="$(git rev-parse --show-toplevel)/"
+
+ __git_dequote "$cur"
+
+ # If the paths provided by the user already start with '/', then
+ # they are considered relative to the toplevel of the repository
+ # already. If they do not start with /, then we need to adjust
+ # them to start with the appropriate prefix.
+ case "$cur" in
+ /*)
+ cur="${cur:1}"
+ ;;
+ *)
+ pfx="$(__git rev-parse --show-prefix)"
+ esac
+
+ # Since sparse-index is limited to cone-mode, in non-cone-mode the
+ # list of valid paths is precisely the cached files in the index.
+ #
+ # NEEDSWORK:
+ # 1) We probably need to take care of cases where ls-files
+ # responds with special quoting.
+ # 2) We probably need to take care of cases where ${cur} has
+ # some kind of special quoting.
+ # 3) On top of any quoting from 1 & 2, we have to provide an extra
+ # level of quoting for any paths that contain a '*', '?', '\',
+ # '[', ']', or leading '#' or '!' since those will be
+ # interpreted by sparse-checkout as something other than a
+ # literal path character.
+ # Since there are two types of quoting here, this might get really
+ # complex. For now, just punt on all of this...
+ completions="$(__git -C "${toplevel}" -c core.quotePath=false \
+ ls-files --cached -- "${pfx}${cur}*" \
+ | sed -e s%^%/% -e 's%$% %')"
+ # Note, above, though that we needed all of the completions to be
+ # prefixed with a '/', and we want to add a space so that bash
+ # completion will actually complete an entry and let us move on to
+ # the next one.
+
+ # Return what we've found.
+ if test -n "$completions"; then
+ # We found some completions; return them
+ local IFS=$'\n'
+ COMPREPLY=($completions)
+ else
+ # Do NOT fall back to bash-style all-local-files-and-dirs
+ # when we find no match. Such options are worse than
+ # useless:
+ # 1. "git sparse-checkout add" needs paths that are NOT
+ # currently in the working copy. "git
+ # sparse-checkout set" does as well, except in the
+ # special cases when users are only trying to narrow
+ # their sparse checkout to a subset of what they
+ # already have.
+ #
+ # 2. A path like '.config' is ambiguous as to whether
+ # the user wants all '.config' files throughout the
+ # tree, or just the one under the current directory.
+ # It would result in a warning from the
+ # sparse-checkout command due to this. As such, all
+ # completions of paths should be prefixed with a
+ # '/'.
+ #
+ # 3. We don't want paths prefixed with a '/' to
+ # complete files in the system root directory, we
+ # want it to complete on files relative to the
+ # repository root.
+ #
+ # As such, make sure that NO completions are offered rather
+ # than falling back to bash's default completions.
+ COMPREPLY=( "" )
+ fi
+}
+
+_git_sparse_checkout ()
+{
+ local subcommands="list init set disable add reapply"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ local using_cone=true
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ case "$subcommand,$cur" in
+ *,--*)
+ __gitcomp_builtin sparse-checkout_$subcommand "" "--"
+ ;;
+ set,*|add,*)
+ if [[ "$(__git config core.sparseCheckout)" == "true" &&
+ "$(__git config core.sparseCheckoutCone)" == "false" &&
+ -z "$(__git_find_on_cmdline --cone)" ]]; then
+ using_cone=false
+ fi
+ if [[ -n "$(__git_find_on_cmdline --no-cone)" ]]; then
+ using_cone=false
+ fi
+ if [[ "$using_cone" == "true" ]]; then
+ __gitcomp_directories
+ else
+ __gitcomp_slash_leading_paths
+ fi
+ esac
+}
+
_git_stash ()
{
- local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
local subcommands='push list show apply clear drop pop create branch'
local subcommand="$(__git_find_on_cmdline "$subcommands save")"
- if [ -n "$(__git_find_on_cmdline "-p")" ]; then
- subcommand="push"
- fi
+
if [ -z "$subcommand" ]; then
- case "$cur" in
- --*)
- __gitcomp "$save_opts"
+ case "$((cword - __git_cmd_idx)),$cur" in
+ *,--*)
+ __gitcomp_builtin stash_push
;;
- sa*)
- if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
- __gitcomp "save"
- fi
+ 1,sa*)
+ __gitcomp "save"
;;
- *)
- if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
- __gitcomp "$subcommands"
- fi
+ 1,*)
+ __gitcomp "$subcommands"
;;
esac
- else
- case "$subcommand,$cur" in
- push,--*)
- __gitcomp "$save_opts --message"
- ;;
- save,--*)
- __gitcomp "$save_opts"
- ;;
- apply,--*|pop,--*)
- __gitcomp "--index --quiet"
- ;;
- drop,--*)
- __gitcomp "--quiet"
- ;;
- list,--*)
- __gitcomp "--name-status --oneline --patch-with-stat"
- ;;
- show,--*|branch,--*)
- ;;
- branch,*)
- if [ $cword -eq 3 ]; then
- __git_complete_refs
- else
- __gitcomp_nl "$(__git stash list \
- | sed -n -e 's/:.*//p')"
- fi
- ;;
- show,*|apply,*|drop,*|pop,*)
+ return
+ fi
+
+ case "$subcommand,$cur" in
+ list,--*)
+ # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
+ __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
+ ;;
+ show,--*)
+ __gitcomp_builtin stash_show "$__git_diff_common_options"
+ ;;
+ *,--*)
+ __gitcomp_builtin "stash_$subcommand"
+ ;;
+ branch,*)
+ if [ $cword -eq $((__git_cmd_idx+2)) ]; then
+ __git_complete_refs
+ else
__gitcomp_nl "$(__git stash list \
| sed -n -e 's/:.*//p')"
- ;;
- *)
- ;;
- esac
- fi
+ fi
+ ;;
+ show,*|apply,*|drop,*|pop,*)
+ __gitcomp_nl "$(__git stash list \
+ | sed -n -e 's/:.*//p')"
+ ;;
+ esac
}
_git_submodule ()
{
__git_has_doubledash && return
- local subcommands="add status init deinit update set-branch summary foreach sync absorbgitdirs"
+ local subcommands="add status init deinit update set-branch set-url summary foreach sync absorbgitdirs"
local subcommand="$(__git_find_on_cmdline "$subcommands")"
if [ -z "$subcommand" ]; then
case "$cur" in
@@ -2843,6 +3501,7 @@ _git_svn ()
--log-window-size= --no-checkout --quiet
--repack-flags --use-log-author --localtime
--add-author-from
+ --recursive
--ignore-paths= --include-paths= $remote_opts
"
local init_opts="
@@ -2924,7 +3583,7 @@ _git_svn ()
_git_tag ()
{
- local i c=1 f=0
+ local i c="$__git_cmd_idx" f=0
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
@@ -2964,33 +3623,84 @@ _git_whatchanged ()
_git_log
}
+__git_complete_worktree_paths ()
+{
+ local IFS=$'\n'
+ # Generate completion reply from worktree list skipping the first
+ # entry: it's the path of the main worktree, which can't be moved,
+ # removed, locked, etc.
+ __gitcomp_nl "$(__git worktree list --porcelain |
+ sed -n -e '2,$ s/^worktree //p')"
+}
+
_git_worktree ()
{
local subcommands="add list lock move prune remove unlock"
- local subcommand="$(__git_find_on_cmdline "$subcommands")"
- if [ -z "$subcommand" ]; then
+ local subcommand subcommand_idx
+
+ subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
+ subcommand_idx="${subcommand% *}"
+ subcommand="${subcommand#* }"
+
+ case "$subcommand,$cur" in
+ ,*)
__gitcomp "$subcommands"
- else
- case "$subcommand,$cur" in
- add,--*)
- __gitcomp_builtin worktree_add
- ;;
- list,--*)
- __gitcomp_builtin worktree_list
- ;;
- lock,--*)
- __gitcomp_builtin worktree_lock
- ;;
- prune,--*)
- __gitcomp_builtin worktree_prune
- ;;
- remove,--*)
- __gitcomp "--force"
+ ;;
+ *,--*)
+ __gitcomp_builtin worktree_$subcommand
+ ;;
+ add,*) # usage: git worktree add [<options>] <path> [<commit-ish>]
+ # Here we are not completing an --option, it's either the
+ # path or a ref.
+ case "$prev" in
+ -b|-B) # Complete refs for branch to be created/reseted.
+ __git_complete_refs
;;
- *)
+ -*) # The previous word is an -o|--option without an
+ # unstuck argument: have to complete the path for
+ # the new worktree, so don't list anything, but let
+ # Bash fall back to filename completion.
+ ;;
+ *) # The previous word is not an --option, so it must
+ # be either the 'add' subcommand, the unstuck
+ # argument of an option (e.g. branch for -b|-B), or
+ # the path for the new worktree.
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
+ # Right after the 'add' subcommand: have to
+ # complete the path, so fall back to Bash
+ # filename completion.
+ :
+ else
+ case "${words[cword-2]}" in
+ -b|-B) # After '-b <branch>': have to
+ # complete the path, so fall back
+ # to Bash filename completion.
+ ;;
+ *) # After the path: have to complete
+ # the ref to be checked out.
+ __git_complete_refs
+ ;;
+ esac
+ fi
;;
esac
- fi
+ ;;
+ lock,*|remove,*|unlock,*)
+ __git_complete_worktree_paths
+ ;;
+ move,*)
+ if [ $cword -eq $((subcommand_idx+1)) ]; then
+ # The first parameter must be an existing working
+ # tree to be moved.
+ __git_complete_worktree_paths
+ else
+ # The second parameter is the destination: it could
+ # be any path, so don't list anything, but let Bash
+ # fall back to filename completion.
+ :
+ fi
+ ;;
+ esac
}
__git_complete_common () {
@@ -3018,15 +3728,19 @@ __git_support_parseopt_helper () {
esac
}
+__git_have_func () {
+ declare -f -- "$1" >/dev/null 2>&1
+}
+
__git_complete_command () {
local command="$1"
local completion_func="_git_${command//-/_}"
- if ! declare -f $completion_func >/dev/null 2>/dev/null &&
- declare -f _completion_loader >/dev/null 2>/dev/null
+ if ! __git_have_func $completion_func &&
+ __git_have_func _completion_loader
then
_completion_loader "git-$command"
fi
- if declare -f $completion_func >/dev/null 2>/dev/null
+ if __git_have_func $completion_func
then
$completion_func
return 0
@@ -3043,26 +3757,45 @@ __git_main ()
{
local i c=1 command __git_dir __git_repo_path
local __git_C_args C_args_count=0
+ local __git_cmd_idx
while [ $c -lt $cword ]; do
i="${words[c]}"
case "$i" in
- --git-dir=*) __git_dir="${i#--git-dir=}" ;;
- --git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
- --bare) __git_dir="." ;;
- --help) command="help"; break ;;
- -c|--work-tree|--namespace) ((c++)) ;;
- -C) __git_C_args[C_args_count++]=-C
+ --git-dir=*)
+ __git_dir="${i#--git-dir=}"
+ ;;
+ --git-dir)
+ ((c++))
+ __git_dir="${words[c]}"
+ ;;
+ --bare)
+ __git_dir="."
+ ;;
+ --help)
+ command="help"
+ break
+ ;;
+ -c|--work-tree|--namespace)
+ ((c++))
+ ;;
+ -C)
+ __git_C_args[C_args_count++]=-C
((c++))
__git_C_args[C_args_count++]="${words[c]}"
;;
- -*) ;;
- *) command="$i"; break ;;
+ -*)
+ ;;
+ *)
+ command="$i"
+ __git_cmd_idx="$c"
+ break
+ ;;
esac
((c++))
done
- if [ -z "$command" ]; then
+ if [ -z "${command-}" ]; then
case "$prev" in
--git-dir|-C|--work-tree)
# these need a path argument, let's fall back to
@@ -3079,7 +3812,8 @@ __git_main ()
;;
esac
case "$cur" in
- --*) __gitcomp "
+ --*)
+ __gitcomp "
--paginate
--no-pager
--git-dir=
@@ -3097,11 +3831,17 @@ __git_main ()
"
;;
*)
- if test -n "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
+ if test -n "${GIT_TESTING_PORCELAIN_COMMAND_LIST-}"
then
__gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
else
- __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)"
+ local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
+
+ if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
+ then
+ list_cmds=builtins,$list_cmds
+ fi
+ __gitcomp "$(__git --list-cmds=$list_cmds)"
fi
;;
esac
@@ -3125,7 +3865,7 @@ __gitk_main ()
__git_find_repo_path
local merge=""
- if [ -f "$__git_repo_path/MERGE_HEAD" ]; then
+ if __git_pseudoref_exists MERGE_HEAD; then
merge="--merge"
fi
case "$cur" in
@@ -3141,102 +3881,20 @@ __gitk_main ()
__git_complete_revlist
}
-if [[ -n ${ZSH_VERSION-} ]] &&
- # Don't define these functions when sourced from 'git-completion.zsh',
- # it has its own implementations.
- [[ -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
- echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
-
- autoload -U +X compinit && compinit
-
- __gitcomp ()
- {
- emulate -L zsh
-
- local cur_="${3-$cur}"
-
- case "$cur_" in
- --*=)
- ;;
- *)
- local c IFS=$' \t\n'
- local -a array
- for c in ${=1}; do
- c="$c${4-}"
- case $c in
- --*=*|*.) ;;
- *) c="$c " ;;
- esac
- array[${#array[@]}+1]="$c"
- done
- compset -P '*[=:]'
- compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
- ;;
- esac
- }
-
- __gitcomp_direct ()
- {
- emulate -L zsh
-
- local IFS=$'\n'
- compset -P '*[=:]'
- compadd -Q -- ${=1} && _ret=0
- }
-
- __gitcomp_nl ()
- {
- emulate -L zsh
-
- local IFS=$'\n'
- compset -P '*[=:]'
- compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
- }
-
- __gitcomp_file_direct ()
- {
- emulate -L zsh
-
- local IFS=$'\n'
- compset -P '*[=:]'
- compadd -f -- ${=1} && _ret=0
- }
-
- __gitcomp_file ()
- {
- emulate -L zsh
-
- local IFS=$'\n'
- compset -P '*[=:]'
- compadd -p "${2-}" -f -- ${=1} && _ret=0
- }
-
- _git ()
- {
- local _ret=1 cur cword prev
- cur=${words[CURRENT]}
- prev=${words[CURRENT-1]}
- let cword=CURRENT-1
- emulate ksh -c __${service}_main
- let _ret && _default && _ret=0
- return _ret
- }
-
- compdef _git git gitk
+if [[ -n ${ZSH_VERSION-} && -z ${GIT_SOURCING_ZSH_COMPLETION-} ]]; then
+ echo "ERROR: this script is obsolete, please see git-completion.zsh" 1>&2
return
fi
__git_func_wrap ()
{
local cur words cword prev
+ local __git_cmd_idx=0
_get_comp_words_by_ref -n =: cur words cword prev
$1
}
-# Setup completion for certain functions defined above by setting common
-# variables and workarounds.
-# This is NOT a public function; use at your own risk.
-__git_complete ()
+___git_complete ()
{
local wrapper="__git_wrap${2}"
eval "$wrapper () { __git_func_wrap $2 ; }"
@@ -3244,25 +3902,33 @@ __git_complete ()
|| complete -o default -o nospace -F $wrapper $1
}
-# wrapper for backwards compatibility
-_git ()
+# Setup the completion for git commands
+# 1: command or alias
+# 2: function to call (e.g. `git`, `gitk`, `git_fetch`)
+__git_complete ()
{
- __git_wrap__git_main
-}
+ local func
-# wrapper for backwards compatibility
-_gitk ()
-{
- __git_wrap__gitk_main
+ if __git_have_func $2; then
+ func=$2
+ elif __git_have_func __$2_main; then
+ func=__$2_main
+ elif __git_have_func _$2; then
+ func=_$2
+ else
+ echo "ERROR: could not find function '$2'" 1>&2
+ return 1
+ fi
+ ___git_complete $1 $func
}
-__git_complete git __git_main
-__git_complete gitk __gitk_main
+___git_complete git __git_main
+___git_complete gitk __gitk_main
# The following are necessary only for Cygwin, and only are needed
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
#
-if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
-__git_complete git.exe __git_main
+if [ "$OSTYPE" = cygwin ]; then
+ ___git_complete git.exe __git_main
fi
diff --git a/contrib/completion/git-completion.tcsh b/contrib/completion/git-completion.tcsh
index 4a790d8..ba797e5 100644
--- a/contrib/completion/git-completion.tcsh
+++ b/contrib/completion/git-completion.tcsh
@@ -80,8 +80,9 @@ else
COMP_CWORD=\$((\${#COMP_WORDS[@]}-1))
fi
-# Call _git() or _gitk() of the bash script, based on the first argument
-_\${1}
+# Call __git_wrap__git_main() or __git_wrap__gitk_main() of the bash script,
+# based on the first argument
+__git_wrap__\${1}_main
IFS=\$'\n'
if [ \${#COMPREPLY[*]} -eq 0 ]; then
diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh
index eef4eff..cac6f61 100644
--- a/contrib/completion/git-completion.zsh
+++ b/contrib/completion/git-completion.zsh
@@ -2,26 +2,24 @@
# zsh completion wrapper for git
#
-# Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
+# Copyright (c) 2012-2020 Felipe Contreras <felipe.contreras@gmail.com>
#
-# You need git's bash completion script installed somewhere, by default it
-# would be the location bash-completion uses.
+# The recommended way to install this script is to make a copy of it as a
+# file named '_git' inside any directory in your fpath.
#
-# If your script is somewhere else, you can configure it on your ~/.zshrc:
+# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
+# and then add the following to your ~/.zshrc file:
#
-# zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh
+# fpath=(~/.zsh $fpath)
#
-# The recommended way to install this script is to make a copy of it in
-# ~/.zsh/ directory as ~/.zsh/git-completion.zsh and then add the following
-# to your ~/.zshrc file:
+# You need git's bash completion script installed. By default bash-completion's
+# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).
+#
+# If your bash completion script is somewhere else, you can specify the
+# location in your ~/.zshrc:
+#
+# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
#
-# fpath=(~/.zsh $fpath)
-
-complete ()
-{
- # do nothing
- return 0
-}
zstyle -T ':completion:*:*:git:*' tag-order && \
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
@@ -29,18 +27,26 @@ zstyle -T ':completion:*:*:git:*' tag-order && \
zstyle -s ":completion:*:*:git:*" script script
if [ -z "$script" ]; then
local -a locations
- local e
+ local e bash_completion
+
+ bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) ||
+ bash_completion='/usr/share/bash-completion/completions/'
+
locations=(
- $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
- '/etc/bash_completion.d/git' # fedora, old debian
- '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
- '/usr/share/bash-completion/git' # gentoo
+ "$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
+ "$HOME/.local/share/bash-completion/completions/git"
+ "$bash_completion/git"
+ '/etc/bash_completion.d/git' # old debian
)
for e in $locations; do
test -f $e && script="$e" && break
done
fi
+
+local old_complete="$functions[complete]"
+functions[complete]=:
GIT_SOURCING_ZSH_COMPLETION=y . "$script"
+functions[complete]="$old_complete"
__gitcomp ()
{
@@ -51,13 +57,35 @@ __gitcomp ()
case "$cur_" in
--*=)
;;
+ --no-*)
+ local c IFS=$' \t\n'
+ local -a array
+ for c in ${=1}; do
+ if [[ $c == "--" ]]; then
+ continue
+ fi
+ c="$c${4-}"
+ case $c in
+ --*=|*.) ;;
+ *) c="$c " ;;
+ esac
+ array+=("$c")
+ done
+ compset -P '*[=:]'
+ compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
+ ;;
*)
local c IFS=$' \t\n'
local -a array
for c in ${=1}; do
+ if [[ $c == "--" ]]; then
+ c="--no-...${4-}"
+ array+=("$c ")
+ break
+ fi
c="$c${4-}"
case $c in
- --*=*|*.) ;;
+ --*=|*.) ;;
*) c="$c " ;;
esac
array+=("$c")
@@ -72,44 +100,58 @@ __gitcomp_direct ()
{
emulate -L zsh
- local IFS=$'\n'
compset -P '*[=:]'
- compadd -Q -- ${=1} && _ret=0
+ compadd -Q -S '' -- ${(f)1} && _ret=0
}
__gitcomp_nl ()
{
emulate -L zsh
- local IFS=$'\n'
compset -P '*[=:]'
- compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+ compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0
}
-__gitcomp_nl_append ()
+__gitcomp_file ()
{
emulate -L zsh
- local IFS=$'\n'
- compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+ compset -P '*[=:]'
+ compadd -f -p "${2-}" -- ${(f)1} && _ret=0
+}
+
+__gitcomp_direct_append ()
+{
+ __gitcomp_direct "$@"
+}
+
+__gitcomp_nl_append ()
+{
+ __gitcomp_nl "$@"
}
__gitcomp_file_direct ()
{
- emulate -L zsh
+ __gitcomp_file "$1" ""
+}
- local IFS=$'\n'
- compset -P '*[=:]'
- compadd -f -- ${=1} && _ret=0
+_git_zsh ()
+{
+ __gitcomp "v1.1"
}
-__gitcomp_file ()
+__git_complete_command ()
{
emulate -L zsh
- local IFS=$'\n'
- compset -P '*[=:]'
- compadd -p "${2-}" -f -- ${=1} && _ret=0
+ local command="$1"
+ local completion_func="_git_${command//-/_}"
+ if (( $+functions[$completion_func] )); then
+ emulate ksh -c $completion_func
+ return 0
+ else
+ return 1
+ fi
}
__git_zsh_bash_func ()
@@ -118,14 +160,12 @@ __git_zsh_bash_func ()
local command=$1
- local completion_func="_git_${command//-/_}"
- declare -f $completion_func >/dev/null && $completion_func && return
+ __git_complete_command "$command" && return
local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then
words[1]=$expansion
- completion_func="_git_${expansion//-/_}"
- declare -f $completion_func >/dev/null && $completion_func
+ __git_complete_command "$expansion"
fi
}
@@ -150,9 +190,11 @@ __git_zsh_cmd_common ()
push:'update remote refs along with associated objects'
rebase:'forward-port local commits to the updated upstream head'
reset:'reset current HEAD to the specified state'
+ restore:'restore working tree files'
rm:'remove files from the working tree and from the index'
show:'show various types of objects'
status:'show the working tree status'
+ switch:'switch branches'
tag:'create, list, delete or verify a tag object signed with GPG')
_describe -t common-commands 'common commands' list && _ret=0
}
@@ -160,8 +202,9 @@ __git_zsh_cmd_common ()
__git_zsh_cmd_alias ()
{
local -a list
- list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*})
- _describe -t alias-commands 'aliases' list $* && _ret=0
+ list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.})
+ list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"})
+ _describe -t alias-commands 'aliases' list && _ret=0
}
__git_zsh_cmd_all ()
@@ -199,13 +242,16 @@ __git_zsh_main ()
case $state in
(command)
- _alternative \
- 'alias-commands:alias:__git_zsh_cmd_alias' \
- 'common-commands:common:__git_zsh_cmd_common' \
- 'all-commands:all:__git_zsh_cmd_all' && _ret=0
+ _tags common-commands alias-commands all-commands
+ while _tags; do
+ _requested common-commands && __git_zsh_cmd_common
+ _requested alias-commands && __git_zsh_cmd_alias
+ _requested all-commands && __git_zsh_cmd_all
+ let _ret || break
+ done
;;
(arg)
- local command="${words[1]}" __git_dir
+ local command="${words[1]}" __git_dir __git_cmd_idx=1
if (( $+opt_args[--bare] )); then
__git_dir='.'
@@ -233,8 +279,12 @@ _git ()
if (( $+functions[__${service}_zsh_main] )); then
__${service}_zsh_main
- else
+ elif (( $+functions[__${service}_main] )); then
emulate ksh -c __${service}_main
+ elif (( $+functions[_${service}] )); then
+ emulate ksh -c _${service}
+ elif (( $+functions[_${service//-/_}] )); then
+ emulate ksh -c _${service//-/_}
fi
let _ret && _default && _ret=0
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 1d510cd..5330e76 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -66,15 +66,28 @@
# git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream
#
-# You can change the separator between the branch name and the above
-# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
-# is SP.
-#
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
# find one, or @{upstream} otherwise. Once you have set
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
# setting the bash.showUpstream config variable.
#
+# You can change the separator between the branch name and the above
+# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
+# is SP.
+#
+# When there is an in-progress operation such as a merge, rebase,
+# revert, cherry-pick, or bisect, the prompt will include information
+# related to the operation, often in the form "|<OPERATION-NAME>".
+#
+# When the repository has a sparse-checkout, a notification of the form
+# "|SPARSE" will be included in the prompt. This can be shortened to a
+# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
+# by setting GIT_PS1_OMITSPARSESTATE.
+#
+# If you would like to see a notification on the prompt when there are
+# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to "yes". The
+# prompt will include "|CONFLICT".
+#
# If you would like to see more information about the identity of
# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
# to one of these values:
@@ -87,8 +100,7 @@
#
# If you would like a colored hint about the current dirty state, set
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
-# the colored output of "git status -sb" and are available only when
-# using __git_ps1 for PROMPT_COMMAND or precmd.
+# the colored output of "git status -sb".
#
# If you would like __git_ps1 to do nothing in the case when the current
# directory is set up to be ignored by git, then set
@@ -105,7 +117,7 @@ __git_ps1_show_upstream ()
{
local key value
local svn_remote svn_url_pattern count n
- local upstream=git legacy="" verbose="" name=""
+ local upstream_type=git legacy="" verbose="" name=""
svn_remote=()
# get some config options from git-config
@@ -122,24 +134,25 @@ __git_ps1_show_upstream ()
svn-remote.*.url)
svn_remote[$((${#svn_remote[@]} + 1))]="$value"
svn_url_pattern="$svn_url_pattern\\|$value"
- upstream=svn+git # default upstream is SVN if available, else git
+ upstream_type=svn+git # default upstream type is SVN if available, else git
;;
esac
done <<< "$output"
# parse configuration values
- for option in ${GIT_PS1_SHOWUPSTREAM}; do
+ local option
+ for option in ${GIT_PS1_SHOWUPSTREAM-}; do
case "$option" in
- git|svn) upstream="$option" ;;
+ git|svn) upstream_type="$option" ;;
verbose) verbose=1 ;;
legacy) legacy=1 ;;
name) name=1 ;;
esac
done
- # Find our upstream
- case "$upstream" in
- git) upstream="@{upstream}" ;;
+ # Find our upstream type
+ case "$upstream_type" in
+ git) upstream_type="@{upstream}" ;;
svn*)
# get the upstream from the "git-svn-id: ..." in a commit message
# (git-svn uses essentially the same procedure internally)
@@ -156,12 +169,12 @@ __git_ps1_show_upstream ()
if [[ -z "$svn_upstream" ]]; then
# default branch name for checkouts with no layout:
- upstream=${GIT_SVN_ID:-git-svn}
+ upstream_type=${GIT_SVN_ID:-git-svn}
else
- upstream=${svn_upstream#/}
+ upstream_type=${svn_upstream#/}
fi
- elif [[ "svn+git" = "$upstream" ]]; then
- upstream="@{upstream}"
+ elif [[ "svn+git" = "$upstream_type" ]]; then
+ upstream_type="@{upstream}"
fi
;;
esac
@@ -169,11 +182,11 @@ __git_ps1_show_upstream ()
# Find how many commits we are ahead/behind our upstream
if [[ -z "$legacy" ]]; then
count="$(git rev-list --count --left-right \
- "$upstream"...HEAD 2>/dev/null)"
+ "$upstream_type"...HEAD 2>/dev/null)"
else
# produce equivalent output to --count for older versions of git
local commits
- if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
+ if commits="$(git rev-list --left-right "$upstream_type"...HEAD 2>/dev/null)"
then
local commit behind=0 ahead=0
for commit in $commits
@@ -203,26 +216,26 @@ __git_ps1_show_upstream ()
*) # diverged from upstream
p="<>" ;;
esac
- else
+ else # verbose, set upstream instead of p
case "$count" in
"") # no upstream
- p="" ;;
+ upstream="" ;;
"0 0") # equal to upstream
- p=" u=" ;;
+ upstream="|u=" ;;
"0 "*) # ahead of upstream
- p=" u+${count#0 }" ;;
+ upstream="|u+${count#0 }" ;;
*" 0") # behind upstream
- p=" u-${count% 0}" ;;
+ upstream="|u-${count% 0}" ;;
*) # diverged from upstream
- p=" u+${count#* }-${count% *}" ;;
+ upstream="|u+${count#* }-${count% *}" ;;
esac
if [[ -n "$count" && -n "$name" ]]; then
__git_ps1_upstream_name=$(git rev-parse \
- --abbrev-ref "$upstream" 2>/dev/null)
+ --abbrev-ref "$upstream_type" 2>/dev/null)
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
- p="$p \${__git_ps1_upstream_name}"
+ upstream="$upstream \${__git_ps1_upstream_name}"
else
- p="$p ${__git_ps1_upstream_name}"
+ upstream="$upstream ${__git_ps1_upstream_name}"
# not needed anymore; keep user's
# environment clean
unset __git_ps1_upstream_name
@@ -234,7 +247,8 @@ __git_ps1_show_upstream ()
# Helper function that is meant to be called from __git_ps1. It
# injects color codes into the appropriate gitstring variables used
-# to build a gitstring.
+# to build a gitstring. Colored variables are responsible for clearing
+# their own color.
__git_ps1_colorize_gitstring ()
{
if [[ -n ${ZSH_VERSION-} ]]; then
@@ -243,12 +257,12 @@ __git_ps1_colorize_gitstring ()
local c_lblue='%F{blue}'
local c_clear='%f'
else
- # Using \[ and \] around colors is necessary to prevent
+ # Using \001 and \002 around colors is necessary to prevent
# issues with command line editing/browsing/completion!
- local c_red='\[\e[31m\]'
- local c_green='\[\e[32m\]'
- local c_lblue='\[\e[1;34m\]'
- local c_clear='\[\e[0m\]'
+ local c_red=$'\001\e[31m\002'
+ local c_green=$'\001\e[32m\002'
+ local c_lblue=$'\001\e[1;34m\002'
+ local c_clear=$'\001\e[0m\002'
fi
local bad_color=$c_red
local ok_color=$c_green
@@ -260,22 +274,23 @@ __git_ps1_colorize_gitstring ()
else
branch_color="$bad_color"
fi
- c="$branch_color$c"
+ if [ -n "$c" ]; then
+ c="$branch_color$c$c_clear"
+ fi
+ b="$branch_color$b$c_clear"
- z="$c_clear$z"
- if [ "$w" = "*" ]; then
- w="$bad_color$w"
+ if [ -n "$w" ]; then
+ w="$bad_color$w$c_clear"
fi
if [ -n "$i" ]; then
- i="$ok_color$i"
+ i="$ok_color$i$c_clear"
fi
if [ -n "$s" ]; then
- s="$flags_color$s"
+ s="$flags_color$s$c_clear"
fi
if [ -n "$u" ]; then
- u="$bad_color$u"
+ u="$bad_color$u$c_clear"
fi
- r="$c_clear$r"
}
# Helper function to read the first line of a file into a variable.
@@ -283,7 +298,7 @@ __git_ps1_colorize_gitstring ()
# variable, in that order.
__git_eread ()
{
- test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
+ test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1"
}
# see if a cherry-pick or revert is in progress, if the user has committed a
@@ -393,7 +408,7 @@ __git_ps1 ()
local repo_info rev_parse_exit_code
repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
- --is-bare-repository --is-inside-work-tree \
+ --is-bare-repository --is-inside-work-tree --show-ref-format \
--short HEAD 2>/dev/null)"
rev_parse_exit_code="$?"
@@ -406,6 +421,8 @@ __git_ps1 ()
short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
fi
+ local ref_format="${repo_info##*$'\n'}"
+ repo_info="${repo_info%$'\n'*}"
local inside_worktree="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local bare_repo="${repo_info##*$'\n'}"
@@ -421,6 +438,13 @@ __git_ps1 ()
return $exit
fi
+ local sparse=""
+ if [ -z "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
+ [ -z "${GIT_PS1_OMITSPARSESTATE-}" ] &&
+ [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
+ sparse="|SPARSE"
+ fi
+
local r=""
local b=""
local step=""
@@ -429,11 +453,7 @@ __git_ps1 ()
__git_eread "$g/rebase-merge/head-name" b
__git_eread "$g/rebase-merge/msgnum" step
__git_eread "$g/rebase-merge/end" total
- if [ -f "$g/rebase-merge/interactive" ]; then
- r="|REBASE-i"
- else
- r="|REBASE-m"
- fi
+ r="|REBASE"
else
if [ -d "$g/rebase-apply" ]; then
__git_eread "$g/rebase-apply/next" step
@@ -461,12 +481,25 @@ __git_ps1 ()
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
local head=""
- if ! __git_eread "$g/HEAD" head; then
- return $exit
- fi
- # is it a symbolic ref?
- b="${head#ref: }"
- if [ "$head" = "$b" ]; then
+
+ case "$ref_format" in
+ files)
+ if ! __git_eread "$g/HEAD" head; then
+ return $exit
+ fi
+
+ if [[ $head == "ref: "* ]]; then
+ head="${head#ref: }"
+ else
+ head=""
+ fi
+ ;;
+ *)
+ head="$(git symbolic-ref HEAD 2>/dev/null)"
+ ;;
+ esac
+
+ if test -z "$head"; then
detached=yes
b="$(
case "${GIT_PS1_DESCRIBE_STYLE-}" in
@@ -484,6 +517,8 @@ __git_ps1 ()
b="$short_sha..."
b="($b)"
+ else
+ b="$head"
fi
fi
fi
@@ -492,12 +527,20 @@ __git_ps1 ()
r="$r $step/$total"
fi
+ local conflict="" # state indicator for unresolved conflicts
+ if [[ "${GIT_PS1_SHOWCONFLICTSTATE-}" == "yes" ]] &&
+ [[ $(git ls-files --unmerged 2>/dev/null) ]]; then
+ conflict="|CONFLICT"
+ fi
+
local w=""
local i=""
local s=""
local u=""
+ local h=""
local c=""
- local p=""
+ local p="" # short version of upstream state indicator
+ local upstream="" # verbose version of upstream state indicator
if [ "true" = "$inside_gitdir" ]; then
if [ "true" = "$bare_repo" ]; then
@@ -528,6 +571,11 @@ __git_ps1 ()
u="%${ZSH_VERSION+%}"
fi
+ if [ -n "${GIT_PS1_COMPRESSSPARSESTATE-}" ] &&
+ [ "$(git config --bool core.sparseCheckout)" = "true" ]; then
+ h="?"
+ fi
+
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
__git_ps1_show_upstream
fi
@@ -535,19 +583,18 @@ __git_ps1 ()
local z="${GIT_PS1_STATESEPARATOR-" "}"
- # NO color option unless in PROMPT_COMMAND mode
- if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
- __git_ps1_colorize_gitstring
- fi
-
b=${b##refs/heads/}
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
__git_ps1_branch_name=$b
b="\${__git_ps1_branch_name}"
fi
- local f="$w$i$s$u"
- local gitstring="$c$b${f:+$z$f}$r$p"
+ if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
+ __git_ps1_colorize_gitstring
+ fi
+
+ local f="$h$w$i$s$u$p"
+ local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}"
if [ $pcmode = yes ]; then
if [ "${__git_printf_supports_v-}" != yes ]; then
diff --git a/contrib/coverage-diff.sh b/contrib/coverage-diff.sh
index 4ec419f..6ce9603 100755
--- a/contrib/coverage-diff.sh
+++ b/contrib/coverage-diff.sh
@@ -74,8 +74,7 @@ do
sort >uncovered_lines.txt
comm -12 uncovered_lines.txt new_lines.txt |
- sed -e 's/$/\)/' |
- sed -e 's/^/ /' >uncovered_new_lines.txt
+ sed -e 's/$/\)/' -e 's/^/ /' >uncovered_new_lines.txt
grep -q '[^[:space:]]' <uncovered_new_lines.txt &&
echo $file >>coverage-data.txt &&
@@ -91,11 +90,7 @@ cat coverage-data.txt
echo "Commits introducing uncovered code:"
-commit_list=$(cat coverage-data.txt |
- grep -E '^[0-9a-f]{7,} ' |
- awk '{print $1;}' |
- sort |
- uniq)
+commit_list=$(awk '/^[0-9a-f]{7,}/ { print $1 }' coverage-data.txt | sort -u)
(
for commit in $commit_list
diff --git a/contrib/credential/gnome-keyring/.gitignore b/contrib/credential/gnome-keyring/.gitignore
deleted file mode 100644
index 88d8fcd..0000000
--- a/contrib/credential/gnome-keyring/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-git-credential-gnome-keyring
diff --git a/contrib/credential/gnome-keyring/Makefile b/contrib/credential/gnome-keyring/Makefile
deleted file mode 100644
index 22c19df..0000000
--- a/contrib/credential/gnome-keyring/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-MAIN:=git-credential-gnome-keyring
-all:: $(MAIN)
-
-CC = gcc
-RM = rm -f
-CFLAGS = -g -O2 -Wall
-PKG_CONFIG = pkg-config
-
--include ../../../config.mak.autogen
--include ../../../config.mak
-
-INCS:=$(shell $(PKG_CONFIG) --cflags gnome-keyring-1 glib-2.0)
-LIBS:=$(shell $(PKG_CONFIG) --libs gnome-keyring-1 glib-2.0)
-
-SRCS:=$(MAIN).c
-OBJS:=$(SRCS:.c=.o)
-
-%.o: %.c
- $(CC) $(CFLAGS) $(CPPFLAGS) $(INCS) -o $@ -c $<
-
-$(MAIN): $(OBJS)
- $(CC) -o $@ $(LDFLAGS) $^ $(LIBS)
-
-clean:
- @$(RM) $(MAIN) $(OBJS)
diff --git a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c b/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
deleted file mode 100644
index d389bfa..0000000
--- a/contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * Copyright (C) 2011 John Szakmeister <john@szakmeister.net>
- * 2012 Philipp A. Hartmann <pah@qo.cx>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Credits:
- * - GNOME Keyring API handling originally written by John Szakmeister
- * - ported to credential helper API by Philipp A. Hartmann
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <glib.h>
-#include <gnome-keyring.h>
-
-#ifdef GNOME_KEYRING_DEFAULT
-
- /* Modern gnome-keyring */
-
-#include <gnome-keyring-memory.h>
-
-#else
-
- /*
- * Support ancient gnome-keyring, circ. RHEL 5.X.
- * GNOME_KEYRING_DEFAULT seems to have been introduced with Gnome 2.22,
- * and the other features roughly around Gnome 2.20, 6 months before.
- * Ubuntu 8.04 used Gnome 2.22 (I think). Not sure any distro used 2.20.
- * So the existence/non-existence of GNOME_KEYRING_DEFAULT seems like
- * a decent thing to use as an indicator.
- */
-
-#define GNOME_KEYRING_DEFAULT NULL
-
-/*
- * ancient gnome-keyring returns DENIED when an entry is not found.
- * Setting NO_MATCH to DENIED will prevent us from reporting DENIED
- * errors during get and erase operations, but we will still report
- * DENIED errors during a store.
- */
-#define GNOME_KEYRING_RESULT_NO_MATCH GNOME_KEYRING_RESULT_DENIED
-
-#define gnome_keyring_memory_alloc g_malloc
-#define gnome_keyring_memory_free gnome_keyring_free_password
-#define gnome_keyring_memory_strdup g_strdup
-
-static const char *gnome_keyring_result_to_message(GnomeKeyringResult result)
-{
- switch (result) {
- case GNOME_KEYRING_RESULT_OK:
- return "OK";
- case GNOME_KEYRING_RESULT_DENIED:
- return "Denied";
- case GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON:
- return "No Keyring Daemon";
- case GNOME_KEYRING_RESULT_ALREADY_UNLOCKED:
- return "Already UnLocked";
- case GNOME_KEYRING_RESULT_NO_SUCH_KEYRING:
- return "No Such Keyring";
- case GNOME_KEYRING_RESULT_BAD_ARGUMENTS:
- return "Bad Arguments";
- case GNOME_KEYRING_RESULT_IO_ERROR:
- return "IO Error";
- case GNOME_KEYRING_RESULT_CANCELLED:
- return "Cancelled";
- case GNOME_KEYRING_RESULT_ALREADY_EXISTS:
- return "Already Exists";
- default:
- return "Unknown Error";
- }
-}
-
-/*
- * Support really ancient gnome-keyring, circ. RHEL 4.X.
- * Just a guess for the Glib version. Glib 2.8 was roughly Gnome 2.12 ?
- * Which was released with gnome-keyring 0.4.3 ??
- */
-#if GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 8
-
-static void gnome_keyring_done_cb(GnomeKeyringResult result, gpointer user_data)
-{
- gpointer *data = (gpointer *)user_data;
- int *done = (int *)data[0];
- GnomeKeyringResult *r = (GnomeKeyringResult *)data[1];
-
- *r = result;
- *done = 1;
-}
-
-static void wait_for_request_completion(int *done)
-{
- GMainContext *mc = g_main_context_default();
- while (!*done)
- g_main_context_iteration(mc, TRUE);
-}
-
-static GnomeKeyringResult gnome_keyring_item_delete_sync(const char *keyring, guint32 id)
-{
- int done = 0;
- GnomeKeyringResult result;
- gpointer data[] = { &done, &result };
-
- gnome_keyring_item_delete(keyring, id, gnome_keyring_done_cb, data,
- NULL);
-
- wait_for_request_completion(&done);
-
- return result;
-}
-
-#endif
-#endif
-
-/*
- * This credential struct and API is simplified from git's credential.{h,c}
- */
-struct credential {
- char *protocol;
- char *host;
- unsigned short port;
- char *path;
- char *username;
- char *password;
-};
-
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
-
-typedef int (*credential_op_cb)(struct credential *);
-
-struct credential_operation {
- char *name;
- credential_op_cb op;
-};
-
-#define CREDENTIAL_OP_END { NULL, NULL }
-
-/* ----------------- GNOME Keyring functions ----------------- */
-
-/* create a special keyring option string, if path is given */
-static char *keyring_object(struct credential *c)
-{
- if (!c->path)
- return NULL;
-
- if (c->port)
- return g_strdup_printf("%s:%hd/%s", c->host, c->port, c->path);
-
- return g_strdup_printf("%s/%s", c->host, c->path);
-}
-
-static int keyring_get(struct credential *c)
-{
- char *object = NULL;
- GList *entries;
- GnomeKeyringNetworkPasswordData *password_data;
- GnomeKeyringResult result;
-
- if (!c->protocol || !(c->host || c->path))
- return EXIT_FAILURE;
-
- object = keyring_object(c);
-
- result = gnome_keyring_find_network_password_sync(
- c->username,
- NULL /* domain */,
- c->host,
- object,
- c->protocol,
- NULL /* authtype */,
- c->port,
- &entries);
-
- g_free(object);
-
- if (result == GNOME_KEYRING_RESULT_NO_MATCH)
- return EXIT_SUCCESS;
-
- if (result == GNOME_KEYRING_RESULT_CANCELLED)
- return EXIT_SUCCESS;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- /* pick the first one from the list */
- password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
-
- gnome_keyring_memory_free(c->password);
- c->password = gnome_keyring_memory_strdup(password_data->password);
-
- if (!c->username)
- c->username = g_strdup(password_data->user);
-
- gnome_keyring_network_password_list_free(entries);
-
- return EXIT_SUCCESS;
-}
-
-
-static int keyring_store(struct credential *c)
-{
- guint32 item_id;
- char *object = NULL;
- GnomeKeyringResult result;
-
- /*
- * Sanity check that what we are storing is actually sensible.
- * In particular, we can't make a URL without a protocol field.
- * Without either a host or pathname (depending on the scheme),
- * we have no primary key. And without a username and password,
- * we are not actually storing a credential.
- */
- if (!c->protocol || !(c->host || c->path) ||
- !c->username || !c->password)
- return EXIT_FAILURE;
-
- object = keyring_object(c);
-
- result = gnome_keyring_set_network_password_sync(
- GNOME_KEYRING_DEFAULT,
- c->username,
- NULL /* domain */,
- c->host,
- object,
- c->protocol,
- NULL /* authtype */,
- c->port,
- c->password,
- &item_id);
-
- g_free(object);
-
- if (result != GNOME_KEYRING_RESULT_OK &&
- result != GNOME_KEYRING_RESULT_CANCELLED) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}
-
-static int keyring_erase(struct credential *c)
-{
- char *object = NULL;
- GList *entries;
- GnomeKeyringNetworkPasswordData *password_data;
- GnomeKeyringResult result;
-
- /*
- * Sanity check that we actually have something to match
- * against. The input we get is a restrictive pattern,
- * so technically a blank credential means "erase everything".
- * But it is too easy to accidentally send this, since it is equivalent
- * to empty input. So explicitly disallow it, and require that the
- * pattern have some actual content to match.
- */
- if (!c->protocol && !c->host && !c->path && !c->username)
- return EXIT_FAILURE;
-
- object = keyring_object(c);
-
- result = gnome_keyring_find_network_password_sync(
- c->username,
- NULL /* domain */,
- c->host,
- object,
- c->protocol,
- NULL /* authtype */,
- c->port,
- &entries);
-
- g_free(object);
-
- if (result == GNOME_KEYRING_RESULT_NO_MATCH)
- return EXIT_SUCCESS;
-
- if (result == GNOME_KEYRING_RESULT_CANCELLED)
- return EXIT_SUCCESS;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- /* pick the first one from the list (delete all matches?) */
- password_data = (GnomeKeyringNetworkPasswordData *)entries->data;
-
- result = gnome_keyring_item_delete_sync(
- password_data->keyring, password_data->item_id);
-
- gnome_keyring_network_password_list_free(entries);
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- g_critical("%s", gnome_keyring_result_to_message(result));
- return EXIT_FAILURE;
- }
-
- return EXIT_SUCCESS;
-}
-
-/*
- * Table with helper operation callbacks, used by generic
- * credential helper main function.
- */
-static struct credential_operation const credential_helper_ops[] = {
- { "get", keyring_get },
- { "store", keyring_store },
- { "erase", keyring_erase },
- CREDENTIAL_OP_END
-};
-
-/* ------------------ credential functions ------------------ */
-
-static void credential_init(struct credential *c)
-{
- memset(c, 0, sizeof(*c));
-}
-
-static void credential_clear(struct credential *c)
-{
- g_free(c->protocol);
- g_free(c->host);
- g_free(c->path);
- g_free(c->username);
- gnome_keyring_memory_free(c->password);
-
- credential_init(c);
-}
-
-static int credential_read(struct credential *c)
-{
- char *buf;
- size_t line_len;
- char *key;
- char *value;
-
- key = buf = gnome_keyring_memory_alloc(1024);
-
- while (fgets(buf, 1024, stdin)) {
- line_len = strlen(buf);
-
- if (line_len && buf[line_len-1] == '\n')
- buf[--line_len] = '\0';
-
- if (!line_len)
- break;
-
- value = strchr(buf, '=');
- if (!value) {
- g_warning("invalid credential line: %s", key);
- gnome_keyring_memory_free(buf);
- return -1;
- }
- *value++ = '\0';
-
- if (!strcmp(key, "protocol")) {
- g_free(c->protocol);
- c->protocol = g_strdup(value);
- } else if (!strcmp(key, "host")) {
- g_free(c->host);
- c->host = g_strdup(value);
- value = strrchr(c->host, ':');
- if (value) {
- *value++ = '\0';
- c->port = atoi(value);
- }
- } else if (!strcmp(key, "path")) {
- g_free(c->path);
- c->path = g_strdup(value);
- } else if (!strcmp(key, "username")) {
- g_free(c->username);
- c->username = g_strdup(value);
- } else if (!strcmp(key, "password")) {
- gnome_keyring_memory_free(c->password);
- c->password = gnome_keyring_memory_strdup(value);
- while (*value)
- *value++ = '\0';
- }
- /*
- * Ignore other lines; we don't know what they mean, but
- * this future-proofs us when later versions of git do
- * learn new lines, and the helpers are updated to match.
- */
- }
-
- gnome_keyring_memory_free(buf);
-
- return 0;
-}
-
-static void credential_write_item(FILE *fp, const char *key, const char *value)
-{
- if (!value)
- return;
- fprintf(fp, "%s=%s\n", key, value);
-}
-
-static void credential_write(const struct credential *c)
-{
- /* only write username/password, if set */
- credential_write_item(stdout, "username", c->username);
- credential_write_item(stdout, "password", c->password);
-}
-
-static void usage(const char *name)
-{
- struct credential_operation const *try_op = credential_helper_ops;
- const char *basename = strrchr(name, '/');
-
- basename = (basename) ? basename + 1 : name;
- fprintf(stderr, "usage: %s <", basename);
- while (try_op->name) {
- fprintf(stderr, "%s", (try_op++)->name);
- if (try_op->name)
- fprintf(stderr, "%s", "|");
- }
- fprintf(stderr, "%s", ">\n");
-}
-
-int main(int argc, char *argv[])
-{
- int ret = EXIT_SUCCESS;
-
- struct credential_operation const *try_op = credential_helper_ops;
- struct credential cred = CREDENTIAL_INIT;
-
- if (!argv[1]) {
- usage(argv[0]);
- exit(EXIT_FAILURE);
- }
-
- g_set_application_name("Git Credential Helper");
-
- /* lookup operation callback */
- while (try_op->name && strcmp(argv[1], try_op->name))
- try_op++;
-
- /* unsupported operation given -- ignore silently */
- if (!try_op->name || !try_op->op)
- goto out;
-
- ret = credential_read(&cred);
- if (ret)
- goto out;
-
- /* perform credential operation */
- ret = (*try_op->op)(&cred);
-
- credential_write(&cred);
-
-out:
- credential_clear(&cred);
- return ret;
-}
diff --git a/contrib/credential/libsecret/.gitignore b/contrib/credential/libsecret/.gitignore
new file mode 100644
index 0000000..4fa2235
--- /dev/null
+++ b/contrib/credential/libsecret/.gitignore
@@ -0,0 +1 @@
+git-credential-libsecret
diff --git a/contrib/credential/libsecret/git-credential-libsecret.c b/contrib/credential/libsecret/git-credential-libsecret.c
index e6598b6..90034d0 100644
--- a/contrib/credential/libsecret/git-credential-libsecret.c
+++ b/contrib/credential/libsecret/git-credential-libsecret.c
@@ -39,9 +39,11 @@ struct credential {
char *path;
char *username;
char *password;
+ char *password_expiry_utc;
+ char *oauth_refresh_token;
};
-#define CREDENTIAL_INIT { NULL, NULL, 0, NULL, NULL, NULL }
+#define CREDENTIAL_INIT { 0 }
typedef int (*credential_op_cb)(struct credential *);
@@ -52,8 +54,29 @@ struct credential_operation {
#define CREDENTIAL_OP_END { NULL, NULL }
+static void credential_clear(struct credential *c);
+
/* ----------------- Secret Service functions ----------------- */
+static const SecretSchema schema = {
+ "org.git.Password",
+ /* Ignore schema name during search for backwards compatibility */
+ SECRET_SCHEMA_DONT_MATCH_NAME,
+ {
+ /*
+ * libsecret assumes attribute values are non-confidential and
+ * unchanging, so we can't include oauth_refresh_token or
+ * password_expiry_utc.
+ */
+ { "user", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { "object", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { "protocol", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { "port", SECRET_SCHEMA_ATTRIBUTE_INTEGER },
+ { "server", SECRET_SCHEMA_ATTRIBUTE_STRING },
+ { NULL, 0 },
+ }
+};
+
static char *make_label(struct credential *c)
{
if (c->port)
@@ -101,7 +124,7 @@ static int keyring_get(struct credential *c)
attributes = make_attr_list(c);
items = secret_service_search_sync(service,
- SECRET_SCHEMA_COMPAT_NETWORK,
+ &schema,
attributes,
SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK,
NULL,
@@ -117,6 +140,7 @@ static int keyring_get(struct credential *c)
SecretItem *item;
SecretValue *secret;
const char *s;
+ gchar **parts;
item = items->data;
secret = secret_item_get_secret(item);
@@ -130,8 +154,30 @@ static int keyring_get(struct credential *c)
s = secret_value_get_text(secret);
if (s) {
- g_free(c->password);
- c->password = g_strdup(s);
+ /*
+ * Passwords and other attributes encoded in following format:
+ * hunter2
+ * password_expiry_utc=1684189401
+ * oauth_refresh_token=xyzzy
+ */
+ parts = g_strsplit(s, "\n", 0);
+ if (g_strv_length(parts) >= 1) {
+ g_free(c->password);
+ c->password = g_strdup(parts[0]);
+ } else {
+ g_free(c->password);
+ c->password = g_strdup("");
+ }
+ for (int i = 1; i < g_strv_length(parts); i++) {
+ if (g_str_has_prefix(parts[i], "password_expiry_utc=")) {
+ g_free(c->password_expiry_utc);
+ c->password_expiry_utc = g_strdup(&parts[i][20]);
+ } else if (g_str_has_prefix(parts[i], "oauth_refresh_token=")) {
+ g_free(c->oauth_refresh_token);
+ c->oauth_refresh_token = g_strdup(&parts[i][20]);
+ }
+ }
+ g_strfreev(parts);
}
g_hash_table_unref(attributes);
@@ -148,6 +194,7 @@ static int keyring_store(struct credential *c)
char *label = NULL;
GHashTable *attributes = NULL;
GError *error = NULL;
+ GString *secret = NULL;
/*
* Sanity check that what we are storing is actually sensible.
@@ -162,13 +209,23 @@ static int keyring_store(struct credential *c)
label = make_label(c);
attributes = make_attr_list(c);
- secret_password_storev_sync(SECRET_SCHEMA_COMPAT_NETWORK,
+ secret = g_string_new(c->password);
+ if (c->password_expiry_utc) {
+ g_string_append_printf(secret, "\npassword_expiry_utc=%s",
+ c->password_expiry_utc);
+ }
+ if (c->oauth_refresh_token) {
+ g_string_append_printf(secret, "\noauth_refresh_token=%s",
+ c->oauth_refresh_token);
+ }
+ secret_password_storev_sync(&schema,
attributes,
NULL,
label,
- c->password,
+ secret->str,
NULL,
&error);
+ g_string_free(secret, TRUE);
g_free(label);
g_hash_table_unref(attributes);
@@ -185,6 +242,7 @@ static int keyring_erase(struct credential *c)
{
GHashTable *attributes = NULL;
GError *error = NULL;
+ struct credential existing = CREDENTIAL_INIT;
/*
* Sanity check that we actually have something to match
@@ -197,8 +255,22 @@ static int keyring_erase(struct credential *c)
if (!c->protocol && !c->host && !c->path && !c->username)
return EXIT_FAILURE;
+ if (c->password) {
+ existing.host = g_strdup(c->host);
+ existing.path = g_strdup(c->path);
+ existing.port = c->port;
+ existing.protocol = g_strdup(c->protocol);
+ existing.username = g_strdup(c->username);
+ keyring_get(&existing);
+ if (existing.password && strcmp(c->password, existing.password)) {
+ credential_clear(&existing);
+ return EXIT_SUCCESS;
+ }
+ credential_clear(&existing);
+ }
+
attributes = make_attr_list(c);
- secret_password_clearv_sync(SECRET_SCHEMA_COMPAT_NETWORK,
+ secret_password_clearv_sync(&schema,
attributes,
NULL,
&error);
@@ -238,23 +310,24 @@ static void credential_clear(struct credential *c)
g_free(c->path);
g_free(c->username);
g_free(c->password);
+ g_free(c->password_expiry_utc);
+ g_free(c->oauth_refresh_token);
credential_init(c);
}
static int credential_read(struct credential *c)
{
- char *buf;
- size_t line_len;
+ char *buf = NULL;
+ size_t alloc;
+ ssize_t line_len;
char *key;
char *value;
- key = buf = g_malloc(1024);
-
- while (fgets(buf, 1024, stdin)) {
- line_len = strlen(buf);
+ while ((line_len = getline(&buf, &alloc, stdin)) > 0) {
+ key = buf;
- if (line_len && buf[line_len-1] == '\n')
+ if (buf[line_len-1] == '\n')
buf[--line_len] = '\0';
if (!line_len)
@@ -285,11 +358,19 @@ static int credential_read(struct credential *c)
} else if (!strcmp(key, "username")) {
g_free(c->username);
c->username = g_strdup(value);
+ } else if (!strcmp(key, "password_expiry_utc")) {
+ g_free(c->password_expiry_utc);
+ c->password_expiry_utc = g_strdup(value);
} else if (!strcmp(key, "password")) {
g_free(c->password);
c->password = g_strdup(value);
while (*value)
*value++ = '\0';
+ } else if (!strcmp(key, "oauth_refresh_token")) {
+ g_free(c->oauth_refresh_token);
+ c->oauth_refresh_token = g_strdup(value);
+ while (*value)
+ *value++ = '\0';
}
/*
* Ignore other lines; we don't know what they mean, but
@@ -298,7 +379,7 @@ static int credential_read(struct credential *c)
*/
}
- g_free(buf);
+ free(buf);
return 0;
}
@@ -315,6 +396,10 @@ static void credential_write(const struct credential *c)
/* only write username/password, if set */
credential_write_item(stdout, "username", c->username);
credential_write_item(stdout, "password", c->password);
+ credential_write_item(stdout, "password_expiry_utc",
+ c->password_expiry_utc);
+ credential_write_item(stdout, "oauth_refresh_token",
+ c->oauth_refresh_token);
}
static void usage(const char *name)
diff --git a/contrib/credential/netrc/.gitignore b/contrib/credential/netrc/.gitignore
new file mode 100644
index 0000000..d41cdde
--- /dev/null
+++ b/contrib/credential/netrc/.gitignore
@@ -0,0 +1 @@
+git-credential-netrc
diff --git a/contrib/credential/netrc/Makefile b/contrib/credential/netrc/Makefile
index 6174e3b..c284fb8 100644
--- a/contrib/credential/netrc/Makefile
+++ b/contrib/credential/netrc/Makefile
@@ -1,8 +1,30 @@
# The default target of this Makefile is...
all::
-test:
+SCRIPT_PERL = git-credential-netrc.perl
+GIT_ROOT_DIR = ../../..
+HERE = contrib/credential/netrc
+
+SCRIPT_PERL_FULL = $(patsubst %,$(HERE)/%,$(SCRIPT_PERL))
+
+all:: build
+
+build:
+ $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
+ build-perl-script
+
+install: build
+ $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
+ install-perl-script
+
+clean:
+ $(MAKE) -C $(GIT_ROOT_DIR) SCRIPT_PERL="$(SCRIPT_PERL_FULL)" \
+ clean-perl-script
+
+test: build
./t-git-credential-netrc.sh
-testverbose:
+testverbose: build
./t-git-credential-netrc.sh -d -v
+
+.PHONY: all build install clean test testverbose
diff --git a/contrib/credential/netrc/git-credential-netrc b/contrib/credential/netrc/git-credential-netrc.perl
index ebfc123..9fb998a 100755
--- a/contrib/credential/netrc/git-credential-netrc
+++ b/contrib/credential/netrc/git-credential-netrc.perl
@@ -356,7 +356,10 @@ sub read_credential_data_from_stdin {
next unless m/^([^=]+)=(.+)/;
my ($token, $value) = ($1, $2);
- die "Unknown search token $token" unless exists $q{$token};
+
+ # skip any unknown tokens
+ next unless exists $q{$token};
+
$q{$token} = $value;
log_debug("We were given search token $token and value $value");
}
@@ -423,7 +426,7 @@ sub load_config {
# load settings from git config
my $options = shift;
# set from command argument, gpg.program option, or default to gpg
- $options->{'gpg'} //= Git->repository()->config('gpg.program')
+ $options->{'gpg'} //= Git::config('gpg.program')
// 'gpg';
log_verbose("using $options{'gpg'} for GPG operations");
}
diff --git a/contrib/credential/netrc/t-git-credential-netrc.sh b/contrib/credential/netrc/t-git-credential-netrc.sh
index 07227d0..bf27773 100755
--- a/contrib/credential/netrc/t-git-credential-netrc.sh
+++ b/contrib/credential/netrc/t-git-credential-netrc.sh
@@ -3,16 +3,9 @@
cd ../../../t
test_description='git-credential-netrc'
. ./test-lib.sh
+ . "$TEST_DIRECTORY"/lib-perl.sh
- if ! test_have_prereq PERL; then
- skip_all='skipping perl interface tests, perl not available'
- test_done
- fi
-
- perl -MTest::More -e 0 2>/dev/null || {
- skip_all="Perl Test::More unavailable, skipping test"
- test_done
- }
+ skip_all_if_no_Test_More
# set up test repository
@@ -20,13 +13,10 @@
'set up test repository' \
'git config --add gpg.program test.git-config-gpg'
- # The external test will outputs its own plan
- test_external_has_tap=1
-
export PERL5LIB="$GITPERLLIB"
- test_external \
- 'git-credential-netrc' \
+ test_expect_success 'git-credential-netrc' '
perl "$GIT_BUILD_DIR"/contrib/credential/netrc/test.pl
+ '
test_done
)
diff --git a/contrib/credential/osxkeychain/Makefile b/contrib/credential/osxkeychain/Makefile
index 4b3a08a..238f5f8 100644
--- a/contrib/credential/osxkeychain/Makefile
+++ b/contrib/credential/osxkeychain/Makefile
@@ -8,7 +8,8 @@ CFLAGS = -g -O2 -Wall
-include ../../../config.mak
git-credential-osxkeychain: git-credential-osxkeychain.o
- $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -Wl,-framework -Wl,Security
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) \
+ -framework Security -framework CoreFoundation
git-credential-osxkeychain.o: git-credential-osxkeychain.c
$(CC) -c $(CFLAGS) $<
diff --git a/contrib/credential/osxkeychain/git-credential-osxkeychain.c b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
index bcd3f57..6a40917 100644
--- a/contrib/credential/osxkeychain/git-credential-osxkeychain.c
+++ b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
@@ -3,13 +3,51 @@
#include <stdlib.h>
#include <Security/Security.h>
-static SecProtocolType protocol;
-static char *host;
-static char *path;
-static char *username;
-static char *password;
-static UInt16 port;
+#define ENCODING kCFStringEncodingUTF8
+static CFStringRef protocol; /* Stores constant strings - not memory managed */
+static CFStringRef host;
+static CFNumberRef port;
+static CFStringRef path;
+static CFStringRef username;
+static CFDataRef password;
+static CFDataRef password_expiry_utc;
+static CFDataRef oauth_refresh_token;
+static void clear_credential(void)
+{
+ if (host) {
+ CFRelease(host);
+ host = NULL;
+ }
+ if (port) {
+ CFRelease(port);
+ port = NULL;
+ }
+ if (path) {
+ CFRelease(path);
+ path = NULL;
+ }
+ if (username) {
+ CFRelease(username);
+ username = NULL;
+ }
+ if (password) {
+ CFRelease(password);
+ password = NULL;
+ }
+ if (password_expiry_utc) {
+ CFRelease(password_expiry_utc);
+ password_expiry_utc = NULL;
+ }
+ if (oauth_refresh_token) {
+ CFRelease(oauth_refresh_token);
+ oauth_refresh_token = NULL;
+ }
+}
+
+#define STRING_WITH_LENGTH(s) s, sizeof(s) - 1
+
+__attribute__((format (printf, 1, 2), __noreturn__))
static void die(const char *err, ...)
{
char msg[4096];
@@ -18,70 +56,199 @@ static void die(const char *err, ...)
vsnprintf(msg, sizeof(msg), err, params);
fprintf(stderr, "%s\n", msg);
va_end(params);
+ clear_credential();
exit(1);
}
-static void *xstrdup(const char *s1)
+static void *xmalloc(size_t len)
{
- void *ret = strdup(s1);
+ void *ret = malloc(len);
if (!ret)
die("Out of memory");
return ret;
}
-#define KEYCHAIN_ITEM(x) (x ? strlen(x) : 0), x
-#define KEYCHAIN_ARGS \
- NULL, /* default keychain */ \
- KEYCHAIN_ITEM(host), \
- 0, NULL, /* account domain */ \
- KEYCHAIN_ITEM(username), \
- KEYCHAIN_ITEM(path), \
- port, \
- protocol, \
- kSecAuthenticationTypeDefault
-
-static void write_item(const char *what, const char *buf, int len)
+static CFDictionaryRef create_dictionary(CFAllocatorRef allocator, ...)
+{
+ va_list args;
+ const void *key;
+ CFMutableDictionaryRef result;
+
+ result = CFDictionaryCreateMutable(allocator,
+ 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+
+ va_start(args, allocator);
+ while ((key = va_arg(args, const void *)) != NULL) {
+ const void *value;
+ value = va_arg(args, const void *);
+ if (value)
+ CFDictionarySetValue(result, key, value);
+ }
+ va_end(args);
+
+ return result;
+}
+
+#define CREATE_SEC_ATTRIBUTES(...) \
+ create_dictionary(kCFAllocatorDefault, \
+ kSecClass, kSecClassInternetPassword, \
+ kSecAttrServer, host, \
+ kSecAttrAccount, username, \
+ kSecAttrPath, path, \
+ kSecAttrPort, port, \
+ kSecAttrProtocol, protocol, \
+ kSecAttrAuthenticationType, \
+ kSecAttrAuthenticationTypeDefault, \
+ __VA_ARGS__);
+
+static void write_item(const char *what, const char *buf, size_t len)
{
printf("%s=", what);
fwrite(buf, 1, len, stdout);
putchar('\n');
}
-static void find_username_in_item(SecKeychainItemRef item)
+static void find_username_in_item(CFDictionaryRef item)
{
- SecKeychainAttributeList list;
- SecKeychainAttribute attr;
+ CFStringRef account_ref;
+ char *username_buf;
+ CFIndex buffer_len;
- list.count = 1;
- list.attr = &attr;
- attr.tag = kSecAccountItemAttr;
+ account_ref = CFDictionaryGetValue(item, kSecAttrAccount);
+ if (!account_ref)
+ {
+ write_item("username", "", 0);
+ return;
+ }
- if (SecKeychainItemCopyContent(item, NULL, &list, NULL, NULL))
+ username_buf = (char *)CFStringGetCStringPtr(account_ref, ENCODING);
+ if (username_buf)
+ {
+ write_item("username", username_buf, strlen(username_buf));
return;
+ }
- write_item("username", attr.data, attr.length);
- SecKeychainItemFreeContent(&list, NULL);
+ /* If we can't get a CString pointer then
+ * we need to allocate our own buffer */
+ buffer_len = CFStringGetMaximumSizeForEncoding(
+ CFStringGetLength(account_ref), ENCODING) + 1;
+ username_buf = xmalloc(buffer_len);
+ if (CFStringGetCString(account_ref,
+ username_buf,
+ buffer_len,
+ ENCODING)) {
+ write_item("username", username_buf, buffer_len - 1);
+ }
+ free(username_buf);
}
-static void find_internet_password(void)
+static OSStatus find_internet_password(void)
{
- void *buf;
- UInt32 len;
- SecKeychainItemRef item;
+ CFDictionaryRef attrs;
+ CFDictionaryRef item;
+ CFDataRef data;
+ OSStatus result;
- if (SecKeychainFindInternetPassword(KEYCHAIN_ARGS, &len, &buf, &item))
- return;
+ attrs = CREATE_SEC_ATTRIBUTES(kSecMatchLimit, kSecMatchLimitOne,
+ kSecReturnAttributes, kCFBooleanTrue,
+ kSecReturnData, kCFBooleanTrue,
+ NULL);
+ result = SecItemCopyMatching(attrs, (CFTypeRef *)&item);
+ if (result) {
+ goto out;
+ }
- write_item("password", buf, len);
+ data = CFDictionaryGetValue(item, kSecValueData);
+
+ write_item("password",
+ (const char *)CFDataGetBytePtr(data),
+ CFDataGetLength(data));
if (!username)
find_username_in_item(item);
- SecKeychainItemFreeContent(NULL, buf);
+ CFRelease(item);
+
+out:
+ CFRelease(attrs);
+
+ /* We consider not found to not be an error */
+ if (result == errSecItemNotFound)
+ result = errSecSuccess;
+
+ return result;
+}
+
+static OSStatus delete_ref(const void *itemRef)
+{
+ CFArrayRef item_ref_list;
+ CFDictionaryRef delete_query;
+ OSStatus result;
+
+ item_ref_list = CFArrayCreate(kCFAllocatorDefault,
+ &itemRef,
+ 1,
+ &kCFTypeArrayCallBacks);
+ delete_query = create_dictionary(kCFAllocatorDefault,
+ kSecClass, kSecClassInternetPassword,
+ kSecMatchItemList, item_ref_list,
+ NULL);
+
+ if (password) {
+ /* We only want to delete items with a matching password */
+ CFIndex capacity;
+ CFMutableDictionaryRef query;
+ CFDataRef data;
+
+ capacity = CFDictionaryGetCount(delete_query) + 1;
+ query = CFDictionaryCreateMutableCopy(kCFAllocatorDefault,
+ capacity,
+ delete_query);
+ CFDictionarySetValue(query, kSecReturnData, kCFBooleanTrue);
+ result = SecItemCopyMatching(query, (CFTypeRef *)&data);
+ if (!result) {
+ CFDataRef kc_password;
+ const UInt8 *raw_data;
+ const UInt8 *line;
+
+ /* Don't match appended metadata */
+ raw_data = CFDataGetBytePtr(data);
+ line = memchr(raw_data, '\n', CFDataGetLength(data));
+ if (line)
+ kc_password = CFDataCreateWithBytesNoCopy(
+ kCFAllocatorDefault,
+ raw_data,
+ line - raw_data,
+ kCFAllocatorNull);
+ else
+ kc_password = data;
+
+ if (CFEqual(kc_password, password))
+ result = SecItemDelete(delete_query);
+
+ if (line)
+ CFRelease(kc_password);
+ CFRelease(data);
+ }
+
+ CFRelease(query);
+ } else {
+ result = SecItemDelete(delete_query);
+ }
+
+ CFRelease(delete_query);
+ CFRelease(item_ref_list);
+
+ return result;
}
-static void delete_internet_password(void)
+static OSStatus delete_internet_password(void)
{
- SecKeychainItemRef item;
+ CFDictionaryRef attrs;
+ CFArrayRef refs;
+ OSStatus result;
/*
* Require at least a protocol and host for removal, which is what git
@@ -89,37 +256,83 @@ static void delete_internet_password(void)
* Keychain manager.
*/
if (!protocol || !host)
- return;
+ return -1;
- if (SecKeychainFindInternetPassword(KEYCHAIN_ARGS, 0, NULL, &item))
- return;
+ attrs = CREATE_SEC_ATTRIBUTES(kSecMatchLimit, kSecMatchLimitAll,
+ kSecReturnRef, kCFBooleanTrue,
+ NULL);
+ result = SecItemCopyMatching(attrs, (CFTypeRef *)&refs);
+ CFRelease(attrs);
+
+ if (!result) {
+ for (CFIndex i = 0; !result && i < CFArrayGetCount(refs); i++)
+ result = delete_ref(CFArrayGetValueAtIndex(refs, i));
+
+ CFRelease(refs);
+ }
+
+ /* We consider not found to not be an error */
+ if (result == errSecItemNotFound)
+ result = errSecSuccess;
- SecKeychainItemDelete(item);
+ return result;
}
-static void add_internet_password(void)
+static OSStatus add_internet_password(void)
{
+ CFMutableDataRef data;
+ CFDictionaryRef attrs;
+ OSStatus result;
+
/* Only store complete credentials */
if (!protocol || !host || !username || !password)
- return;
+ return -1;
- if (SecKeychainAddInternetPassword(
- KEYCHAIN_ARGS,
- KEYCHAIN_ITEM(password),
- NULL))
- return;
+ data = CFDataCreateMutableCopy(kCFAllocatorDefault, 0, password);
+ if (password_expiry_utc) {
+ CFDataAppendBytes(data,
+ (const UInt8 *)STRING_WITH_LENGTH("\npassword_expiry_utc="));
+ CFDataAppendBytes(data,
+ CFDataGetBytePtr(password_expiry_utc),
+ CFDataGetLength(password_expiry_utc));
+ }
+ if (oauth_refresh_token) {
+ CFDataAppendBytes(data,
+ (const UInt8 *)STRING_WITH_LENGTH("\noauth_refresh_token="));
+ CFDataAppendBytes(data,
+ CFDataGetBytePtr(oauth_refresh_token),
+ CFDataGetLength(oauth_refresh_token));
+ }
+
+ attrs = CREATE_SEC_ATTRIBUTES(kSecValueData, data,
+ NULL);
+
+ result = SecItemAdd(attrs, NULL);
+ if (result == errSecDuplicateItem) {
+ CFDictionaryRef query;
+ query = CREATE_SEC_ATTRIBUTES(NULL);
+ result = SecItemUpdate(query, attrs);
+ CFRelease(query);
+ }
+
+ CFRelease(data);
+ CFRelease(attrs);
+
+ return result;
}
static void read_credential(void)
{
- char buf[1024];
+ char *buf = NULL;
+ size_t alloc;
+ ssize_t line_len;
- while (fgets(buf, sizeof(buf), stdin)) {
+ while ((line_len = getline(&buf, &alloc, stdin)) > 0) {
char *v;
if (!strcmp(buf, "\n"))
break;
- buf[strlen(buf)-1] = '\0';
+ buf[line_len-1] = '\0';
v = strchr(buf, '=');
if (!v)
@@ -128,56 +341,93 @@ static void read_credential(void)
if (!strcmp(buf, "protocol")) {
if (!strcmp(v, "imap"))
- protocol = kSecProtocolTypeIMAP;
+ protocol = kSecAttrProtocolIMAP;
else if (!strcmp(v, "imaps"))
- protocol = kSecProtocolTypeIMAPS;
+ protocol = kSecAttrProtocolIMAPS;
else if (!strcmp(v, "ftp"))
- protocol = kSecProtocolTypeFTP;
+ protocol = kSecAttrProtocolFTP;
else if (!strcmp(v, "ftps"))
- protocol = kSecProtocolTypeFTPS;
+ protocol = kSecAttrProtocolFTPS;
else if (!strcmp(v, "https"))
- protocol = kSecProtocolTypeHTTPS;
+ protocol = kSecAttrProtocolHTTPS;
else if (!strcmp(v, "http"))
- protocol = kSecProtocolTypeHTTP;
+ protocol = kSecAttrProtocolHTTP;
else if (!strcmp(v, "smtp"))
- protocol = kSecProtocolTypeSMTP;
- else /* we don't yet handle other protocols */
+ protocol = kSecAttrProtocolSMTP;
+ else {
+ /* we don't yet handle other protocols */
+ clear_credential();
exit(0);
+ }
}
else if (!strcmp(buf, "host")) {
char *colon = strchr(v, ':');
if (colon) {
+ UInt16 port_i;
*colon++ = '\0';
- port = atoi(colon);
+ port_i = atoi(colon);
+ port = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberShortType,
+ &port_i);
}
- host = xstrdup(v);
+ host = CFStringCreateWithCString(kCFAllocatorDefault,
+ v,
+ ENCODING);
}
else if (!strcmp(buf, "path"))
- path = xstrdup(v);
+ path = CFStringCreateWithCString(kCFAllocatorDefault,
+ v,
+ ENCODING);
else if (!strcmp(buf, "username"))
- username = xstrdup(v);
+ username = CFStringCreateWithCString(
+ kCFAllocatorDefault,
+ v,
+ ENCODING);
else if (!strcmp(buf, "password"))
- password = xstrdup(v);
+ password = CFDataCreate(kCFAllocatorDefault,
+ (UInt8 *)v,
+ strlen(v));
+ else if (!strcmp(buf, "password_expiry_utc"))
+ password_expiry_utc = CFDataCreate(kCFAllocatorDefault,
+ (UInt8 *)v,
+ strlen(v));
+ else if (!strcmp(buf, "oauth_refresh_token"))
+ oauth_refresh_token = CFDataCreate(kCFAllocatorDefault,
+ (UInt8 *)v,
+ strlen(v));
+ /*
+ * Ignore other lines; we don't know what they mean, but
+ * this future-proofs us when later versions of git do
+ * learn new lines, and the helpers are updated to match.
+ */
}
+
+ free(buf);
}
int main(int argc, const char **argv)
{
+ OSStatus result = 0;
const char *usage =
"usage: git credential-osxkeychain <get|store|erase>";
if (!argv[1])
- die(usage);
+ die("%s", usage);
read_credential();
if (!strcmp(argv[1], "get"))
- find_internet_password();
+ result = find_internet_password();
else if (!strcmp(argv[1], "store"))
- add_internet_password();
+ result = add_internet_password();
else if (!strcmp(argv[1], "erase"))
- delete_internet_password();
+ result = delete_internet_password();
/* otherwise, ignore unknown action */
+ if (result)
+ die("failed to %s: %d", argv[1], (int)result);
+
+ clear_credential();
+
return 0;
}
diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c
index 5bdad41..4be0d58 100644
--- a/contrib/credential/wincred/git-credential-wincred.c
+++ b/contrib/credential/wincred/git-credential-wincred.c
@@ -6,11 +6,13 @@
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
+#include <wincred.h>
/* common helpers */
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+__attribute__((format (printf, 1, 2)))
static void die(const char *err, ...)
{
char msg[4096];
@@ -32,65 +34,8 @@ static void *xmalloc(size_t size)
return ret;
}
-/* MinGW doesn't have wincred.h, so we need to define stuff */
-
-typedef struct _CREDENTIAL_ATTRIBUTEW {
- LPWSTR Keyword;
- DWORD Flags;
- DWORD ValueSize;
- LPBYTE Value;
-} CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;
-
-typedef struct _CREDENTIALW {
- DWORD Flags;
- DWORD Type;
- LPWSTR TargetName;
- LPWSTR Comment;
- FILETIME LastWritten;
- DWORD CredentialBlobSize;
- LPBYTE CredentialBlob;
- DWORD Persist;
- DWORD AttributeCount;
- PCREDENTIAL_ATTRIBUTEW Attributes;
- LPWSTR TargetAlias;
- LPWSTR UserName;
-} CREDENTIALW, *PCREDENTIALW;
-
-#define CRED_TYPE_GENERIC 1
-#define CRED_PERSIST_LOCAL_MACHINE 2
-#define CRED_MAX_ATTRIBUTES 64
-
-typedef BOOL (WINAPI *CredWriteWT)(PCREDENTIALW, DWORD);
-typedef BOOL (WINAPI *CredEnumerateWT)(LPCWSTR, DWORD, DWORD *,
- PCREDENTIALW **);
-typedef VOID (WINAPI *CredFreeT)(PVOID);
-typedef BOOL (WINAPI *CredDeleteWT)(LPCWSTR, DWORD, DWORD);
-
-static HMODULE advapi;
-static CredWriteWT CredWriteW;
-static CredEnumerateWT CredEnumerateW;
-static CredFreeT CredFree;
-static CredDeleteWT CredDeleteW;
-
-static void load_cred_funcs(void)
-{
- /* load DLLs */
- advapi = LoadLibraryExA("advapi32.dll", NULL,
- LOAD_LIBRARY_SEARCH_SYSTEM32);
- if (!advapi)
- die("failed to load advapi32.dll");
-
- /* get function pointers */
- CredWriteW = (CredWriteWT)GetProcAddress(advapi, "CredWriteW");
- CredEnumerateW = (CredEnumerateWT)GetProcAddress(advapi,
- "CredEnumerateW");
- CredFree = (CredFreeT)GetProcAddress(advapi, "CredFree");
- CredDeleteW = (CredDeleteWT)GetProcAddress(advapi, "CredDeleteW");
- if (!CredWriteW || !CredEnumerateW || !CredFree || !CredDeleteW)
- die("failed to load functions");
-}
-
-static WCHAR *wusername, *password, *protocol, *host, *path, target[1024];
+static WCHAR *wusername, *password, *protocol, *host, *path, target[1024],
+ *password_expiry_utc, *oauth_refresh_token;
static void write_item(const char *what, LPCWSTR wbuf, int wlen)
{
@@ -164,7 +109,18 @@ static int match_part_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
return match_part_with_last(ptarget, want, delim, 1);
}
-static int match_cred(const CREDENTIALW *cred)
+static int match_cred_password(const CREDENTIALW *cred) {
+ int ret;
+ WCHAR *cred_password = xmalloc(cred->CredentialBlobSize);
+ wcsncpy_s(cred_password, cred->CredentialBlobSize,
+ (LPCWSTR)cred->CredentialBlob,
+ cred->CredentialBlobSize / sizeof(WCHAR));
+ ret = !wcscmp(cred_password, password);
+ free(cred_password);
+ return ret;
+}
+
+static int match_cred(const CREDENTIALW *cred, int match_password)
{
LPCWSTR target = cred->TargetName;
if (wusername && wcscmp(wusername, cred->UserName ? cred->UserName : L""))
@@ -174,7 +130,8 @@ static int match_cred(const CREDENTIALW *cred)
match_part(&target, protocol, L"://") &&
match_part_last(&target, wusername, L"@") &&
match_part(&target, host, L"/") &&
- match_part(&target, path, L"");
+ match_part(&target, path, L"") &&
+ (!match_password || match_cred_password(cred));
}
static void get_credential(void)
@@ -182,18 +139,47 @@ static void get_credential(void)
CREDENTIALW **creds;
DWORD num_creds;
int i;
+ CREDENTIAL_ATTRIBUTEW *attr;
+ WCHAR *secret;
+ WCHAR *line;
+ WCHAR *remaining_lines;
+ WCHAR *part;
+ WCHAR *remaining_parts;
if (!CredEnumerateW(L"git:*", 0, &num_creds, &creds))
return;
/* search for the first credential that matches username */
for (i = 0; i < num_creds; ++i)
- if (match_cred(creds[i])) {
+ if (match_cred(creds[i], 0)) {
write_item("username", creds[i]->UserName,
creds[i]->UserName ? wcslen(creds[i]->UserName) : 0);
- write_item("password",
- (LPCWSTR)creds[i]->CredentialBlob,
- creds[i]->CredentialBlobSize / sizeof(WCHAR));
+ if (creds[i]->CredentialBlobSize > 0) {
+ secret = xmalloc(creds[i]->CredentialBlobSize);
+ wcsncpy_s(secret, creds[i]->CredentialBlobSize, (LPCWSTR)creds[i]->CredentialBlob, creds[i]->CredentialBlobSize / sizeof(WCHAR));
+ line = wcstok_s(secret, L"\r\n", &remaining_lines);
+ write_item("password", line, line ? wcslen(line) : 0);
+ while(line != NULL) {
+ part = wcstok_s(line, L"=", &remaining_parts);
+ if (!wcscmp(part, L"oauth_refresh_token")) {
+ write_item("oauth_refresh_token", remaining_parts, remaining_parts ? wcslen(remaining_parts) : 0);
+ }
+ line = wcstok_s(NULL, L"\r\n", &remaining_lines);
+ }
+ free(secret);
+ } else {
+ write_item("password",
+ (LPCWSTR)creds[i]->CredentialBlob,
+ creds[i]->CredentialBlobSize / sizeof(WCHAR));
+ }
+ for (int j = 0; j < creds[i]->AttributeCount; j++) {
+ attr = creds[i]->Attributes + j;
+ if (!wcscmp(attr->Keyword, L"git_password_expiry_utc")) {
+ write_item("password_expiry_utc", (LPCWSTR)attr->Value,
+ attr->ValueSize / sizeof(WCHAR));
+ break;
+ }
+ }
break;
}
@@ -203,22 +189,43 @@ static void get_credential(void)
static void store_credential(void)
{
CREDENTIALW cred;
+ CREDENTIAL_ATTRIBUTEW expiry_attr;
+ WCHAR *secret;
+ int wlen;
if (!wusername || !password)
return;
+ if (oauth_refresh_token) {
+ wlen = _scwprintf(L"%s\r\noauth_refresh_token=%s", password, oauth_refresh_token);
+ secret = xmalloc(sizeof(WCHAR) * wlen);
+ _snwprintf_s(secret, sizeof(WCHAR) * wlen, wlen, L"%s\r\noauth_refresh_token=%s", password, oauth_refresh_token);
+ } else {
+ secret = _wcsdup(password);
+ }
+
cred.Flags = 0;
cred.Type = CRED_TYPE_GENERIC;
cred.TargetName = target;
cred.Comment = L"saved by git-credential-wincred";
- cred.CredentialBlobSize = (wcslen(password)) * sizeof(WCHAR);
- cred.CredentialBlob = (LPVOID)password;
+ cred.CredentialBlobSize = wcslen(secret) * sizeof(WCHAR);
+ cred.CredentialBlob = (LPVOID)_wcsdup(secret);
cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
cred.AttributeCount = 0;
cred.Attributes = NULL;
+ if (password_expiry_utc != NULL) {
+ expiry_attr.Keyword = L"git_password_expiry_utc";
+ expiry_attr.Value = (LPVOID)password_expiry_utc;
+ expiry_attr.ValueSize = (wcslen(password_expiry_utc)) * sizeof(WCHAR);
+ expiry_attr.Flags = 0;
+ cred.Attributes = &expiry_attr;
+ cred.AttributeCount = 1;
+ }
cred.TargetAlias = NULL;
cred.UserName = wusername;
+ free(secret);
+
if (!CredWriteW(&cred, 0))
die("CredWrite failed");
}
@@ -233,7 +240,7 @@ static void erase_credential(void)
return;
for (i = 0; i < num_creds; ++i) {
- if (match_cred(creds[i]))
+ if (match_cred(creds[i], password != NULL))
CredDeleteW(creds[i]->TargetName, creds[i]->Type, 0);
}
@@ -248,17 +255,28 @@ static WCHAR *utf8_to_utf16_dup(const char *str)
return wstr;
}
+#define KB (1024)
+
static void read_credential(void)
{
- char buf[1024];
+ size_t alloc = 100 * KB;
+ char *buf = calloc(alloc, sizeof(*buf));
- while (fgets(buf, sizeof(buf), stdin)) {
+ while (fgets(buf, alloc, stdin)) {
char *v;
- int len = strlen(buf);
+ size_t len = strlen(buf);
+ int ends_in_newline = 0;
/* strip trailing CR / LF */
- while (len && strchr("\r\n", buf[len - 1]))
+ if (len && buf[len - 1] == '\n') {
+ buf[--len] = 0;
+ ends_in_newline = 1;
+ }
+ if (len && buf[len - 1] == '\r')
buf[--len] = 0;
+ if (!ends_in_newline)
+ die("bad input: %s", buf);
+
if (!*buf)
break;
@@ -277,9 +295,18 @@ static void read_credential(void)
wusername = utf8_to_utf16_dup(v);
} else if (!strcmp(buf, "password"))
password = utf8_to_utf16_dup(v);
- else
- die("unrecognized input");
+ else if (!strcmp(buf, "password_expiry_utc"))
+ password_expiry_utc = utf8_to_utf16_dup(v);
+ else if (!strcmp(buf, "oauth_refresh_token"))
+ oauth_refresh_token = utf8_to_utf16_dup(v);
+ /*
+ * Ignore other lines; we don't know what they mean, but
+ * this future-proofs us when later versions of git do
+ * learn new lines, and the helpers are updated to match.
+ */
}
+
+ free(buf);
}
int main(int argc, char *argv[])
@@ -288,7 +315,7 @@ int main(int argc, char *argv[])
"usage: git credential-wincred <get|store|erase>\n";
if (!argv[1])
- die(usage);
+ die("%s", usage);
/* git use binary pipes to avoid CRLF-issues */
_setmode(_fileno(stdin), _O_BINARY);
@@ -296,8 +323,6 @@ int main(int argc, char *argv[])
read_credential();
- load_cred_funcs();
-
if (!protocol || !(host || path))
return 0;
diff --git a/contrib/diff-highlight/DiffHighlight.pm b/contrib/diff-highlight/DiffHighlight.pm
index e258992..636add6 100644
--- a/contrib/diff-highlight/DiffHighlight.pm
+++ b/contrib/diff-highlight/DiffHighlight.pm
@@ -1,6 +1,6 @@
package DiffHighlight;
-use 5.008;
+use 5.008001;
use warnings FATAL => 'all';
use strict;
@@ -112,7 +112,7 @@ sub handle_line {
# Since we can receive arbitrary input, there's no optimal
# place to flush. Flushing on a blank line is a heuristic that
# happens to match git-log output.
- if (!length) {
+ if (/^$/) {
$flush_cb->();
}
}
diff --git a/contrib/fast-import/import-tars.perl b/contrib/fast-import/import-tars.perl
index e800d9f..d50ce26 100755
--- a/contrib/fast-import/import-tars.perl
+++ b/contrib/fast-import/import-tars.perl
@@ -139,6 +139,8 @@ foreach my $tar_file (@ARGV)
print FI "\n";
}
+ next if ($typeflag eq 'g'); # ignore global header
+
my $path;
if ($prefix) {
$path = "$prefix/$name";
diff --git a/contrib/git-jump/README b/contrib/git-jump/README
index 2f618a7..3211841 100644
--- a/contrib/git-jump/README
+++ b/contrib/git-jump/README
@@ -65,6 +65,9 @@ git jump diff --cached
# jump to merge conflicts
git jump merge
+# documentation conflicts are hard; skip past them for now
+git jump merge :^Documentation
+
# jump to all instances of foo_bar
git jump grep foo_bar
@@ -76,6 +79,14 @@ git jump grep -i foo_bar
git config jump.grepCmd "ag --column"
--------------------------------------------------
+You can use the optional argument '--stdout' to print the listing to
+standard output instead of feeding it to the editor. You can use the
+argument with M-x grep on Emacs:
+
+--------------------------------------------------
+# In Emacs, M-x grep and invoke "git jump --stdout <mode>"
+M-x grep<RET>git jump --stdout diff<RET>
+--------------------------------------------------
Related Programs
----------------
@@ -97,7 +108,7 @@ Limitations
-----------
This script was written and tested with vim. Given that the quickfix
-format is the same as what gcc produces, I expect emacs users have a
+format is the same as what gcc produces, I expect other tools have a
similar feature for iterating through the list, but I know nothing about
how to activate it.
diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
index 931b0fe..47e0c55 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -2,25 +2,43 @@
usage() {
cat <<\EOF
-usage: git jump <mode> [<args>]
+usage: git jump [--stdout] <mode> [<args>]
Jump to interesting elements in an editor.
The <mode> parameter is one of:
diff: elements are diff hunks. Arguments are given to diff.
-merge: elements are merge conflicts. Arguments are ignored.
+merge: elements are merge conflicts. Arguments are given to ls-files -u.
grep: elements are grep hits. Arguments are given to git grep or, if
configured, to the command in `jump.grepCmd`.
ws: elements are whitespace errors. Arguments are given to diff --check.
+
+If the optional argument `--stdout` is given, print the quickfix
+lines to standard output instead of feeding it to the editor.
EOF
}
open_editor() {
editor=`git var GIT_EDITOR`
- eval "$editor -q \$1"
+ case "$editor" in
+ *emacs*)
+ # Supported editor values are:
+ # - emacs
+ # - emacsclient
+ # - emacsclient -t
+ #
+ # Wait for completion of the asynchronously executed process
+ # to avoid race conditions in case of "emacsclient".
+ eval "$editor --eval \"(let ((buf (grep \\\"cat \$1\\\"))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\""
+ ;;
+ *)
+ # assume anything else is vi-compatible
+ eval "$editor -q \$1"
+ ;;
+ esac
}
mode_diff() {
@@ -39,7 +57,7 @@ mode_diff() {
}
mode_merge() {
- git ls-files -u |
+ git ls-files -u "$@" |
perl -pe 's/^.*?\t//' |
sort -u |
while IFS= read fn; do
@@ -64,15 +82,36 @@ mode_ws() {
git diff --check "$@"
}
+use_stdout=
+while test $# -gt 0; do
+ case "$1" in
+ --stdout)
+ use_stdout=t
+ ;;
+ --*)
+ usage >&2
+ exit 1
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
if test $# -lt 1; then
usage >&2
exit 1
fi
mode=$1; shift
+type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
+
+if test "$use_stdout" = "t"; then
+ "mode_$mode" "$@"
+ exit 0
+fi
trap 'rm -f "$tmp"' 0 1 2 3 15
tmp=`mktemp -t git-jump.XXXXXX` || exit 1
-type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
"mode_$mode" "$@" >"$tmp"
test -s "$tmp" || exit 0
open_editor "$tmp"
diff --git a/contrib/git-resurrect.sh b/contrib/git-resurrect.sh
index 8c171dd..d843df3 100755
--- a/contrib/git-resurrect.sh
+++ b/contrib/git-resurrect.sh
@@ -27,7 +27,7 @@ n,dry-run don't recreate the branch"
search_reflog () {
sed -ne 's~^\([^ ]*\) .* checkout: moving from '"$1"' .*~\1~p' \
- < "$GIT_DIR"/logs/HEAD
+ < "$GIT_DIR"/logs/HEAD
}
search_reflog_merges () {
@@ -37,19 +37,18 @@ search_reflog_merges () {
)
}
-_x40="[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]"
-_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
+oid_pattern=$(git hash-object --stdin </dev/null | sed -e 's/./[0-9a-f]/g')
search_merges () {
- git rev-list --all --grep="Merge branch '$1'" \
- --pretty=tformat:"%P %s" |
- sed -ne "/^$_x40 \($_x40\) Merge .*/ {s//\1/p;$early_exit}"
+ git rev-list --all --grep="Merge branch '$1'" \
+ --pretty=tformat:"%P %s" |
+ sed -ne "/^$oid_pattern \($oid_pattern\) Merge .*/ {s//\1/p;$early_exit}"
}
search_merge_targets () {
git rev-list --all --grep="Merge branch '[^']*' into $branch\$" \
--pretty=tformat:"%H %s" --all |
- sed -ne "/^\($_x40\) Merge .*/ {s//\1/p;$early_exit} "
+ sed -ne "/^\($oid_pattern\) Merge .*/ {s//\1/p;$early_exit} "
}
dry_run=
diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py
deleted file mode 100755
index 7eb1b24..0000000
--- a/contrib/hg-to-git/hg-to-git.py
+++ /dev/null
@@ -1,254 +0,0 @@
-#!/usr/bin/env python
-
-""" hg-to-git.py - A Mercurial to GIT converter
-
- Copyright (C)2007 Stelian Pop <stelian@popies.net>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-"""
-
-import os, os.path, sys
-import tempfile, pickle, getopt
-import re
-
-if sys.hexversion < 0x02030000:
- # The behavior of the pickle module changed significantly in 2.3
- sys.stderr.write("hg-to-git.py: requires Python 2.3 or later.\n")
- sys.exit(1)
-
-# Maps hg version -> git version
-hgvers = {}
-# List of children for each hg revision
-hgchildren = {}
-# List of parents for each hg revision
-hgparents = {}
-# Current branch for each hg revision
-hgbranch = {}
-# Number of new changesets converted from hg
-hgnewcsets = 0
-
-#------------------------------------------------------------------------------
-
-def usage():
-
- print("""\
-%s: [OPTIONS] <hgprj>
-
-options:
- -s, --gitstate=FILE: name of the state to be saved/read
- for incrementals
- -n, --nrepack=INT: number of changesets that will trigger
- a repack (default=0, -1 to deactivate)
- -v, --verbose: be verbose
-
-required:
- hgprj: name of the HG project to import (directory)
-""" % sys.argv[0])
-
-#------------------------------------------------------------------------------
-
-def getgitenv(user, date):
- env = ''
- elems = re.compile('(.*?)\s+<(.*)>').match(user)
- if elems:
- env += 'export GIT_AUTHOR_NAME="%s" ;' % elems.group(1)
- env += 'export GIT_COMMITTER_NAME="%s" ;' % elems.group(1)
- env += 'export GIT_AUTHOR_EMAIL="%s" ;' % elems.group(2)
- env += 'export GIT_COMMITTER_EMAIL="%s" ;' % elems.group(2)
- else:
- env += 'export GIT_AUTHOR_NAME="%s" ;' % user
- env += 'export GIT_COMMITTER_NAME="%s" ;' % user
- env += 'export GIT_AUTHOR_EMAIL= ;'
- env += 'export GIT_COMMITTER_EMAIL= ;'
-
- env += 'export GIT_AUTHOR_DATE="%s" ;' % date
- env += 'export GIT_COMMITTER_DATE="%s" ;' % date
- return env
-
-#------------------------------------------------------------------------------
-
-state = ''
-opt_nrepack = 0
-verbose = False
-
-try:
- opts, args = getopt.getopt(sys.argv[1:], 's:t:n:v', ['gitstate=', 'tempdir=', 'nrepack=', 'verbose'])
- for o, a in opts:
- if o in ('-s', '--gitstate'):
- state = a
- state = os.path.abspath(state)
- if o in ('-n', '--nrepack'):
- opt_nrepack = int(a)
- if o in ('-v', '--verbose'):
- verbose = True
- if len(args) != 1:
- raise Exception('params')
-except:
- usage()
- sys.exit(1)
-
-hgprj = args[0]
-os.chdir(hgprj)
-
-if state:
- if os.path.exists(state):
- if verbose:
- print('State does exist, reading')
- f = open(state, 'r')
- hgvers = pickle.load(f)
- else:
- print('State does not exist, first run')
-
-sock = os.popen('hg tip --template "{rev}"')
-tip = sock.read()
-if sock.close():
- sys.exit(1)
-if verbose:
- print('tip is', tip)
-
-# Calculate the branches
-if verbose:
- print('analysing the branches...')
-hgchildren["0"] = ()
-hgparents["0"] = (None, None)
-hgbranch["0"] = "master"
-for cset in range(1, int(tip) + 1):
- hgchildren[str(cset)] = ()
- prnts = os.popen('hg log -r %d --template "{parents}"' % cset).read().strip().split(' ')
- prnts = map(lambda x: x[:x.find(':')], prnts)
- if prnts[0] != '':
- parent = prnts[0].strip()
- else:
- parent = str(cset - 1)
- hgchildren[parent] += ( str(cset), )
- if len(prnts) > 1:
- mparent = prnts[1].strip()
- hgchildren[mparent] += ( str(cset), )
- else:
- mparent = None
-
- hgparents[str(cset)] = (parent, mparent)
-
- if mparent:
- # For merge changesets, take either one, preferably the 'master' branch
- if hgbranch[mparent] == 'master':
- hgbranch[str(cset)] = 'master'
- else:
- hgbranch[str(cset)] = hgbranch[parent]
- else:
- # Normal changesets
- # For first children, take the parent branch, for the others create a new branch
- if hgchildren[parent][0] == str(cset):
- hgbranch[str(cset)] = hgbranch[parent]
- else:
- hgbranch[str(cset)] = "branch-" + str(cset)
-
-if "0" not in hgvers:
- print('creating repository')
- os.system('git init')
-
-# loop through every hg changeset
-for cset in range(int(tip) + 1):
-
- # incremental, already seen
- if str(cset) in hgvers:
- continue
- hgnewcsets += 1
-
- # get info
- log_data = os.popen('hg log -r %d --template "{tags}\n{date|date}\n{author}\n"' % cset).readlines()
- tag = log_data[0].strip()
- date = log_data[1].strip()
- user = log_data[2].strip()
- parent = hgparents[str(cset)][0]
- mparent = hgparents[str(cset)][1]
-
- #get comment
- (fdcomment, filecomment) = tempfile.mkstemp()
- csetcomment = os.popen('hg log -r %d --template "{desc}"' % cset).read().strip()
- os.write(fdcomment, csetcomment)
- os.close(fdcomment)
-
- print('-----------------------------------------')
- print('cset:', cset)
- print('branch:', hgbranch[str(cset)])
- print('user:', user)
- print('date:', date)
- print('comment:', csetcomment)
- if parent:
- print('parent:', parent)
- if mparent:
- print('mparent:', mparent)
- if tag:
- print('tag:', tag)
- print('-----------------------------------------')
-
- # checkout the parent if necessary
- if cset != 0:
- if hgbranch[str(cset)] == "branch-" + str(cset):
- print('creating new branch', hgbranch[str(cset)])
- os.system('git checkout -b %s %s' % (hgbranch[str(cset)], hgvers[parent]))
- else:
- print('checking out branch', hgbranch[str(cset)])
- os.system('git checkout %s' % hgbranch[str(cset)])
-
- # merge
- if mparent:
- if hgbranch[parent] == hgbranch[str(cset)]:
- otherbranch = hgbranch[mparent]
- else:
- otherbranch = hgbranch[parent]
- print('merging', otherbranch, 'into', hgbranch[str(cset)])
- os.system(getgitenv(user, date) + 'git merge --no-commit -s ours "" %s %s' % (hgbranch[str(cset)], otherbranch))
-
- # remove everything except .git and .hg directories
- os.system('find . \( -path "./.hg" -o -path "./.git" \) -prune -o ! -name "." -print | xargs rm -rf')
-
- # repopulate with checkouted files
- os.system('hg update -C %d' % cset)
-
- # add new files
- os.system('git ls-files -x .hg --others | git update-index --add --stdin')
- # delete removed files
- os.system('git ls-files -x .hg --deleted | git update-index --remove --stdin')
-
- # commit
- os.system(getgitenv(user, date) + 'git commit --allow-empty --allow-empty-message -a -F %s' % filecomment)
- os.unlink(filecomment)
-
- # tag
- if tag and tag != 'tip':
- os.system(getgitenv(user, date) + 'git tag %s' % tag)
-
- # delete branch if not used anymore...
- if mparent and len(hgchildren[str(cset)]):
- print("Deleting unused branch:", otherbranch)
- os.system('git branch -d %s' % otherbranch)
-
- # retrieve and record the version
- vvv = os.popen('git show --quiet --pretty=format:%H').read()
- print('record', cset, '->', vvv)
- hgvers[str(cset)] = vvv
-
-if hgnewcsets >= opt_nrepack and opt_nrepack != -1:
- os.system('git repack -a -d')
-
-# write the state for incrementals
-if state:
- if verbose:
- print('Writing state')
- f = open(state, 'w')
- pickle.dump(hgvers, f)
-
-# vim: et ts=8 sw=4 sts=4
diff --git a/contrib/hg-to-git/hg-to-git.txt b/contrib/hg-to-git/hg-to-git.txt
deleted file mode 100644
index 91f8fe6..0000000
--- a/contrib/hg-to-git/hg-to-git.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-hg-to-git.py is able to convert a Mercurial repository into a git one,
-and preserves the branches in the process (unlike tailor)
-
-hg-to-git.py can probably be greatly improved (it's a rather crude
-combination of shell and python) but it does already work quite well for
-me. Features:
- - supports incremental conversion
- (for keeping a git repo in sync with a hg one)
- - supports hg branches
- - converts hg tags
-
-Note that the git repository will be created 'in place' (at the same
-location as the source hg repo). You will have to manually remove the
-'.hg' directory after the conversion.
-
-Also note that the incremental conversion uses 'simple' hg changesets
-identifiers (ordinals, as opposed to SHA-1 ids), and since these ids
-are not stable across different repositories the hg-to-git.py state file
-is forever tied to one hg repository.
-
-Stelian Pop <stelian@popies.net>
diff --git a/contrib/hooks/multimail/CHANGES b/contrib/hooks/multimail/CHANGES
deleted file mode 100644
index 35791fd..0000000
--- a/contrib/hooks/multimail/CHANGES
+++ /dev/null
@@ -1,285 +0,0 @@
-Release 1.5.0
-=============
-
-Backward-incompatible change
-----------------------------
-
-The name of classes for environment was misnamed as `*Environement`.
-It is now `*Environment`.
-
-New features
-------------
-
-* A Thread-Index header is now added to each email sent (except for
- combined emails where it would not make sense), so that MS Outlook
- properly groups messages by threads even though they have a
- different subject line. Unfortunately, even adding this header the
- threading still seems to be unreliable, but it is unclear whether
- this is an issue on our side or on MS Outlook's side (see discussion
- here: https://github.com/git-multimail/git-multimail/pull/194).
-
-* A new variable multimailhook.ExcludeMergeRevisions was added to send
- notification emails only for non-merge commits.
-
-* For gitolite environment, it is now possible to specify the mail map
- in a separate file in addition to gitolite.conf, using the variable
- multimailhook.MailaddressMap.
-
-Internal changes
-----------------
-
-* The testsuite now uses GIT_PRINT_SHA1_ELLIPSIS where needed for
- compatibility with recent Git versions. Only tests are affected.
-
-* We don't try to install pyflakes in the continuous integration job
- for old Python versions where it's no longer available.
-
-* Stop using the deprecated cgi.escape in Python 3.
-
-* New flake8 warnings have been fixed.
-
-* Python 3.6 is now tested against on Travis-CI.
-
-* A bunch of lgtm.com warnings have been fixed.
-
-Bug fixes
----------
-
-* SMTPMailer logs in only once now. It used to re-login for each email
- sent which triggered errors for some SMTP servers.
-
-* migrate-mailhook-config was broken by internal refactoring, it
- should now work again.
-
-This version was tested with Python 2.6 to 3.7. It was tested with Git
-1.7.10.406.gdc801, 2.15.1 and 2.20.1.98.gecbdaf0.
-
-Release 1.4.0
-=============
-
-New features to troubleshoot a git-multimail installation
----------------------------------------------------------
-
-* One can now perform a basic check of git-multimail's setup by
- running the hook with the environment variable
- GIT_MULTIMAIL_CHECK_SETUP set to a non-empty string. See
- doc/troubleshooting.rst for details.
-
-* A new log files system was added. See the multimailhook.logFile,
- multimailhook.errorLogFile and multimailhook.debugLogFile variables.
-
-* git_multimail.py can now be made more verbose using
- multimailhook.verbose.
-
-* A new option --check-ref-filter is now available to help debugging
- the refFilter* options.
-
-Formatting emails
------------------
-
-* Formatting of emails was made slightly more compact, to reduce the
- odds of having long subject lines truncated or wrapped in short list
- of commits.
-
-* multimailhook.emailPrefix may now use the '%(repo_shortname)s'
- placeholder for the repository's short name.
-
-* A new option multimailhook.subjectMaxLength is available to truncate
- overly long subject lines.
-
-Bug fixes and minor changes
----------------------------
-
-* Options refFilterDoSendRegex and refFilterDontSendRegex were
- essentially broken. They should work now.
-
-* The behavior when both refFilter{Do,Dont}SendRegex and
- refFilter{Exclusion,Inclusion}Regex are set have been slightly
- changed. Exclusion/Inclusion is now strictly stronger than
- DoSend/DontSend.
-
-* The management of precedence when a setting can be computed in
- multiple ways has been considerably refactored and modified.
- multimailhook.from and multimailhook.reponame now have precedence
- over the environment-specific settings ($GL_REPO/$GL_USER for
- gitolite, --stash-user/repo for Stash, --submitter/--project for
- Gerrit).
-
-* The coverage of the testsuite has been considerably improved. All
- configuration variables now appear at least once in the testsuite.
-
-This version was tested with Python 2.6 to 3.5. It also mostly works
-with Python 2.4, but there is one known breakage in the testsuite
-related to non-ascii characters. It was tested with Git
-1.7.10.406.gdc801, 1.8.5.6, 2.1.4, and 2.10.0.rc0.1.g07c9292.
-
-Release 1.3.1 (bugfix-only release)
-===================================
-
-* Generate links to commits in combined emails (it was done only for
- commit emails in 1.3.0).
-
-* Fix broken links on PyPi.
-
-Release 1.3.0
-=============
-
-* New options multimailhook.htmlInIntro and multimailhook.htmlInFooter
- now allow using HTML in the introduction and footer of emails (e.g.
- for a more pleasant formatting or to insert a link to the commit on
- a web interface).
-
-* A new option multimailhook.commitBrowseURL gives a simpler (and less
- flexible) way to add a link to a web interface for commit emails
- than multimailhook.htmlInIntro and multimailhook.htmlInFooter.
-
-* A new public function config.add_config_parameters was added to
- allow custom hooks to set specific Git configuration variables
- without modifying the configuration files. See an example in
- post-receive.example.
-
-* Error handling for SMTP has been improved (we used to print Python
- backtraces for legitimate errors).
-
-* The SMTP mailer can now check TLS certificates when the newly added
- configuration variable multimailhook.smtpCACerts.
-
-* Python 3 portability has been improved.
-
-* The documentation's formatting has been improved.
-
-* The testsuite has been improved (we now use pyflakes to check for
- errors in the code).
-
-This version has been tested with Python 2.4 and 2.6 to 3.5, and Git
-v1.7.10-406-gdc801e7, 2.1.4 and 2.8.1.339.g3ad15fd.
-
-No change since 1.3 RC1.
-
-Release 1.2.0
-=============
-
-* It is now possible to exclude some refs (e.g. exclude some branches
- or tags). See refFilterDoSendRegex, refFilterDontSendRegex,
- refFilterInclusionRegex and refFilterExclusionRegex.
-
-* New commitEmailFormat option which can be set to "html" to generate
- simple colorized diffs using HTML for the commit emails.
-
-* git-multimail can now be ran as a Gerrit ref-updated hook, or from
- Atlassian BitBucket Server (formerly known as Atlassian Stash).
-
-* The From: field is now more customizeable. It can be set
- independently for refchange emails and commit emails (see
- fromCommit, fromRefChange). The special values pusher and author can
- be used in these configuration variable.
-
-* A new command-line option, --version, was added. The version is also
- available in the X-Git-Multimail-Version header of sent emails.
-
-* Set X-Git-NotificationType header to differentiate the various types
- of notifications. Current values are: diff, ref_changed_plus_diff,
- ref_changed.
-
-* Preliminary support for Python 3. The testsuite passes with Python 3,
- but it has not received as much testing as the Python 2 version yet.
-
-* Several encoding-related fixes. UTF-8 characters work in more
- situations (but non-ascii characters in email address are still not
- supported).
-
-* The testsuite and its documentation has been greatly improved.
-
-Plus all the bugfixes from version 1.1.1.
-
-This version has been tested with Python 2.4 and 2.6 to 3.5, and Git
-v1.7.10-406-gdc801e7, git-1.8.2.3 and 2.6.0. Git versions prior to
-v1.7.10-406-gdc801e7 probably work, but cannot run the testsuite
-properly.
-
-Release 1.1.1 (bugfix-only release)
-===================================
-
-* The SMTP mailer was not working with Python 2.4.
-
-Release 1.1.0
-=============
-
-* When a single commit is pushed, omit the reference changed email.
- Set multimailhook.combineWhenSingleCommit to false to disable this
- new feature.
-
-* In gitolite environments, the pusher's email address can be used as
- the From address by creating a specially formatted comment block in
- gitolite.conf (see multimailhook.from in README).
-
-* Support for SMTP authentication and SSL/TLS encryption was added,
- see smtpUser, smtpPass, smtpEncryption in README.
-
-* A new option scanCommitForCc was added to allow git-multimail to
- search the commit message for 'Cc: ...' lines, and add the
- corresponding emails in Cc.
-
-* If $USER is not set, use the variable $USERNAME. This is needed on
- Windows platform to recognize the pusher.
-
-* The emailPrefix variable can now be set to an empty string to remove
- the prefix.
-
-* A short tutorial was added in doc/gitolite.rst to set up
- git-multimail with gitolite.
-
-* The post-receive file was renamed to post-receive.example. It has
- always been an example (the standard way to call git-multimail is to
- call git_multimail.py), but it was unclear to many users.
-
-* A new refchangeShowGraph option was added to make it possible to
- include both a graph and a log in the summary emails. The options
- to control the graph formatting can be set via the new graphOpts
- option.
-
-* New option --force-send was added to disable new commit detection
- for update hook. One use-case is to run git_multimail.py after
- running "git fetch" to send emails about commits that have just been
- fetched (the detection of new commits was unreliable in this mode).
-
-* The testing infrastructure was considerably improved (continuous
- integration with travis-ci, automatic check of PEP8 and RST syntax,
- many improvements to the test scripts).
-
-This version has been tested with Python 2.4 to 2.7, and Git 1.7.1 to
-2.4.
-
-Release 1.0.0
-=============
-
-* Fix encoding of non-ASCII email addresses in email headers.
-
-* Fix backwards-compatibility bugs for older Python 2.x versions.
-
-* Fix a backwards-compatibility bug for Git 1.7.1.
-
-* Add an option commitDiffOpts to customize logs for revisions.
-
-* Pass "-oi" to sendmail by default to prevent premature termination
- on a line containing only ".".
-
-* Stagger email "Date:" values in an attempt to help mail clients
- thread the emails in the right order.
-
-* If a mailing list setting is missing, just skip sending the
- corresponding email (with a warning) instead of failing.
-
-* Add a X-Git-Host header that can be used for email filtering.
-
-* Allow the sender's fully-qualified domain name to be configured.
-
-* Minor documentation improvements.
-
-* Add this CHANGES file.
-
-
-Release 0.9.0
-=============
-
-* Initial release.
diff --git a/contrib/hooks/multimail/CONTRIBUTING.rst b/contrib/hooks/multimail/CONTRIBUTING.rst
deleted file mode 100644
index de20a54..0000000
--- a/contrib/hooks/multimail/CONTRIBUTING.rst
+++ /dev/null
@@ -1,60 +0,0 @@
-Contributing
-============
-
-git-multimail is an open-source project, built by volunteers. We would
-welcome your help!
-
-The current maintainers are `Matthieu Moy <http://matthieu-moy.fr>`__ and
-`Michael Haggerty <https://github.com/mhagger>`__.
-
-Please note that although a copy of git-multimail is distributed in
-the "contrib" section of the main Git project, development takes place
-in a separate `git-multimail repository on GitHub`_.
-
-Whenever enough changes to git-multimail have accumulated, a new
-code-drop of git-multimail will be submitted for inclusion in the Git
-project.
-
-We use the GitHub issue tracker to keep track of bugs and feature
-requests, and we use GitHub pull requests to exchange patches (though,
-if you prefer, you can send patches via the Git mailing list with CC
-to the maintainers). Please sign off your patches as per the `Git
-project practice
-<https://github.com/git/git/blob/master/Documentation/SubmittingPatches#L234>`__.
-
-Please vote for issues you would like to be addressed in priority
-(click "add your reaction" and then the "+1" thumbs-up button on the
-GitHub issue).
-
-General discussion of git-multimail can take place on the main `Git
-mailing list`_.
-
-Please CC emails regarding git-multimail to the maintainers so that we
-don't overlook them.
-
-Help needed: testers/maintainer for specific environments/OS
-------------------------------------------------------------
-
-The current maintainer uses and tests git-multimail on Linux with the
-Generic environment. More testers, or better contributors are needed
-to test git-multimail on other real-life setups:
-
-* Mac OS X, Windows: git-multimail is currently not supported on these
- platforms. But since we have no external dependencies and try to
- write code as portable as possible, it is possible that
- git-multimail already runs there and if not, it is likely that it
- could be ported easily.
-
- Patches to improve support for Windows and OS X are welcome.
- Ideally, there would be a sub-maintainer for each OS who would test
- at least once before each release (around twice a year).
-
-* Gerrit, Stash, Gitolite environments: although the testsuite
- contains tests for these environments, a tester/maintainer for each
- environment would be welcome to test and report failure (or success)
- on real-life environments periodically (here also, feedback before
- each release would be highly appreciated).
-
-
-.. _`git-multimail repository on GitHub`: https://github.com/git-multimail/git-multimail
-.. _`Git mailing list`: git@vger.kernel.org
diff --git a/contrib/hooks/multimail/README.Git b/contrib/hooks/multimail/README.Git
index 0444442..c427efc 100644
--- a/contrib/hooks/multimail/README.Git
+++ b/contrib/hooks/multimail/README.Git
@@ -1,15 +1,7 @@
-This copy of git-multimail is distributed as part of the "contrib"
-section of the Git project as a convenience to Git users.
git-multimail is developed as an independent project at the following
website:
https://github.com/git-multimail/git-multimail
-The version in this directory was obtained from the upstream project
-on January 07 2019 and consists of the "git-multimail" subdirectory from
-revision
-
- 04e80e6c40be465cc62b6c246f0fcb8fd2cfd454 refs/tags/1.5.0
-
-Please see the README file in this directory for information about how
-to report bugs or contribute to git-multimail.
+Please refer to that project page for information about how to report
+bugs or contribute to git-multimail.
diff --git a/contrib/hooks/multimail/README.migrate-from-post-receive-email b/contrib/hooks/multimail/README.migrate-from-post-receive-email
deleted file mode 100644
index 1e6a976..0000000
--- a/contrib/hooks/multimail/README.migrate-from-post-receive-email
+++ /dev/null
@@ -1,145 +0,0 @@
-git-multimail is close to, but not exactly, a plug-in replacement for
-the old Git project script contrib/hooks/post-receive-email. This
-document describes the differences and explains how to configure
-git-multimail to get behavior closest to that of post-receive-email.
-
-If you are in a hurry
-=====================
-
-A script called migrate-mailhook-config is included with
-git-multimail. If you run this script within a Git repository that is
-configured to use post-receive-email, it will convert the
-configuration settings into the approximate equivalent settings for
-git-multimail. For more information, run
-
- migrate-mailhook-config --help
-
-
-Configuration differences
-=========================
-
-* The names of the config options for git-multimail are in namespace
- "multimailhook.*" instead of "hooks.*". (Editorial comment:
- post-receive-email should never have used such a generic top-level
- namespace.)
-
-* In emails about new annotated tags, post-receive-email includes a
- shortlog of all changes since the previous annotated tag. To get
- this behavior with git-multimail, you need to set
- multimailhook.announceshortlog to true:
-
- git config multimailhook.announceshortlog true
-
-* multimailhook.commitlist -- This is a new configuration variable.
- Recipients listed here will receive a separate email for each new
- commit. However, if this variable is *not* set, it defaults to the
- value of multimailhook.mailinglist. Therefore, if you *don't* want
- the members of multimailhook.mailinglist to receive one email per
- commit, then set this value to the empty string:
-
- git config multimailhook.commitlist ''
-
-* multimailhook.emailprefix -- If this value is not set, then the
- subjects of generated emails are prefixed with the short name of the
- repository enclosed in square brackets; e.g., "[myrepo]".
- post-receive-email defaults to prefix "[SCM]" if this option is not
- set. So if you were using the old default and want to retain it
- (for example, to avoid having to change your email filters), set
- this variable explicitly to the old value:
-
- git config multimailhook.emailprefix "[SCM]"
-
-* The "multimailhook.showrev" configuration option is not supported.
- Its main use is obsoleted by the one-email-per-commit feature of
- git-multimail.
-
-
-Other differences
-=================
-
-This section describes other differences in the behavior of
-git-multimail vs. post-receive-email. For full details, please refer
-to the main README file:
-
-* One email per commit. For each reference change, the script first
- outputs one email summarizing the reference change (including
- one-line summaries of the new commits), then it outputs a separate
- email for each new commit that was introduced, including patches.
- These one-email-per-commit emails go to the addresses listed in
- multimailhook.commitlist. post-receive-email sends only one email
- for each *reference* that is changed, no matter how many commits
- were added to the reference.
-
-* Better algorithm for detecting new commits. post-receive-email
- processes one reference change at a time, which causes it to fail to
- describe new commits that were included in multiple branches. For
- example, if a single push adds the "*" commits in the diagram below,
- then post-receive-email would never include the details of the two
- commits that are common to "master" and "branch" in its
- notifications.
-
- o---o---o---*---*---* <-- master
- \
- *---* <-- branch
-
- git-multimail analyzes all reference modifications to determine
- which commits were not present before the change, therefore avoiding
- that error.
-
-* In reference change emails, git-multimail tells which commits have
- been added to the reference vs. are entirely new to the repository,
- and which commits that have been omitted from the reference
- vs. entirely discarded from the repository.
-
-* The environment in which Git is running can be configured via an
- "Environment" abstraction.
-
-* Built-in support for Gitolite-managed repositories.
-
-* Instead of using full SHA1 object names in emails, git-multimail
- mostly uses abbreviated SHA1s, plus one-line log message summaries
- where appropriate.
-
-* In the schematic diagrams that explain non-fast-forward commits,
- git-multimail shows the names of the branches involved.
-
-* The emails generated by git-multimail include the name of the Git
- repository that was modified; this is convenient for recipients who
- are monitoring multiple repositories.
-
-* git-multimail allows the email "From" addresses to be configured.
-
-* The recipients lists (multimailhook.mailinglist,
- multimailhook.refchangelist, multimailhook.announcelist, and
- multimailhook.commitlist) can be comma-separated values and/or
- multivalued settings in the config file; e.g.,
-
- [multimailhook]
- mailinglist = mr.brown@example.com, mr.black@example.com
- announcelist = Him <him@example.com>
- announcelist = Jim <jim@example.com>
- announcelist = pop@example.com
-
- This might make it easier to maintain short recipients lists without
- requiring full-fledged mailing list software.
-
-* By default, git-multimail sets email "Reply-To" headers to reply to
- the pusher (for reference updates) and to the author (for commit
- notifications). By default, the pusher's email address is
- constructed by appending "multimailhook.emaildomain" to the pusher's
- username.
-
-* The generated emails contain a configurable footer. By default, it
- lists the name of the administrator who should be contacted to
- unsubscribe from notification emails.
-
-* New option multimailhook.emailmaxlinelength to limit the length of
- lines in the main part of the email body. The default limit is 500
- characters.
-
-* New option multimailhook.emailstrictutf8 to ensure that the main
- part of the email body is valid UTF-8. Invalid characters are
- turned into the Unicode replacement character, U+FFFD. By default
- this option is turned on.
-
-* Written in Python. Easier to add new features.
diff --git a/contrib/hooks/multimail/README.rst b/contrib/hooks/multimail/README.rst
deleted file mode 100644
index 7c0fc4a..0000000
--- a/contrib/hooks/multimail/README.rst
+++ /dev/null
@@ -1,774 +0,0 @@
-git-multimail version 1.5.0
-===========================
-
-.. image:: https://travis-ci.org/git-multimail/git-multimail.svg?branch=master
- :target: https://travis-ci.org/git-multimail/git-multimail
-
-git-multimail is a tool for sending notification emails on pushes to a
-Git repository. It includes a Python module called ``git_multimail.py``,
-which can either be used as a hook script directly or can be imported
-as a Python module into another script.
-
-git-multimail is derived from the Git project's old
-contrib/hooks/post-receive-email, and is mostly compatible with that
-script. See README.migrate-from-post-receive-email for details about
-the differences and for how to migrate from post-receive-email to
-git-multimail.
-
-git-multimail, like the rest of the Git project, is licensed under
-GPLv2 (see the COPYING file for details).
-
-Please note: although, as a convenience, git-multimail may be
-distributed along with the main Git project, development of
-git-multimail takes place in its own, separate project. Please, read
-`<CONTRIBUTING.rst>`__ for more information.
-
-
-By default, for each push received by the repository, git-multimail:
-
-1. Outputs one email summarizing each reference that was changed.
- These "reference change" (called "refchange" below) emails describe
- the nature of the change (e.g., was the reference created, deleted,
- fast-forwarded, etc.) and include a one-line summary of each commit
- that was added to the reference.
-
-2. Outputs one email for each new commit that was introduced by the
- reference change. These "commit" emails include a list of the
- files changed by the commit, followed by the diffs of files
- modified by the commit. The commit emails are threaded to the
- corresponding reference change email via "In-Reply-To". This style
- (similar to the "git format-patch" style used on the Git mailing
- list) makes it easy to scan through the emails, jump to patches
- that need further attention, and write comments about specific
- commits. Commits are handled in reverse topological order (i.e.,
- parents shown before children). For example::
-
- [git] branch master updated
- + [git] 01/08: doc: fix xref link from api docs to manual pages
- + [git] 02/08: api-credentials.txt: show the big picture first
- + [git] 03/08: api-credentials.txt: mention credential.helper explicitly
- + [git] 04/08: api-credentials.txt: add "see also" section
- + [git] 05/08: t3510 (cherry-pick-sequence): add missing '&&'
- + [git] 06/08: Merge branch 'rr/maint-t3510-cascade-fix'
- + [git] 07/08: Merge branch 'mm/api-credentials-doc'
- + [git] 08/08: Git 1.7.11-rc2
-
- By default, each commit appears in exactly one commit email, the
- first time that it is pushed to the repository. If a commit is later
- merged into another branch, then a one-line summary of the commit
- is included in the reference change email (as usual), but no
- additional commit email is generated. See
- `multimailhook.refFilter(Inclusion|Exclusion|DoSend|DontSend)Regex`
- below to configure which branches and tags are watched by the hook.
-
- By default, reference change emails have their "Reply-To" field set
- to the person who pushed the change, and commit emails have their
- "Reply-To" field set to the author of the commit.
-
-3. Output one "announce" mail for each new annotated tag, including
- information about the tag and optionally a shortlog describing the
- changes since the previous tag. Such emails might be useful if you
- use annotated tags to mark releases of your project.
-
-
-Requirements
-------------
-
-* Python 2.x, version 2.4 or later. No non-standard Python modules
- are required. git-multimail has preliminary support for Python 3
- (but it has been better tested with Python 2).
-
-* The ``git`` command must be in your PATH. git-multimail is known to
- work with Git versions back to 1.7.1. (Earlier versions have not
- been tested; if you do so, please report your results.)
-
-* To send emails using the default configuration, a standard sendmail
- program must be located at '/usr/sbin/sendmail' or
- '/usr/lib/sendmail' and must be configured correctly to send emails.
- If this is not the case, set multimailhook.sendmailCommand, or see
- the multimailhook.mailer configuration variable below for how to
- configure git-multimail to send emails via an SMTP server.
-
-* git-multimail is currently tested only on Linux. It may or may not
- work on other platforms such as Windows and Mac OS. See
- `<CONTRIBUTING.rst>`__ to improve the situation.
-
-
-Invocation
-----------
-
-``git_multimail.py`` is designed to be used as a ``post-receive`` hook in a
-Git repository (see githooks(5)). Link or copy it to
-$GIT_DIR/hooks/post-receive within the repository for which email
-notifications are desired. Usually it should be installed on the
-central repository for a project, to which all commits are eventually
-pushed.
-
-For use on pre-v1.5.1 Git servers, ``git_multimail.py`` can also work as
-an ``update`` hook, taking its arguments on the command line. To use
-this script in this manner, link or copy it to $GIT_DIR/hooks/update.
-Please note that the script is not completely reliable in this mode
-[1]_.
-
-Alternatively, ``git_multimail.py`` can be imported as a Python module
-into your own Python post-receive script. This method is a bit more
-work, but allows the behavior of the hook to be customized using
-arbitrary Python code. For example, you can use a custom environment
-(perhaps inheriting from GenericEnvironment or GitoliteEnvironment) to
-
-* change how the user who did the push is determined
-
-* read users' email addresses from an LDAP server or from a database
-
-* decide which users should be notified about which commits based on
- the contents of the commits (e.g., for users who want to be notified
- only about changes affecting particular files or subdirectories)
-
-Or you can change how emails are sent by writing your own Mailer
-class. The ``post-receive`` script in this directory demonstrates how
-to use ``git_multimail.py`` as a Python module. (If you make interesting
-changes of this type, please consider sharing them with the
-community.)
-
-
-Troubleshooting/FAQ
--------------------
-
-Please read `<doc/troubleshooting.rst>`__ for frequently asked
-questions and common issues with git-multimail.
-
-
-Configuration
--------------
-
-By default, git-multimail mostly takes its configuration from the
-following ``git config`` settings:
-
-multimailhook.environment
- This describes the general environment of the repository. In most
- cases, you do not need to specify a value for this variable:
- `git-multimail` will autodetect which environment to use.
- Currently supported values:
-
- generic
- the username of the pusher is read from $USER or $USERNAME and
- the repository name is derived from the repository's path.
-
- gitolite
- Environment to use when ``git-multimail`` is ran as a gitolite_
- hook.
-
- The username of the pusher is read from $GL_USER, the repository
- name is read from $GL_REPO, and the From: header value is
- optionally read from gitolite.conf (see multimailhook.from).
-
- For more information about gitolite and git-multimail, read
- `<doc/gitolite.rst>`__
-
- stash
- Environment to use when ``git-multimail`` is ran as an Atlassian
- BitBucket Server (formerly known as Atlassian Stash) hook.
-
- **Warning:** this mode was provided by a third-party contributor
- and never tested by the git-multimail maintainers. It is
- provided as-is and may or may not work for you.
-
- This value is automatically assumed when the stash-specific
- flags (``--stash-user`` and ``--stash-repo``) are specified on
- the command line. When this environment is active, the username
- and repo come from these two command line flags, which must be
- specified.
-
- gerrit
- Environment to use when ``git-multimail`` is ran as a
- ``ref-updated`` Gerrit hook.
-
- This value is used when the gerrit-specific command line flags
- (``--oldrev``, ``--newrev``, ``--refname``, ``--project``) for
- gerrit's ref-updated hook are present. When this environment is
- active, the username of the pusher is taken from the
- ``--submitter`` argument if that command line option is passed,
- otherwise 'Gerrit' is used. The repository name is taken from
- the ``--project`` option on the command line, which must be passed.
-
- For more information about gerrit and git-multimail, read
- `<doc/gerrit.rst>`__
-
- If none of these environments is suitable for your setup, then you
- can implement a Python class that inherits from Environment and
- instantiate it via a script that looks like the example
- post-receive script.
-
- The environment value can be specified on the command line using
- the ``--environment`` option. If it is not specified on the
- command line or by ``multimailhook.environment``, the value is
- guessed as follows:
-
- * If stash-specific (respectively gerrit-specific) command flags
- are present on the command-line, then ``stash`` (respectively
- ``gerrit``) is used.
-
- * If the environment variables $GL_USER and $GL_REPO are set, then
- ``gitolite`` is used.
-
- * If none of the above apply, then ``generic`` is used.
-
-multimailhook.repoName
- A short name of this Git repository, to be used in various places
- in the notification email text. The default is to use $GL_REPO
- for gitolite repositories, or otherwise to derive this value from
- the repository path name.
-
-multimailhook.mailingList
- The list of email addresses to which notification emails should be
- sent, as RFC 2822 email addresses separated by commas. This
- configuration option can be multivalued. Leave it unset or set it
- to the empty string to not send emails by default. The next few
- settings can be used to configure specific address lists for
- specific types of notification email.
-
-multimailhook.refchangeList
- The list of email addresses to which summary emails about
- reference changes should be sent, as RFC 2822 email addresses
- separated by commas. This configuration option can be
- multivalued. The default is the value in
- multimailhook.mailingList. Set this value to "none" (or the empty
- string) to prevent reference change emails from being sent even if
- multimailhook.mailingList is set.
-
-multimailhook.announceList
- The list of email addresses to which emails about new annotated
- tags should be sent, as RFC 2822 email addresses separated by
- commas. This configuration option can be multivalued. The
- default is the value in multimailhook.refchangeList or
- multimailhook.mailingList. Set this value to "none" (or the empty
- string) to prevent annotated tag announcement emails from being sent
- even if one of the other values is set.
-
-multimailhook.commitList
- The list of email addresses to which emails about individual new
- commits should be sent, as RFC 2822 email addresses separated by
- commas. This configuration option can be multivalued. The
- default is the value in multimailhook.mailingList. Set this value
- to "none" (or the empty string) to prevent notification emails about
- individual commits from being sent even if
- multimailhook.mailingList is set.
-
-multimailhook.announceShortlog
- If this option is set to true, then emails about changes to
- annotated tags include a shortlog of changes since the previous
- tag. This can be useful if the annotated tags represent releases;
- then the shortlog will be a kind of rough summary of what has
- happened since the last release. But if your tagging policy is
- not so straightforward, then the shortlog might be confusing
- rather than useful. Default is false.
-
-multimailhook.commitEmailFormat
- The format of email messages for the individual commits, can be "text" or
- "html". In the latter case, the emails will include diffs using colorized
- HTML instead of plain text used by default. Note that this currently the
- ref change emails are always sent in plain text.
-
- Note that when using "html", the formatting is done by parsing the
- output of ``git log`` with ``-p``. When using
- ``multimailhook.commitLogOpts`` to specify a ``--format`` for
- ``git log``, one may get false positive (e.g. lines in the body of
- the message starting with ``+++`` or ``---`` colored in red or
- green).
-
- By default, all the message is HTML-escaped. See
- ``multimailhook.htmlInIntro`` to change this behavior.
-
-multimailhook.commitBrowseURL
- Used to generate a link to an online repository browser in commit
- emails. This variable must be a string. Format directives like
- ``%(<variable>)s`` will be expanded the same way as template
- strings. In particular, ``%(id)s`` will be replaced by the full
- Git commit identifier (40-chars hexadecimal).
-
- If the string does not contain any format directive, then
- ``%(id)s`` will be automatically added to the string. If you don't
- want ``%(id)s`` to be automatically added, use the empty format
- directive ``%()s`` anywhere in the string.
-
- For example, a suitable value for the git-multimail project itself
- would be
- ``https://github.com/git-multimail/git-multimail/commit/%(id)s``.
-
-multimailhook.htmlInIntro, multimailhook.htmlInFooter
- When generating an HTML message, git-multimail escapes any HTML
- sequence by default. This means that if a template contains HTML
- like ``<a href="foo">link</a>``, the reader will see the HTML
- source code and not a proper link.
-
- Set ``multimailhook.htmlInIntro`` to true to allow writing HTML
- formatting in introduction templates. Similarly, set
- ``multimailhook.htmlInFooter`` for HTML in the footer.
-
- Variables expanded in the template are still escaped. For example,
- if a repository's path contains a ``<``, it will be rendered as
- such in the message.
-
- Read `<doc/customizing-emails.rst>`__ for more details and
- examples.
-
-multimailhook.refchangeShowGraph
- If this option is set to true, then summary emails about reference
- changes will additionally include:
-
- * a graph of the added commits (if any)
-
- * a graph of the discarded commits (if any)
-
- The log is generated by running ``git log --graph`` with the options
- specified in graphOpts. The default is false.
-
-multimailhook.refchangeShowLog
- If this option is set to true, then summary emails about reference
- changes will include a detailed log of the added commits in
- addition to the one line summary. The log is generated by running
- ``git log`` with the options specified in multimailhook.logOpts.
- Default is false.
-
-multimailhook.mailer
- This option changes the way emails are sent. Accepted values are:
-
- * **sendmail (the default)**: use the command ``/usr/sbin/sendmail`` or
- ``/usr/lib/sendmail`` (or sendmailCommand, if configured). This
- mode can be further customized via the following options:
-
- multimailhook.sendmailCommand
- The command used by mailer ``sendmail`` to send emails. Shell
- quoting is allowed in the value of this setting, but remember that
- Git requires double-quotes to be escaped; e.g.::
-
- git config multimailhook.sendmailcommand '/usr/sbin/sendmail -oi -t -F \"Git Repo\"'
-
- Default is '/usr/sbin/sendmail -oi -t' or
- '/usr/lib/sendmail -oi -t' (depending on which file is
- present and executable).
-
- multimailhook.envelopeSender
- If set then pass this value to sendmail via the -f option to set
- the envelope sender address.
-
- * **smtp**: use Python's smtplib. This is useful when the sendmail
- command is not available on the system. This mode can be
- further customized via the following options:
-
- multimailhook.smtpServer
- The name of the SMTP server to connect to. The value can
- also include a colon and a port number; e.g.,
- ``mail.example.com:25``. Default is 'localhost' using port 25.
-
- multimailhook.smtpUser, multimailhook.smtpPass
- Server username and password. Required if smtpEncryption is 'ssl'.
- Note that the username and password currently need to be
- set cleartext in the configuration file, which is not
- recommended. If you need to use this option, be sure your
- configuration file is read-only.
-
- multimailhook.envelopeSender
- The sender address to be passed to the SMTP server. If
- unset, then the value of multimailhook.from is used.
-
- multimailhook.smtpServerTimeout
- Timeout in seconds. Default is 10.
-
- multimailhook.smtpEncryption
- Set the security type. Allowed values: ``none``, ``ssl``, ``tls`` (starttls).
- Default is ``none``.
-
- multimailhook.smtpCACerts
- Set the path to a list of trusted CA certificate to verify the
- server certificate, only supported when ``smtpEncryption`` is
- ``tls``. If unset or empty, the server certificate is not
- verified. If it targets a file containing a list of trusted CA
- certificates (PEM format) these CAs will be used to verify the
- server certificate. For debian, you can set
- ``/etc/ssl/certs/ca-certificates.crt`` for using the system
- trusted CAs. For self-signed server, you can add your server
- certificate to the system store::
-
- cd /usr/local/share/ca-certificates/
- openssl s_client -starttls smtp \
- -connect mail.example.net:587 -showcerts \
- </dev/null 2>/dev/null \
- | openssl x509 -outform PEM >mail.example.net.crt
- update-ca-certificates
-
- and used the updated ``/etc/ssl/certs/ca-certificates.crt``. Or
- directly use your ``/path/to/mail.example.net.crt``. Default is
- unset.
-
- multimailhook.smtpServerDebugLevel
- Integer number. Set to greater than 0 to activate debugging.
-
-multimailhook.from, multimailhook.fromCommit, multimailhook.fromRefchange
- If set, use this value in the From: field of generated emails.
- ``fromCommit`` is used for commit emails, ``fromRefchange`` is
- used for refchange emails, and ``from`` is used as fall-back in
- all cases.
-
- The value for these variables can be either:
-
- - An email address, which will be used directly.
-
- - The value ``pusher``, in which case the pusher's address (if
- available) will be used.
-
- - The value ``author`` (meaningful only for ``fromCommit``), in which
- case the commit author's address will be used.
-
- If config values are unset, the value of the From: header is
- determined as follows:
-
- 1. (gitolite environment only)
- 1.a) If ``multimailhook.MailaddressMap`` is set, and is a path
- to an existing file (if relative, it is considered relative to
- the place where ``gitolite.conf`` is located), then this file
- should contain lines like::
-
- username Firstname Lastname <email@example.com>
-
- git-multimail will then look for a line where ``$GL_USER``
- matches the ``username`` part, and use the rest of the line for
- the ``From:`` header.
-
- 1.b) Parse gitolite.conf, looking for a block of comments that
- looks like this::
-
- # BEGIN USER EMAILS
- # username Firstname Lastname <email@example.com>
- # END USER EMAILS
-
- If that block exists, and there is a line between the BEGIN
- USER EMAILS and END USER EMAILS lines where the first field
- matches the gitolite username ($GL_USER), use the rest of the
- line for the From: header.
-
- 2. If the user.email configuration setting is set, use its value
- (and the value of user.name, if set).
-
- 3. Use the value of multimailhook.envelopeSender.
-
-multimailhook.MailaddressMap
- (gitolite environment only)
- File to look for a ``From:`` address based on the user doing the
- push. Defaults to unset. See ``multimailhook.from`` for details.
-
-multimailhook.administrator
- The name and/or email address of the administrator of the Git
- repository; used in FOOTER_TEMPLATE. Default is
- multimailhook.envelopesender if it is set; otherwise a generic
- string is used.
-
-multimailhook.emailPrefix
- All emails have this string prepended to their subjects, to aid
- email filtering (though filtering based on the X-Git-* email
- headers is probably more robust). Default is the short name of
- the repository in square brackets; e.g., ``[myrepo]``. Set this
- value to the empty string to suppress the email prefix. You may
- use the placeholder ``%(repo_shortname)s`` for the short name of
- the repository.
-
-multimailhook.emailMaxLines
- The maximum number of lines that should be included in the body of
- a generated email. If not specified, there is no limit. Lines
- beyond the limit are suppressed and counted, and a final line is
- added indicating the number of suppressed lines.
-
-multimailhook.emailMaxLineLength
- The maximum length of a line in the email body. Lines longer than
- this limit are truncated to this length with a trailing ``[...]``
- added to indicate the missing text. The default is 500, because
- (a) diffs with longer lines are probably from binary files, for
- which a diff is useless, and (b) even if a text file has such long
- lines, the diffs are probably unreadable anyway. To disable line
- truncation, set this option to 0.
-
-multimailhook.subjectMaxLength
- The maximum length of the subject line (i.e. the ``oneline`` field
- in templates, not including the prefix). Lines longer than this
- limit are truncated to this length with a trailing ``[...]`` added
- to indicate the missing text. This option The default is to use
- ``multimailhook.emailMaxLineLength``. This option avoids sending
- emails with overly long subject lines, but should not be needed if
- the commit messages follow the Git convention (one short subject
- line, then a blank line, then the message body). To disable line
- truncation, set this option to 0.
-
-multimailhook.maxCommitEmails
- The maximum number of commit emails to send for a given change.
- When the number of patches is larger that this value, only the
- summary refchange email is sent. This can avoid accidental
- mailbombing, for example on an initial push. To disable commit
- emails limit, set this option to 0. The default is 500.
-
-multimailhook.excludeMergeRevisions
- When sending out revision emails, do not consider merge commits (the
- functional equivalent of `rev-list --no-merges`).
- The default is `false` (send merge commit emails).
-
-multimailhook.emailStrictUTF8
- If this boolean option is set to `true`, then the main part of the
- email body is forced to be valid UTF-8. Any characters that are
- not valid UTF-8 are converted to the Unicode replacement
- character, U+FFFD. The default is `true`.
-
- This option is ineffective with Python 3, where non-UTF-8
- characters are unconditionally replaced.
-
-multimailhook.diffOpts
- Options passed to ``git diff-tree`` when generating the summary
- information for ReferenceChange emails. Default is ``--stat
- --summary --find-copies-harder``. Add -p to those options to
- include a unified diff of changes in addition to the usual summary
- output. Shell quoting is allowed; see ``multimailhook.logOpts`` for
- details.
-
-multimailhook.graphOpts
- Options passed to ``git log --graph`` when generating graphs for the
- reference change summary emails (used only if refchangeShowGraph
- is true). The default is '--oneline --decorate'.
-
- Shell quoting is allowed; see logOpts for details.
-
-multimailhook.logOpts
- Options passed to ``git log`` to generate additional info for
- reference change emails (used only if refchangeShowLog is set).
- For example, adding -p will show each commit's complete diff. The
- default is empty.
-
- Shell quoting is allowed; for example, a log format that contains
- spaces can be specified using something like::
-
- git config multimailhook.logopts '--pretty=format:"%h %aN <%aE>%n%s%n%n%b%n"'
-
- If you want to set this by editing your configuration file
- directly, remember that Git requires double-quotes to be escaped
- (see git-config(1) for more information)::
-
- [multimailhook]
- logopts = --pretty=format:\"%h %aN <%aE>%n%s%n%n%b%n\"
-
-multimailhook.commitLogOpts
- Options passed to ``git log`` to generate additional info for
- revision change emails. For example, adding --ignore-all-spaces
- will suppress whitespace changes. The default options are ``-C
- --stat -p --cc``. Shell quoting is allowed; see
- multimailhook.logOpts for details.
-
-multimailhook.dateSubstitute
- String to use as a substitute for ``Date:`` in the output of ``git
- log`` while formatting commit messages. This is useful to avoid
- emitting a line that can be interpreted by mailers as the start of
- a cited message (Zimbra webmail in particular). Defaults to
- ``CommitDate:``. Set to an empty string or ``none`` to deactivate
- the behavior.
-
-multimailhook.emailDomain
- Domain name appended to the username of the person doing the push
- to convert it into an email address
- (via ``"%s@%s" % (username, emaildomain)``). More complicated
- schemes can be implemented by overriding Environment and
- overriding its get_pusher_email() method.
-
-multimailhook.replyTo, multimailhook.replyToCommit, multimailhook.replyToRefchange
- Addresses to use in the Reply-To: field for commit emails
- (replyToCommit) and refchange emails (replyToRefchange).
- multimailhook.replyTo is used as default when replyToCommit or
- replyToRefchange is not set. The shortcuts ``pusher`` and
- ``author`` are allowed with the same semantics as for
- ``multimailhook.from``. In addition, the value ``none`` can be
- used to omit the ``Reply-To:`` field.
-
- The default is ``pusher`` for refchange emails, and ``author`` for
- commit emails.
-
-multimailhook.quiet
- Do not output the list of email recipients from the hook
-
-multimailhook.stdout
- For debugging, send emails to stdout rather than to the
- mailer. Equivalent to the --stdout command line option
-
-multimailhook.scanCommitForCc
- If this option is set to true, than recipients from lines in commit body
- that starts with ``CC:`` will be added to CC list.
- Default: false
-
-multimailhook.combineWhenSingleCommit
- If this option is set to true and a single new commit is pushed to
- a branch, combine the summary and commit email messages into a
- single email.
- Default: true
-
-multimailhook.refFilterInclusionRegex, multimailhook.refFilterExclusionRegex, multimailhook.refFilterDoSendRegex, multimailhook.refFilterDontSendRegex
- **Warning:** these options are experimental. They should work, but
- the user-interface is not stable yet (in particular, the option
- names may change). If you want to participate in stabilizing the
- feature, please contact the maintainers and/or send pull-requests.
- If you are happy with the current shape of the feature, please
- report it too.
-
- Regular expressions that can be used to limit refs for which email
- updates will be sent. It is an error to specify both an inclusion
- and an exclusion regex. If a ``refFilterInclusionRegex`` is
- specified, emails will only be sent for refs which match this
- regex. If a ``refFilterExclusionRegex`` regex is specified,
- emails will be sent for all refs except those that match this
- regex (or that match a predefined regex specific to the
- environment, such as "^refs/notes" for most environments and
- "^refs/notes|^refs/changes" for the gerrit environment).
-
- The expressions are matched against the complete refname, and is
- considered to match if any substring matches. For example, to
- filter-out all tags, set ``refFilterExclusionRegex`` to
- ``^refs/tags/`` (note the leading ``^`` but no trailing ``$``). If
- you set ``refFilterExclusionRegex`` to ``master``, then any ref
- containing ``master`` will be excluded (the ``master`` branch, but
- also ``refs/tags/master`` or ``refs/heads/foo-master-bar``).
-
- ``refFilterDoSendRegex`` and ``refFilterDontSendRegex`` are
- analogous to ``refFilterInclusionRegex`` and
- ``refFilterExclusionRegex`` with one difference: with
- ``refFilterDoSendRegex`` and ``refFilterDontSendRegex``, commits
- introduced by one excluded ref will not be considered as new when
- they reach an included ref. Typically, if you add a branch ``foo``
- to ``refFilterDontSendRegex``, push commits to this branch, and
- later merge branch ``foo`` into ``master``, then the notification
- email for ``master`` will contain a commit email only for the
- merge commit. If you include ``foo`` in
- ``refFilterExclusionRegex``, then at the time of merge, you will
- receive one commit email per commit in the branch.
-
- These variables can be multi-valued, like::
-
- [multimailhook]
- refFilterExclusionRegex = ^refs/tags/
- refFilterExclusionRegex = ^refs/heads/master$
-
- You can also provide a whitespace-separated list like::
-
- [multimailhook]
- refFilterExclusionRegex = ^refs/tags/ ^refs/heads/master$
-
- Both examples exclude tags and the master branch, and are
- equivalent to::
-
- [multimailhook]
- refFilterExclusionRegex = ^refs/tags/|^refs/heads/master$
-
- ``refFilterInclusionRegex`` and ``refFilterExclusionRegex`` are
- strictly stronger than ``refFilterDoSendRegex`` and
- ``refFilterDontSendRegex``. In other words, adding a ref to a
- DoSend/DontSend regex has no effect if it is already excluded by a
- Exclusion/Inclusion regex.
-
-multimailhook.logFile, multimailhook.errorLogFile, multimailhook.debugLogFile
-
- When set, these variable designate path to files where
- git-multimail will log some messages. Normal messages and error
- messages are sent to ``logFile``, and error messages are also sent
- to ``errorLogFile``. Debug messages and all other messages are
- sent to ``debugLogFile``. The recommended way is to set only one
- of these variables, but it is also possible to set several of them
- (part of the information is then duplicated in several log files,
- for example errors are duplicated to all log files).
-
- Relative path are relative to the Git repository where the push is
- done.
-
-multimailhook.verbose
-
- Verbosity level of git-multimail on its standard output. By
- default, show only error and info messages. If set to true, show
- also debug messages.
-
-Email filtering aids
---------------------
-
-All emails include extra headers to enable fine tuned filtering and
-give information for debugging. All emails include the headers
-``X-Git-Host``, ``X-Git-Repo``, ``X-Git-Refname``, and ``X-Git-Reftype``.
-ReferenceChange emails also include headers ``X-Git-Oldrev`` and ``X-Git-Newrev``;
-Revision emails also include header ``X-Git-Rev``.
-
-
-Customizing email contents
---------------------------
-
-git-multimail mostly generates emails by expanding templates. The
-templates can be customized. To avoid the need to edit
-``git_multimail.py`` directly, the preferred way to change the templates
-is to write a separate Python script that imports ``git_multimail.py`` as
-a module, then replaces the templates in place. See the provided
-post-receive script for an example of how this is done.
-
-
-Customizing git-multimail for your environment
-----------------------------------------------
-
-git-multimail is mostly customized via an "environment" that describes
-the local environment in which Git is running. Two types of
-environment are built in:
-
-GenericEnvironment
- a stand-alone Git repository.
-
-GitoliteEnvironment
- a Git repository that is managed by gitolite_. For such
- repositories, the identity of the pusher is read from
- environment variable $GL_USER, the name of the repository is read
- from $GL_REPO (if it is not overridden by multimailhook.reponame),
- and the From: header value is optionally read from gitolite.conf
- (see multimailhook.from).
-
-By default, git-multimail assumes GitoliteEnvironment if $GL_USER and
-$GL_REPO are set, and otherwise assumes GenericEnvironment.
-Alternatively, you can choose one of these two environments explicitly
-by setting a ``multimailhook.environment`` config setting (which can
-have the value `generic` or `gitolite`) or by passing an --environment
-option to the script.
-
-If you need to customize the script in ways that are not supported by
-the existing environments, you can define your own environment class
-class using arbitrary Python code. To do so, you need to import
-``git_multimail.py`` as a Python module, as demonstrated by the example
-post-receive script. Then implement your environment class; it should
-usually inherit from one of the existing Environment classes and
-possibly one or more of the EnvironmentMixin classes. Then set the
-``environment`` variable to an instance of your own environment class
-and pass it to ``run_as_post_receive_hook()``.
-
-The standard environment classes, GenericEnvironment and
-GitoliteEnvironment, are in fact themselves put together out of a
-number of mixin classes, each of which handles one aspect of the
-customization. For the finest control over your configuration, you
-can specify exactly which mixin classes your own environment class
-should inherit from, and override individual methods (or even add your
-own mixin classes) to implement entirely new behaviors. If you
-implement any mixins that might be useful to other people, please
-consider sharing them with the community!
-
-
-Getting involved
-----------------
-
-Please, read `<CONTRIBUTING.rst>`__ for instructions on how to
-contribute to git-multimail.
-
-
-Footnotes
----------
-
-.. [1] Because of the way information is passed to update hooks, the
- script's method of determining whether a commit has already
- been seen does not work when it is used as an ``update`` script.
- In particular, no notification email will be generated for a
- new commit that is added to multiple references in the same
- push. A workaround is to use --force-send to force sending the
- emails.
-
-.. _gitolite: https://github.com/sitaramc/gitolite
diff --git a/contrib/hooks/multimail/doc/customizing-emails.rst b/contrib/hooks/multimail/doc/customizing-emails.rst
deleted file mode 100644
index 3f5b67f..0000000
--- a/contrib/hooks/multimail/doc/customizing-emails.rst
+++ /dev/null
@@ -1,56 +0,0 @@
-Customizing the content and formatting of emails
-================================================
-
-Overloading template strings
-----------------------------
-
-The content of emails is generated based on template strings defined
-in ``git_multimail.py``. You can customize these template strings
-without changing the script itself, by defining a Python wrapper
-around it. The python wrapper should ``import git_multimail`` and then
-override the ``git_multimail.*`` strings like this::
-
- import sys # needed for sys.argv
-
- # Import and customize git_multimail:
- import git_multimail
- git_multimail.REVISION_INTRO_TEMPLATE = """..."""
- git_multimail.COMBINED_INTRO_TEMPLATE = git_multimail.REVISION_INTRO_TEMPLATE
-
- # start git_multimail itself:
- git_multimail.main(sys.argv[1:])
-
-The template strings can use any value already used in the existing
-templates (read the source code).
-
-Using HTML in template strings
-------------------------------
-
-If ``multimailhook.commitEmailFormat`` is set to HTML, then
-git-multimail will generate HTML emails for commit notifications. The
-log and diff will be formatted automatically by git-multimail. By
-default, any HTML special character in the templates will be escaped.
-
-To use HTML formatting in the introduction of the email, set
-``multimailhook.htmlInIntro`` to ``true``. Then, the template can
-contain any HTML tags, that will be sent as-is in the email. For
-example, to add some formatting and a link to the online commit, use
-a format like::
-
- git_multimail.REVISION_INTRO_TEMPLATE = """\
- <span style="color:#808080">This is an automated email from the git hooks/post-receive script.</span><br /><br />
-
- <strong>%(pusher)s</strong> pushed a commit to %(refname_type)s %(short_refname)s
- in repository %(repo_shortname)s.<br />
-
- <a href="https://github.com/git-multimail/git-multimail/commit/%(newrev)s">View on GitHub</a>.
- """
-
-Note that the values expanded from ``%(variable)s`` in the format
-strings will still be escaped.
-
-For a less flexible but easier to set up way to add a link to commit
-emails, see ``multimailhook.commitBrowseURL``.
-
-Similarly, one can set ``multimailhook.htmlInFooter`` and override any
-of the ``*_FOOTER*`` template strings.
diff --git a/contrib/hooks/multimail/doc/gerrit.rst b/contrib/hooks/multimail/doc/gerrit.rst
deleted file mode 100644
index 8011d05..0000000
--- a/contrib/hooks/multimail/doc/gerrit.rst
+++ /dev/null
@@ -1,56 +0,0 @@
-Setting up git-multimail on Gerrit
-==================================
-
-Gerrit has its own email-sending system, but you may prefer using
-``git-multimail`` instead. It supports Gerrit natively as a Gerrit
-``ref-updated`` hook (Warning: `Gerrit hooks
-<https://gerrit-review.googlesource.com/Documentation/config-hooks.html>`__
-are distinct from Git hooks). Setting up ``git-multimail`` on a Gerrit
-installation can be done following the instructions below.
-
-The explanations show an easy way to set up ``git-multimail``,
-but leave ``git-multimail`` installed and unconfigured for a while. If
-you run Gerrit on a production server, it is advised that you
-execute the step "Set up the hook" last to avoid confusing your users
-in the meantime.
-
-Set up the hook
----------------
-
-Create a directory ``$site_path/hooks/`` if it does not exist (if you
-don't know what ``$site_path`` is, run ``gerrit.sh status`` and look
-for a ``GERRIT_SITE`` line). Either copy ``git_multimail.py`` to
-``$site_path/hooks/ref-updated`` or create a wrapper script like
-this::
-
- #! /bin/sh
- exec /path/to/git_multimail.py "$@"
-
-In both cases, make sure the file is named exactly
-``$site_path/hooks/ref-updated`` and is executable.
-
-(Alternatively, you may configure the ``[hooks]`` section of
-gerrit.config)
-
-Configuration
--------------
-
-Log on the gerrit server and edit ``$site_path/git/$project/config``
-to configure ``git-multimail``.
-
-Troubleshooting
----------------
-
-Warning: this will disable ``git-multimail`` during the debug, and
-could confuse your users. Don't run on a production server.
-
-To debug configuration issues with ``git-multimail``, you can add the
-``--stdout`` option when calling ``git_multimail.py`` like this::
-
- #!/bin/sh
- exec /path/to/git-multimail/git-multimail/git_multimail.py \
- --stdout "$@" >> /tmp/log.txt
-
-and try pushing from a test repository. You should see the source of
-the email that would have been sent in the output of ``git push`` in
-the file ``/tmp/log.txt``.
diff --git a/contrib/hooks/multimail/doc/gitolite.rst b/contrib/hooks/multimail/doc/gitolite.rst
deleted file mode 100644
index 5054833..0000000
--- a/contrib/hooks/multimail/doc/gitolite.rst
+++ /dev/null
@@ -1,118 +0,0 @@
-Setting up git-multimail on gitolite
-====================================
-
-``git-multimail`` supports gitolite 3 natively.
-The explanations below show an easy way to set up ``git-multimail``,
-but leave ``git-multimail`` installed and unconfigured for a while. If
-you run gitolite on a production server, it is advised that you
-execute the step "Set up the hook" last to avoid confusing your users
-in the meantime.
-
-Set up the hook
----------------
-
-Log in as your gitolite user.
-
-Create a file ``.gitolite/hooks/common/post-receive`` on your gitolite
-account containing (adapt the path, obviously)::
-
- #!/bin/sh
- exec /path/to/git-multimail/git-multimail/git_multimail.py "$@"
-
-Make sure it's executable (``chmod +x``). Record the hook in
-gitolite::
-
- gitolite setup
-
-Configuration
--------------
-
-First, you have to allow the admin to set Git configuration variables.
-
-As gitolite user, edit the line containing ``GIT_CONFIG_KEYS`` in file
-``.gitolite.rc``, to make it look like::
-
- GIT_CONFIG_KEYS => 'multimailhook\..*',
-
-You can now log out and return to your normal user.
-
-In the ``gitolite-admin`` clone, edit the file ``conf/gitolite.conf``
-and add::
-
- repo @all
- # Not strictly needed as git_multimail.py will chose gitolite if
- # $GL_USER is set.
- config multimailhook.environment = gitolite
- config multimailhook.mailingList = # Where emails should be sent
- config multimailhook.from = # From address to use
-
-Note that by default, gitolite forbids ``<`` and ``>`` in variable
-values (for security/paranoia reasons, see
-`compensating for UNSAFE_PATT
-<http://gitolite.com/gitolite/git-config/index.html#compensating-for-unsafe95patt>`__
-in gitolite's documentation for explanations and a way to disable
-this). As a consequence, you will not be able to use ``First Last
-<First.Last@example.com>`` as recipient email, but specifying
-``First.Last@example.com`` alone works.
-
-Obviously, you can customize all parameters on a per-repository basis by
-adding these ``config multimailhook.*`` lines in the section
-corresponding to a repository or set of repositories.
-
-To activate ``git-multimail`` on a per-repository basis, do not set
-``multimailhook.mailingList`` in the ``@all`` section and set it only
-for repositories for which you want ``git-multimail``.
-
-Alternatively, you can set up the ``From:`` field on a per-user basis
-by adding a ``BEGIN USER EMAILS``/``END USER EMAILS`` section (see
-``../README``).
-
-Specificities of Gitolite for Configuration
--------------------------------------------
-
-Empty configuration variables
-.............................
-
-With gitolite, the syntax ``config multimailhook.commitList = ""``
-unsets the variable instead of setting it to an empty string (see
-`here
-<http://gitolite.com/gitolite/git-config.html#an-important-warning-about-deleting-a-config-line>`__).
-As a result, there is no way to set a variable to the empty string.
-In all most places where an empty value is required, git-multimail
-now allows to specify special ``"none"`` value (case-sensitive) to
-mean the same.
-
-Alternatively, one can use ``" "`` (a single space) instead of ``""``.
-In most cases (in particular ``multimailhook.*List`` variables), this
-will be equivalent to an empty string.
-
-If you have a use-case where ``"none"`` is not an acceptable value and
-you need ``" "`` or ``""`` instead, please report it as a bug to
-git-multimail.
-
-Allowing Regular Expressions in Configuration
-.............................................
-
-gitolite has a mechanism to prevent unsafe configuration variable
-values, which prevent characters like ``|`` commonly used in regular
-expressions. If you do not need the safety feature of gitolite and
-need to use regular expressions in your configuration (e.g. for
-``multimailhook.refFilter*`` variables), set
-`UNSAFE_PATT
-<http://gitolite.com/gitolite/git-config.html#unsafe-patt>`__ to a
-less restrictive value.
-
-Troubleshooting
----------------
-
-Warning: this will disable ``git-multimail`` during the debug, and
-could confuse your users. Don't run on a production server.
-
-To debug configuration issues with ``git-multimail``, you can add the
-``--stdout`` option when calling ``git_multimail.py`` like this::
-
- #!/bin/sh
- exec /path/to/git-multimail/git-multimail/git_multimail.py --stdout "$@"
-
-and try pushing from a test repository. You should see the source of
-the email that would have been sent in the output of ``git push``.
diff --git a/contrib/hooks/multimail/doc/troubleshooting.rst b/contrib/hooks/multimail/doc/troubleshooting.rst
deleted file mode 100644
index 651b509..0000000
--- a/contrib/hooks/multimail/doc/troubleshooting.rst
+++ /dev/null
@@ -1,78 +0,0 @@
-Troubleshooting issues with git-multimail: a FAQ
-================================================
-
-How to check that git-multimail is properly set up?
----------------------------------------------------
-
-Since version 1.4.0, git-multimail allows a simple self-checking of
-its configuration: run it with the environment variable
-``GIT_MULTIMAIL_CHECK_SETUP`` set to a non-empty string. You should
-get something like this::
-
- $ GIT_MULTIMAIL_CHECK_SETUP=true /home/moy/dev/git-multimail/git-multimail/git_multimail.py
- Environment values:
- administrator : 'the administrator of this repository'
- charset : 'utf-8'
- emailprefix : '[git-multimail] '
- fqdn : 'anie'
- projectdesc : 'UNNAMED PROJECT'
- pusher : 'moy'
- repo_path : '/home/moy/dev/git-multimail'
- repo_shortname : 'git-multimail'
-
- Now, checking that git-multimail's standard input is properly set ...
- Please type some text and then press Return
- foo
- You have just entered:
- foo
- git-multimail seems properly set up.
-
-If you forgot to set an important variable, you may get instead::
-
- $ GIT_MULTIMAIL_CHECK_SETUP=true /home/moy/dev/git-multimail/git-multimail/git_multimail.py
- No email recipients configured!
-
-Do not set ``$GIT_MULTIMAIL_CHECK_SETUP`` other than for testing your
-configuration: it would disable the hook completely.
-
-Git is not using the right address in the From/To/Reply-To field
-----------------------------------------------------------------
-
-First, make sure that git-multimail actually uses what you think it is
-using. A lot happens to your email (especially when posting to a
-mailing-list) between the time `git_multimail.py` sends it and the
-time it reaches your inbox.
-
-A simple test (to do on a test repository, do not use in production as
-it would disable email sending): change your post-receive hook to call
-`git_multimail.py` with the `--stdout` option, and try to push to the
-repository. You should see something like::
-
- Counting objects: 3, done.
- Writing objects: 100% (3/3), 263 bytes | 0 bytes/s, done.
- Total 3 (delta 0), reused 0 (delta 0)
- remote: Sending notification emails to: foo.bar@example.com
- remote: ===========================================================================
- remote: Date: Mon, 25 Apr 2016 18:39:59 +0200
- remote: To: foo.bar@example.com
- remote: Subject: [git] branch master updated: foo
- remote: MIME-Version: 1.0
- remote: Content-Type: text/plain; charset=utf-8
- remote: Content-Transfer-Encoding: 8bit
- remote: Message-ID: <20160425163959.2311.20498@anie>
- remote: From: Auth Or <Foo.Bar@example.com>
- remote: Reply-To: Auth Or <Foo.Bar@example.com>
- remote: X-Git-Host: example
- ...
- remote: --
- remote: To stop receiving notification emails like this one, please contact
- remote: the administrator of this repository.
- remote: ===========================================================================
- To /path/to/repo
- 6278f04..e173f20 master -> master
-
-Note: this does not include the sender (Return-Path: header), as it is
-not part of the message content but passed to the mailer. Some mailer
-show the ``Sender:`` field instead of the ``From:`` field (for
-example, Zimbra Webmail shows ``From: <sender-field> on behalf of
-<from-field>``).
diff --git a/contrib/hooks/multimail/git_multimail.py b/contrib/hooks/multimail/git_multimail.py
deleted file mode 100755
index 8823399..0000000
--- a/contrib/hooks/multimail/git_multimail.py
+++ /dev/null
@@ -1,4346 +0,0 @@
-#! /usr/bin/env python
-
-__version__ = '1.5.0'
-
-# Copyright (c) 2015-2016 Matthieu Moy and others
-# Copyright (c) 2012-2014 Michael Haggerty and others
-# Derived from contrib/hooks/post-receive-email, which is
-# Copyright (c) 2007 Andy Parkins
-# and also includes contributions by other authors.
-#
-# This file is part of git-multimail.
-#
-# git-multimail is free software: you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version
-# 2 as published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see
-# <http://www.gnu.org/licenses/>.
-
-"""Generate notification emails for pushes to a git repository.
-
-This hook sends emails describing changes introduced by pushes to a
-git repository. For each reference that was changed, it emits one
-ReferenceChange email summarizing how the reference was changed,
-followed by one Revision email for each new commit that was introduced
-by the reference change.
-
-Each commit is announced in exactly one Revision email. If the same
-commit is merged into another branch in the same or a later push, then
-the ReferenceChange email will list the commit's SHA1 and its one-line
-summary, but no new Revision email will be generated.
-
-This script is designed to be used as a "post-receive" hook in a git
-repository (see githooks(5)). It can also be used as an "update"
-script, but this usage is not completely reliable and is deprecated.
-
-To help with debugging, this script accepts a --stdout option, which
-causes the emails to be written to standard output rather than sent
-using sendmail.
-
-See the accompanying README file for the complete documentation.
-
-"""
-
-import sys
-import os
-import re
-import bisect
-import socket
-import subprocess
-import shlex
-import optparse
-import logging
-import smtplib
-try:
- import ssl
-except ImportError:
- # Python < 2.6 do not have ssl, but that's OK if we don't use it.
- pass
-import time
-
-import uuid
-import base64
-
-PYTHON3 = sys.version_info >= (3, 0)
-
-if sys.version_info <= (2, 5):
- def all(iterable):
- for element in iterable:
- if not element:
- return False
- return True
-
-
-def is_ascii(s):
- return all(ord(c) < 128 and ord(c) > 0 for c in s)
-
-
-if PYTHON3:
- def is_string(s):
- return isinstance(s, str)
-
- def str_to_bytes(s):
- return s.encode(ENCODING)
-
- def bytes_to_str(s, errors='strict'):
- return s.decode(ENCODING, errors)
-
- unicode = str
-
- def write_str(f, msg):
- # Try outputing with the default encoding. If it fails,
- # try UTF-8.
- try:
- f.buffer.write(msg.encode(sys.getdefaultencoding()))
- except UnicodeEncodeError:
- f.buffer.write(msg.encode(ENCODING))
-
- def read_line(f):
- # Try reading with the default encoding. If it fails,
- # try UTF-8.
- out = f.buffer.readline()
- try:
- return out.decode(sys.getdefaultencoding())
- except UnicodeEncodeError:
- return out.decode(ENCODING)
-
- import html
-
- def html_escape(s):
- return html.escape(s)
-
-else:
- def is_string(s):
- try:
- return isinstance(s, basestring)
- except NameError: # Silence Pyflakes warning
- raise
-
- def str_to_bytes(s):
- return s
-
- def bytes_to_str(s, errors='strict'):
- return s
-
- def write_str(f, msg):
- f.write(msg)
-
- def read_line(f):
- return f.readline()
-
- def next(it):
- return it.next()
-
- import cgi
-
- def html_escape(s):
- return cgi.escape(s, True)
-
-try:
- from email.charset import Charset
- from email.utils import make_msgid
- from email.utils import getaddresses
- from email.utils import formataddr
- from email.utils import formatdate
- from email.header import Header
-except ImportError:
- # Prior to Python 2.5, the email module used different names:
- from email.Charset import Charset
- from email.Utils import make_msgid
- from email.Utils import getaddresses
- from email.Utils import formataddr
- from email.Utils import formatdate
- from email.Header import Header
-
-
-DEBUG = False
-
-ZEROS = '0' * 40
-LOGBEGIN = '- Log -----------------------------------------------------------------\n'
-LOGEND = '-----------------------------------------------------------------------\n'
-
-ADDR_HEADERS = set(['from', 'to', 'cc', 'bcc', 'reply-to', 'sender'])
-
-# It is assumed in many places that the encoding is uniformly UTF-8,
-# so changing these constants is unsupported. But define them here
-# anyway, to make it easier to find (at least most of) the places
-# where the encoding is important.
-(ENCODING, CHARSET) = ('UTF-8', 'utf-8')
-
-
-REF_CREATED_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s created'
- ' (now %(newrev_short)s)'
- )
-REF_UPDATED_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s updated'
- ' (%(oldrev_short)s -> %(newrev_short)s)'
- )
-REF_DELETED_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s deleted'
- ' (was %(oldrev_short)s)'
- )
-
-COMBINED_REFCHANGE_REVISION_SUBJECT_TEMPLATE = (
- '%(emailprefix)s%(refname_type)s %(short_refname)s updated: %(oneline)s'
- )
-
-REFCHANGE_HEADER_TEMPLATE = """\
-Date: %(send_date)s
-To: %(recipients)s
-Subject: %(subject)s
-MIME-Version: 1.0
-Content-Type: text/%(contenttype)s; charset=%(charset)s
-Content-Transfer-Encoding: 8bit
-Message-ID: %(msgid)s
-From: %(fromaddr)s
-Reply-To: %(reply_to)s
-Thread-Index: %(thread_index)s
-X-Git-Host: %(fqdn)s
-X-Git-Repo: %(repo_shortname)s
-X-Git-Refname: %(refname)s
-X-Git-Reftype: %(refname_type)s
-X-Git-Oldrev: %(oldrev)s
-X-Git-Newrev: %(newrev)s
-X-Git-NotificationType: ref_changed
-X-Git-Multimail-Version: %(multimail_version)s
-Auto-Submitted: auto-generated
-"""
-
-REFCHANGE_INTRO_TEMPLATE = """\
-This is an automated email from the git hooks/post-receive script.
-
-%(pusher)s pushed a change to %(refname_type)s %(short_refname)s
-in repository %(repo_shortname)s.
-
-"""
-
-
-FOOTER_TEMPLATE = """\
-
--- \n\
-To stop receiving notification emails like this one, please contact
-%(administrator)s.
-"""
-
-
-REWIND_ONLY_TEMPLATE = """\
-This update removed existing revisions from the reference, leaving the
-reference pointing at a previous point in the repository history.
-
- * -- * -- N %(refname)s (%(newrev_short)s)
- \\
- O -- O -- O (%(oldrev_short)s)
-
-Any revisions marked "omit" are not gone; other references still
-refer to them. Any revisions marked "discard" are gone forever.
-"""
-
-
-NON_FF_TEMPLATE = """\
-This update added new revisions after undoing existing revisions.
-That is to say, some revisions that were in the old version of the
-%(refname_type)s are not in the new version. This situation occurs
-when a user --force pushes a change and generates a repository
-containing something like this:
-
- * -- * -- B -- O -- O -- O (%(oldrev_short)s)
- \\
- N -- N -- N %(refname)s (%(newrev_short)s)
-
-You should already have received notification emails for all of the O
-revisions, and so the following emails describe only the N revisions
-from the common base, B.
-
-Any revisions marked "omit" are not gone; other references still
-refer to them. Any revisions marked "discard" are gone forever.
-"""
-
-
-NO_NEW_REVISIONS_TEMPLATE = """\
-No new revisions were added by this update.
-"""
-
-
-DISCARDED_REVISIONS_TEMPLATE = """\
-This change permanently discards the following revisions:
-"""
-
-
-NO_DISCARDED_REVISIONS_TEMPLATE = """\
-The revisions that were on this %(refname_type)s are still contained in
-other references; therefore, this change does not discard any commits
-from the repository.
-"""
-
-
-NEW_REVISIONS_TEMPLATE = """\
-The %(tot)s revisions listed above as "new" are entirely new to this
-repository and will be described in separate emails. The revisions
-listed as "add" were already present in the repository and have only
-been added to this reference.
-
-"""
-
-
-TAG_CREATED_TEMPLATE = """\
- at %(newrev_short)-8s (%(newrev_type)s)
-"""
-
-
-TAG_UPDATED_TEMPLATE = """\
-*** WARNING: tag %(short_refname)s was modified! ***
-
- from %(oldrev_short)-8s (%(oldrev_type)s)
- to %(newrev_short)-8s (%(newrev_type)s)
-"""
-
-
-TAG_DELETED_TEMPLATE = """\
-*** WARNING: tag %(short_refname)s was deleted! ***
-
-"""
-
-
-# The template used in summary tables. It looks best if this uses the
-# same alignment as TAG_CREATED_TEMPLATE and TAG_UPDATED_TEMPLATE.
-BRIEF_SUMMARY_TEMPLATE = """\
-%(action)8s %(rev_short)-8s %(text)s
-"""
-
-
-NON_COMMIT_UPDATE_TEMPLATE = """\
-This is an unusual reference change because the reference did not
-refer to a commit either before or after the change. We do not know
-how to provide full information about this reference change.
-"""
-
-
-REVISION_HEADER_TEMPLATE = """\
-Date: %(send_date)s
-To: %(recipients)s
-Cc: %(cc_recipients)s
-Subject: %(emailprefix)s%(num)02d/%(tot)02d: %(oneline)s
-MIME-Version: 1.0
-Content-Type: text/%(contenttype)s; charset=%(charset)s
-Content-Transfer-Encoding: 8bit
-From: %(fromaddr)s
-Reply-To: %(reply_to)s
-In-Reply-To: %(reply_to_msgid)s
-References: %(reply_to_msgid)s
-Thread-Index: %(thread_index)s
-X-Git-Host: %(fqdn)s
-X-Git-Repo: %(repo_shortname)s
-X-Git-Refname: %(refname)s
-X-Git-Reftype: %(refname_type)s
-X-Git-Rev: %(rev)s
-X-Git-NotificationType: diff
-X-Git-Multimail-Version: %(multimail_version)s
-Auto-Submitted: auto-generated
-"""
-
-REVISION_INTRO_TEMPLATE = """\
-This is an automated email from the git hooks/post-receive script.
-
-%(pusher)s pushed a commit to %(refname_type)s %(short_refname)s
-in repository %(repo_shortname)s.
-
-"""
-
-LINK_TEXT_TEMPLATE = """\
-View the commit online:
-%(browse_url)s
-
-"""
-
-LINK_HTML_TEMPLATE = """\
-<p><a href="%(browse_url)s">View the commit online</a>.</p>
-"""
-
-
-REVISION_FOOTER_TEMPLATE = FOOTER_TEMPLATE
-
-
-# Combined, meaning refchange+revision email (for single-commit additions)
-COMBINED_HEADER_TEMPLATE = """\
-Date: %(send_date)s
-To: %(recipients)s
-Subject: %(subject)s
-MIME-Version: 1.0
-Content-Type: text/%(contenttype)s; charset=%(charset)s
-Content-Transfer-Encoding: 8bit
-Message-ID: %(msgid)s
-From: %(fromaddr)s
-Reply-To: %(reply_to)s
-X-Git-Host: %(fqdn)s
-X-Git-Repo: %(repo_shortname)s
-X-Git-Refname: %(refname)s
-X-Git-Reftype: %(refname_type)s
-X-Git-Oldrev: %(oldrev)s
-X-Git-Newrev: %(newrev)s
-X-Git-Rev: %(rev)s
-X-Git-NotificationType: ref_changed_plus_diff
-X-Git-Multimail-Version: %(multimail_version)s
-Auto-Submitted: auto-generated
-"""
-
-COMBINED_INTRO_TEMPLATE = """\
-This is an automated email from the git hooks/post-receive script.
-
-%(pusher)s pushed a commit to %(refname_type)s %(short_refname)s
-in repository %(repo_shortname)s.
-
-"""
-
-COMBINED_FOOTER_TEMPLATE = FOOTER_TEMPLATE
-
-
-class CommandError(Exception):
- def __init__(self, cmd, retcode):
- self.cmd = cmd
- self.retcode = retcode
- Exception.__init__(
- self,
- 'Command "%s" failed with retcode %s' % (' '.join(cmd), retcode,)
- )
-
-
-class ConfigurationException(Exception):
- pass
-
-
-# The "git" program (this could be changed to include a full path):
-GIT_EXECUTABLE = 'git'
-
-
-# How "git" should be invoked (including global arguments), as a list
-# of words. This variable is usually initialized automatically by
-# read_git_output() via choose_git_command(), but if a value is set
-# here then it will be used unconditionally.
-GIT_CMD = None
-
-
-def choose_git_command():
- """Decide how to invoke git, and record the choice in GIT_CMD."""
-
- global GIT_CMD
-
- if GIT_CMD is None:
- try:
- # Check to see whether the "-c" option is accepted (it was
- # only added in Git 1.7.2). We don't actually use the
- # output of "git --version", though if we needed more
- # specific version information this would be the place to
- # do it.
- cmd = [GIT_EXECUTABLE, '-c', 'foo.bar=baz', '--version']
- read_output(cmd)
- GIT_CMD = [GIT_EXECUTABLE, '-c', 'i18n.logoutputencoding=%s' % (ENCODING,)]
- except CommandError:
- GIT_CMD = [GIT_EXECUTABLE]
-
-
-def read_git_output(args, input=None, keepends=False, **kw):
- """Read the output of a Git command."""
-
- if GIT_CMD is None:
- choose_git_command()
-
- return read_output(GIT_CMD + args, input=input, keepends=keepends, **kw)
-
-
-def read_output(cmd, input=None, keepends=False, **kw):
- if input:
- stdin = subprocess.PIPE
- input = str_to_bytes(input)
- else:
- stdin = None
- errors = 'strict'
- if 'errors' in kw:
- errors = kw['errors']
- del kw['errors']
- p = subprocess.Popen(
- tuple(str_to_bytes(w) for w in cmd),
- stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kw
- )
- (out, err) = p.communicate(input)
- out = bytes_to_str(out, errors=errors)
- retcode = p.wait()
- if retcode:
- raise CommandError(cmd, retcode)
- if not keepends:
- out = out.rstrip('\n\r')
- return out
-
-
-def read_git_lines(args, keepends=False, **kw):
- """Return the lines output by Git command.
-
- Return as single lines, with newlines stripped off."""
-
- return read_git_output(args, keepends=True, **kw).splitlines(keepends)
-
-
-def git_rev_list_ish(cmd, spec, args=None, **kw):
- """Common functionality for invoking a 'git rev-list'-like command.
-
- Parameters:
- * cmd is the Git command to run, e.g., 'rev-list' or 'log'.
- * spec is a list of revision arguments to pass to the named
- command. If None, this function returns an empty list.
- * args is a list of extra arguments passed to the named command.
- * All other keyword arguments (if any) are passed to the
- underlying read_git_lines() function.
-
- Return the output of the Git command in the form of a list, one
- entry per output line.
- """
- if spec is None:
- return []
- if args is None:
- args = []
- args = [cmd, '--stdin'] + args
- spec_stdin = ''.join(s + '\n' for s in spec)
- return read_git_lines(args, input=spec_stdin, **kw)
-
-
-def git_rev_list(spec, **kw):
- """Run 'git rev-list' with the given list of revision arguments.
-
- See git_rev_list_ish() for parameter and return value
- documentation.
- """
- return git_rev_list_ish('rev-list', spec, **kw)
-
-
-def git_log(spec, **kw):
- """Run 'git log' with the given list of revision arguments.
-
- See git_rev_list_ish() for parameter and return value
- documentation.
- """
- return git_rev_list_ish('log', spec, **kw)
-
-
-def header_encode(text, header_name=None):
- """Encode and line-wrap the value of an email header field."""
-
- # Convert to unicode, if required.
- if not isinstance(text, unicode):
- text = unicode(text, 'utf-8')
-
- if is_ascii(text):
- charset = 'ascii'
- else:
- charset = 'utf-8'
-
- return Header(text, header_name=header_name, charset=Charset(charset)).encode()
-
-
-def addr_header_encode(text, header_name=None):
- """Encode and line-wrap the value of an email header field containing
- email addresses."""
-
- # Convert to unicode, if required.
- if not isinstance(text, unicode):
- text = unicode(text, 'utf-8')
-
- text = ', '.join(
- formataddr((header_encode(name), emailaddr))
- for name, emailaddr in getaddresses([text])
- )
-
- if is_ascii(text):
- charset = 'ascii'
- else:
- charset = 'utf-8'
-
- return Header(text, header_name=header_name, charset=Charset(charset)).encode()
-
-
-class Config(object):
- def __init__(self, section, git_config=None):
- """Represent a section of the git configuration.
-
- If git_config is specified, it is passed to "git config" in
- the GIT_CONFIG environment variable, meaning that "git config"
- will read the specified path rather than the Git default
- config paths."""
-
- self.section = section
- if git_config:
- self.env = os.environ.copy()
- self.env['GIT_CONFIG'] = git_config
- else:
- self.env = None
-
- @staticmethod
- def _split(s):
- """Split NUL-terminated values."""
-
- words = s.split('\0')
- assert words[-1] == ''
- return words[:-1]
-
- @staticmethod
- def add_config_parameters(c):
- """Add configuration parameters to Git.
-
- c is either an str or a list of str, each element being of the
- form 'var=val' or 'var', with the same syntax and meaning as
- the argument of 'git -c var=val'.
- """
- if isinstance(c, str):
- c = (c,)
- parameters = os.environ.get('GIT_CONFIG_PARAMETERS', '')
- if parameters:
- parameters += ' '
- # git expects GIT_CONFIG_PARAMETERS to be of the form
- # "'name1=value1' 'name2=value2' 'name3=value3'"
- # including everything inside the double quotes (but not the double
- # quotes themselves). Spacing is critical. Also, if a value contains
- # a literal single quote that quote must be represented using the
- # four character sequence: '\''
- parameters += ' '.join("'" + x.replace("'", "'\\''") + "'" for x in c)
- os.environ['GIT_CONFIG_PARAMETERS'] = parameters
-
- def get(self, name, default=None):
- try:
- values = self._split(read_git_output(
- ['config', '--get', '--null', '%s.%s' % (self.section, name)],
- env=self.env, keepends=True,
- ))
- assert len(values) == 1
- return values[0]
- except CommandError:
- return default
-
- def get_bool(self, name, default=None):
- try:
- value = read_git_output(
- ['config', '--get', '--bool', '%s.%s' % (self.section, name)],
- env=self.env,
- )
- except CommandError:
- return default
- return value == 'true'
-
- def get_all(self, name, default=None):
- """Read a (possibly multivalued) setting from the configuration.
-
- Return the result as a list of values, or default if the name
- is unset."""
-
- try:
- return self._split(read_git_output(
- ['config', '--get-all', '--null', '%s.%s' % (self.section, name)],
- env=self.env, keepends=True,
- ))
- except CommandError:
- t, e, traceback = sys.exc_info()
- if e.retcode == 1:
- # "the section or key is invalid"; i.e., there is no
- # value for the specified key.
- return default
- else:
- raise
-
- def set(self, name, value):
- read_git_output(
- ['config', '%s.%s' % (self.section, name), value],
- env=self.env,
- )
-
- def add(self, name, value):
- read_git_output(
- ['config', '--add', '%s.%s' % (self.section, name), value],
- env=self.env,
- )
-
- def __contains__(self, name):
- return self.get_all(name, default=None) is not None
-
- # We don't use this method anymore internally, but keep it here in
- # case somebody is calling it from their own code:
- def has_key(self, name):
- return name in self
-
- def unset_all(self, name):
- try:
- read_git_output(
- ['config', '--unset-all', '%s.%s' % (self.section, name)],
- env=self.env,
- )
- except CommandError:
- t, e, traceback = sys.exc_info()
- if e.retcode == 5:
- # The name doesn't exist, which is what we wanted anyway...
- pass
- else:
- raise
-
- def set_recipients(self, name, value):
- self.unset_all(name)
- for pair in getaddresses([value]):
- self.add(name, formataddr(pair))
-
-
-def generate_summaries(*log_args):
- """Generate a brief summary for each revision requested.
-
- log_args are strings that will be passed directly to "git log" as
- revision selectors. Iterate over (sha1_short, subject) for each
- commit specified by log_args (subject is the first line of the
- commit message as a string without EOLs)."""
-
- cmd = [
- 'log', '--abbrev', '--format=%h %s',
- ] + list(log_args) + ['--']
- for line in read_git_lines(cmd):
- yield tuple(line.split(' ', 1))
-
-
-def limit_lines(lines, max_lines):
- for (index, line) in enumerate(lines):
- if index < max_lines:
- yield line
-
- if index >= max_lines:
- yield '... %d lines suppressed ...\n' % (index + 1 - max_lines,)
-
-
-def limit_linelength(lines, max_linelength):
- for line in lines:
- # Don't forget that lines always include a trailing newline.
- if len(line) > max_linelength + 1:
- line = line[:max_linelength - 7] + ' [...]\n'
- yield line
-
-
-class CommitSet(object):
- """A (constant) set of object names.
-
- The set should be initialized with full SHA1 object names. The
- __contains__() method returns True iff its argument is an
- abbreviation of any the names in the set."""
-
- def __init__(self, names):
- self._names = sorted(names)
-
- def __len__(self):
- return len(self._names)
-
- def __contains__(self, sha1_abbrev):
- """Return True iff this set contains sha1_abbrev (which might be abbreviated)."""
-
- i = bisect.bisect_left(self._names, sha1_abbrev)
- return i < len(self) and self._names[i].startswith(sha1_abbrev)
-
-
-class GitObject(object):
- def __init__(self, sha1, type=None):
- if sha1 == ZEROS:
- self.sha1 = self.type = self.commit_sha1 = None
- else:
- self.sha1 = sha1
- self.type = type or read_git_output(['cat-file', '-t', self.sha1])
-
- if self.type == 'commit':
- self.commit_sha1 = self.sha1
- elif self.type == 'tag':
- try:
- self.commit_sha1 = read_git_output(
- ['rev-parse', '--verify', '%s^0' % (self.sha1,)]
- )
- except CommandError:
- # Cannot deref tag to determine commit_sha1
- self.commit_sha1 = None
- else:
- self.commit_sha1 = None
-
- self.short = read_git_output(['rev-parse', '--short', sha1])
-
- def get_summary(self):
- """Return (sha1_short, subject) for this commit."""
-
- if not self.sha1:
- raise ValueError('Empty commit has no summary')
-
- return next(iter(generate_summaries('--no-walk', self.sha1)))
-
- def __eq__(self, other):
- return isinstance(other, GitObject) and self.sha1 == other.sha1
-
- def __ne__(self, other):
- return not self == other
-
- def __hash__(self):
- return hash(self.sha1)
-
- def __nonzero__(self):
- return bool(self.sha1)
-
- def __bool__(self):
- """Python 2 backward compatibility"""
- return self.__nonzero__()
-
- def __str__(self):
- return self.sha1 or ZEROS
-
-
-class Change(object):
- """A Change that has been made to the Git repository.
-
- Abstract class from which both Revisions and ReferenceChanges are
- derived. A Change knows how to generate a notification email
- describing itself."""
-
- def __init__(self, environment):
- self.environment = environment
- self._values = None
- self._contains_html_diff = False
-
- def _contains_diff(self):
- # We do contain a diff, should it be rendered in HTML?
- if self.environment.commit_email_format == "html":
- self._contains_html_diff = True
-
- def _compute_values(self):
- """Return a dictionary {keyword: expansion} for this Change.
-
- Derived classes overload this method to add more entries to
- the return value. This method is used internally by
- get_values(). The return value should always be a new
- dictionary."""
-
- values = self.environment.get_values()
- fromaddr = self.environment.get_fromaddr(change=self)
- if fromaddr is not None:
- values['fromaddr'] = fromaddr
- values['multimail_version'] = get_version()
- return values
-
- # Aliases usable in template strings. Tuple of pairs (destination,
- # source).
- VALUES_ALIAS = (
- ("id", "newrev"),
- )
-
- def get_values(self, **extra_values):
- """Return a dictionary {keyword: expansion} for this Change.
-
- Return a dictionary mapping keywords to the values that they
- should be expanded to for this Change (used when interpolating
- template strings). If any keyword arguments are supplied, add
- those to the return value as well. The return value is always
- a new dictionary."""
-
- if self._values is None:
- self._values = self._compute_values()
-
- values = self._values.copy()
- if extra_values:
- values.update(extra_values)
-
- for alias, val in self.VALUES_ALIAS:
- values[alias] = values[val]
- return values
-
- def expand(self, template, **extra_values):
- """Expand template.
-
- Expand the template (which should be a string) using string
- interpolation of the values for this Change. If any keyword
- arguments are provided, also include those in the keywords
- available for interpolation."""
-
- return template % self.get_values(**extra_values)
-
- def expand_lines(self, template, html_escape_val=False, **extra_values):
- """Break template into lines and expand each line."""
-
- values = self.get_values(**extra_values)
- if html_escape_val:
- for k in values:
- if is_string(values[k]):
- values[k] = html_escape(values[k])
- for line in template.splitlines(True):
- yield line % values
-
- def expand_header_lines(self, template, **extra_values):
- """Break template into lines and expand each line as an RFC 2822 header.
-
- Encode values and split up lines that are too long. Silently
- skip lines that contain references to unknown variables."""
-
- values = self.get_values(**extra_values)
- if self._contains_html_diff:
- self._content_type = 'html'
- else:
- self._content_type = 'plain'
- values['contenttype'] = self._content_type
-
- for line in template.splitlines():
- (name, value) = line.split(': ', 1)
-
- try:
- value = value % values
- except KeyError:
- t, e, traceback = sys.exc_info()
- if DEBUG:
- self.environment.log_warning(
- 'Warning: unknown variable %r in the following line; line skipped:\n'
- ' %s\n'
- % (e.args[0], line,)
- )
- else:
- if name.lower() in ADDR_HEADERS:
- value = addr_header_encode(value, name)
- else:
- value = header_encode(value, name)
- for splitline in ('%s: %s\n' % (name, value)).splitlines(True):
- yield splitline
-
- def generate_email_header(self):
- """Generate the RFC 2822 email headers for this Change, a line at a time.
-
- The output should not include the trailing blank line."""
-
- raise NotImplementedError()
-
- def generate_browse_link(self, base_url):
- """Generate a link to an online repository browser."""
- return iter(())
-
- def generate_email_intro(self, html_escape_val=False):
- """Generate the email intro for this Change, a line at a time.
-
- The output will be used as the standard boilerplate at the top
- of the email body."""
-
- raise NotImplementedError()
-
- def generate_email_body(self, push):
- """Generate the main part of the email body, a line at a time.
-
- The text in the body might be truncated after a specified
- number of lines (see multimailhook.emailmaxlines)."""
-
- raise NotImplementedError()
-
- def generate_email_footer(self, html_escape_val):
- """Generate the footer of the email, a line at a time.
-
- The footer is always included, irrespective of
- multimailhook.emailmaxlines."""
-
- raise NotImplementedError()
-
- def _wrap_for_html(self, lines):
- """Wrap the lines in HTML <pre> tag when using HTML format.
-
- Escape special HTML characters and add <pre> and </pre> tags around
- the given lines if we should be generating HTML as indicated by
- self._contains_html_diff being set to true.
- """
- if self._contains_html_diff:
- yield "<pre style='margin:0'>\n"
-
- for line in lines:
- yield html_escape(line)
-
- yield '</pre>\n'
- else:
- for line in lines:
- yield line
-
- def generate_email(self, push, body_filter=None, extra_header_values={}):
- """Generate an email describing this change.
-
- Iterate over the lines (including the header lines) of an
- email describing this change. If body_filter is not None,
- then use it to filter the lines that are intended for the
- email body.
-
- The extra_header_values field is received as a dict and not as
- **kwargs, to allow passing other keyword arguments in the
- future (e.g. passing extra values to generate_email_intro()"""
-
- for line in self.generate_email_header(**extra_header_values):
- yield line
- yield '\n'
- html_escape_val = (self.environment.html_in_intro and
- self._contains_html_diff)
- intro = self.generate_email_intro(html_escape_val)
- if not self.environment.html_in_intro:
- intro = self._wrap_for_html(intro)
- for line in intro:
- yield line
-
- if self.environment.commitBrowseURL:
- for line in self.generate_browse_link(self.environment.commitBrowseURL):
- yield line
-
- body = self.generate_email_body(push)
- if body_filter is not None:
- body = body_filter(body)
-
- diff_started = False
- if self._contains_html_diff:
- # "white-space: pre" is the default, but we need to
- # specify it again in case the message is viewed in a
- # webmail which wraps it in an element setting white-space
- # to something else (Zimbra does this and sets
- # white-space: pre-line).
- yield '<pre style="white-space: pre; background: #F8F8F8">'
- for line in body:
- if self._contains_html_diff:
- # This is very, very naive. It would be much better to really
- # parse the diff, i.e. look at how many lines do we have in
- # the hunk headers instead of blindly highlighting everything
- # that looks like it might be part of a diff.
- bgcolor = ''
- fgcolor = ''
- if line.startswith('--- a/'):
- diff_started = True
- bgcolor = 'e0e0ff'
- elif line.startswith('diff ') or line.startswith('index '):
- diff_started = True
- fgcolor = '808080'
- elif diff_started:
- if line.startswith('+++ '):
- bgcolor = 'e0e0ff'
- elif line.startswith('@@'):
- bgcolor = 'e0e0e0'
- elif line.startswith('+'):
- bgcolor = 'e0ffe0'
- elif line.startswith('-'):
- bgcolor = 'ffe0e0'
- elif line.startswith('commit '):
- fgcolor = '808000'
- elif line.startswith(' '):
- fgcolor = '404040'
-
- # Chop the trailing LF, we don't want it inside <pre>.
- line = html_escape(line[:-1])
-
- if bgcolor or fgcolor:
- style = 'display:block; white-space:pre;'
- if bgcolor:
- style += 'background:#' + bgcolor + ';'
- if fgcolor:
- style += 'color:#' + fgcolor + ';'
- # Use a <span style='display:block> to color the
- # whole line. The newline must be inside the span
- # to display properly both in Firefox and in
- # text-based browser.
- line = "<span style='%s'>%s\n</span>" % (style, line)
- else:
- line = line + '\n'
-
- yield line
- if self._contains_html_diff:
- yield '</pre>'
- html_escape_val = (self.environment.html_in_footer and
- self._contains_html_diff)
- footer = self.generate_email_footer(html_escape_val)
- if not self.environment.html_in_footer:
- footer = self._wrap_for_html(footer)
- for line in footer:
- yield line
-
- def get_specific_fromaddr(self):
- """For kinds of Changes which specify it, return the kind-specific
- From address to use."""
- return None
-
-
-class Revision(Change):
- """A Change consisting of a single git commit."""
-
- CC_RE = re.compile(r'^\s*C[Cc]:\s*(?P<to>[^#]+@[^\s#]*)\s*(#.*)?$')
-
- def __init__(self, reference_change, rev, num, tot):
- Change.__init__(self, reference_change.environment)
- self.reference_change = reference_change
- self.rev = rev
- self.change_type = self.reference_change.change_type
- self.refname = self.reference_change.refname
- self.num = num
- self.tot = tot
- self.author = read_git_output(['log', '--no-walk', '--format=%aN <%aE>', self.rev.sha1])
- self.recipients = self.environment.get_revision_recipients(self)
-
- # -s is short for --no-patch, but -s works on older git's (e.g. 1.7)
- self.parents = read_git_lines(['show', '-s', '--format=%P',
- self.rev.sha1])[0].split()
-
- self.cc_recipients = ''
- if self.environment.get_scancommitforcc():
- self.cc_recipients = ', '.join(to.strip() for to in self._cc_recipients())
- if self.cc_recipients:
- self.environment.log_msg(
- 'Add %s to CC for %s' % (self.cc_recipients, self.rev.sha1))
-
- def _cc_recipients(self):
- cc_recipients = []
- message = read_git_output(['log', '--no-walk', '--format=%b', self.rev.sha1])
- lines = message.strip().split('\n')
- for line in lines:
- m = re.match(self.CC_RE, line)
- if m:
- cc_recipients.append(m.group('to'))
-
- return cc_recipients
-
- def _compute_values(self):
- values = Change._compute_values(self)
-
- oneline = read_git_output(
- ['log', '--format=%s', '--no-walk', self.rev.sha1]
- )
-
- max_subject_length = self.environment.get_max_subject_length()
- if max_subject_length > 0 and len(oneline) > max_subject_length:
- oneline = oneline[:max_subject_length - 6] + ' [...]'
-
- values['rev'] = self.rev.sha1
- values['parents'] = ' '.join(self.parents)
- values['rev_short'] = self.rev.short
- values['change_type'] = self.change_type
- values['refname'] = self.refname
- values['newrev'] = self.rev.sha1
- values['short_refname'] = self.reference_change.short_refname
- values['refname_type'] = self.reference_change.refname_type
- values['reply_to_msgid'] = self.reference_change.msgid
- values['thread_index'] = self.reference_change.thread_index
- values['num'] = self.num
- values['tot'] = self.tot
- values['recipients'] = self.recipients
- if self.cc_recipients:
- values['cc_recipients'] = self.cc_recipients
- values['oneline'] = oneline
- values['author'] = self.author
-
- reply_to = self.environment.get_reply_to_commit(self)
- if reply_to:
- values['reply_to'] = reply_to
-
- return values
-
- def generate_email_header(self, **extra_values):
- for line in self.expand_header_lines(
- REVISION_HEADER_TEMPLATE, **extra_values
- ):
- yield line
-
- def generate_browse_link(self, base_url):
- if '%(' not in base_url:
- base_url += '%(id)s'
- url = "".join(self.expand_lines(base_url))
- if self._content_type == 'html':
- for line in self.expand_lines(LINK_HTML_TEMPLATE,
- html_escape_val=True,
- browse_url=url):
- yield line
- elif self._content_type == 'plain':
- for line in self.expand_lines(LINK_TEXT_TEMPLATE,
- html_escape_val=False,
- browse_url=url):
- yield line
- else:
- raise NotImplementedError("Content-type %s unsupported. Please report it as a bug.")
-
- def generate_email_intro(self, html_escape_val=False):
- for line in self.expand_lines(REVISION_INTRO_TEMPLATE,
- html_escape_val=html_escape_val):
- yield line
-
- def generate_email_body(self, push):
- """Show this revision."""
-
- for line in read_git_lines(
- ['log'] + self.environment.commitlogopts + ['-1', self.rev.sha1],
- keepends=True,
- errors='replace'):
- if line.startswith('Date: ') and self.environment.date_substitute:
- yield self.environment.date_substitute + line[len('Date: '):]
- else:
- yield line
-
- def generate_email_footer(self, html_escape_val):
- return self.expand_lines(REVISION_FOOTER_TEMPLATE,
- html_escape_val=html_escape_val)
-
- def generate_email(self, push, body_filter=None, extra_header_values={}):
- self._contains_diff()
- return Change.generate_email(self, push, body_filter, extra_header_values)
-
- def get_specific_fromaddr(self):
- return self.environment.from_commit
-
-
-class ReferenceChange(Change):
- """A Change to a Git reference.
-
- An abstract class representing a create, update, or delete of a
- Git reference. Derived classes handle specific types of reference
- (e.g., tags vs. branches). These classes generate the main
- reference change email summarizing the reference change and
- whether it caused any any commits to be added or removed.
-
- ReferenceChange objects are usually created using the static
- create() method, which has the logic to decide which derived class
- to instantiate."""
-
- REF_RE = re.compile(r'^refs\/(?P<area>[^\/]+)\/(?P<shortname>.*)$')
-
- @staticmethod
- def create(environment, oldrev, newrev, refname):
- """Return a ReferenceChange object representing the change.
-
- Return an object that represents the type of change that is being
- made. oldrev and newrev should be SHA1s or ZEROS."""
-
- old = GitObject(oldrev)
- new = GitObject(newrev)
- rev = new or old
-
- # The revision type tells us what type the commit is, combined with
- # the location of the ref we can decide between
- # - working branch
- # - tracking branch
- # - unannotated tag
- # - annotated tag
- m = ReferenceChange.REF_RE.match(refname)
- if m:
- area = m.group('area')
- short_refname = m.group('shortname')
- else:
- area = ''
- short_refname = refname
-
- if rev.type == 'tag':
- # Annotated tag:
- klass = AnnotatedTagChange
- elif rev.type == 'commit':
- if area == 'tags':
- # Non-annotated tag:
- klass = NonAnnotatedTagChange
- elif area == 'heads':
- # Branch:
- klass = BranchChange
- elif area == 'remotes':
- # Tracking branch:
- environment.log_warning(
- '*** Push-update of tracking branch %r\n'
- '*** - incomplete email generated.'
- % (refname,)
- )
- klass = OtherReferenceChange
- else:
- # Some other reference namespace:
- environment.log_warning(
- '*** Push-update of strange reference %r\n'
- '*** - incomplete email generated.'
- % (refname,)
- )
- klass = OtherReferenceChange
- else:
- # Anything else (is there anything else?)
- environment.log_warning(
- '*** Unknown type of update to %r (%s)\n'
- '*** - incomplete email generated.'
- % (refname, rev.type,)
- )
- klass = OtherReferenceChange
-
- return klass(
- environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
-
- @staticmethod
- def make_thread_index():
- """Return a string appropriate for the Thread-Index header,
- needed by MS Outlook to get threading right.
-
- The format is (base64-encoded):
- - 1 byte must be 1
- - 5 bytes encode a date (hardcoded here)
- - 16 bytes for a globally unique identifier
-
- FIXME: Unfortunately, even with the Thread-Index field, MS
- Outlook doesn't seem to do the threading reliably (see
- https://github.com/git-multimail/git-multimail/pull/194).
- """
- thread_index = b'\x01\x00\x00\x12\x34\x56' + uuid.uuid4().bytes
- return base64.standard_b64encode(thread_index).decode('ascii')
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- Change.__init__(self, environment)
- self.change_type = {
- (False, True): 'create',
- (True, True): 'update',
- (True, False): 'delete',
- }[bool(old), bool(new)]
- self.refname = refname
- self.short_refname = short_refname
- self.old = old
- self.new = new
- self.rev = rev
- self.msgid = make_msgid()
- self.thread_index = self.make_thread_index()
- self.diffopts = environment.diffopts
- self.graphopts = environment.graphopts
- self.logopts = environment.logopts
- self.commitlogopts = environment.commitlogopts
- self.showgraph = environment.refchange_showgraph
- self.showlog = environment.refchange_showlog
-
- self.header_template = REFCHANGE_HEADER_TEMPLATE
- self.intro_template = REFCHANGE_INTRO_TEMPLATE
- self.footer_template = FOOTER_TEMPLATE
-
- def _compute_values(self):
- values = Change._compute_values(self)
-
- values['change_type'] = self.change_type
- values['refname_type'] = self.refname_type
- values['refname'] = self.refname
- values['short_refname'] = self.short_refname
- values['msgid'] = self.msgid
- values['thread_index'] = self.thread_index
- values['recipients'] = self.recipients
- values['oldrev'] = str(self.old)
- values['oldrev_short'] = self.old.short
- values['newrev'] = str(self.new)
- values['newrev_short'] = self.new.short
-
- if self.old:
- values['oldrev_type'] = self.old.type
- if self.new:
- values['newrev_type'] = self.new.type
-
- reply_to = self.environment.get_reply_to_refchange(self)
- if reply_to:
- values['reply_to'] = reply_to
-
- return values
-
- def send_single_combined_email(self, known_added_sha1s):
- """Determine if a combined refchange/revision email should be sent
-
- If there is only a single new (non-merge) commit added by a
- change, it is useful to combine the ReferenceChange and
- Revision emails into one. In such a case, return the single
- revision; otherwise, return None.
-
- This method is overridden in BranchChange."""
-
- return None
-
- def generate_combined_email(self, push, revision, body_filter=None, extra_header_values={}):
- """Generate an email describing this change AND specified revision.
-
- Iterate over the lines (including the header lines) of an
- email describing this change. If body_filter is not None,
- then use it to filter the lines that are intended for the
- email body.
-
- The extra_header_values field is received as a dict and not as
- **kwargs, to allow passing other keyword arguments in the
- future (e.g. passing extra values to generate_email_intro()
-
- This method is overridden in BranchChange."""
-
- raise NotImplementedError
-
- def get_subject(self):
- template = {
- 'create': REF_CREATED_SUBJECT_TEMPLATE,
- 'update': REF_UPDATED_SUBJECT_TEMPLATE,
- 'delete': REF_DELETED_SUBJECT_TEMPLATE,
- }[self.change_type]
- return self.expand(template)
-
- def generate_email_header(self, **extra_values):
- if 'subject' not in extra_values:
- extra_values['subject'] = self.get_subject()
-
- for line in self.expand_header_lines(
- self.header_template, **extra_values
- ):
- yield line
-
- def generate_email_intro(self, html_escape_val=False):
- for line in self.expand_lines(self.intro_template,
- html_escape_val=html_escape_val):
- yield line
-
- def generate_email_body(self, push):
- """Call the appropriate body-generation routine.
-
- Call one of generate_create_summary() /
- generate_update_summary() / generate_delete_summary()."""
-
- change_summary = {
- 'create': self.generate_create_summary,
- 'delete': self.generate_delete_summary,
- 'update': self.generate_update_summary,
- }[self.change_type](push)
- for line in change_summary:
- yield line
-
- for line in self.generate_revision_change_summary(push):
- yield line
-
- def generate_email_footer(self, html_escape_val):
- return self.expand_lines(self.footer_template,
- html_escape_val=html_escape_val)
-
- def generate_revision_change_graph(self, push):
- if self.showgraph:
- args = ['--graph'] + self.graphopts
- for newold in ('new', 'old'):
- has_newold = False
- spec = push.get_commits_spec(newold, self)
- for line in git_log(spec, args=args, keepends=True):
- if not has_newold:
- has_newold = True
- yield '\n'
- yield 'Graph of %s commits:\n\n' % (
- {'new': 'new', 'old': 'discarded'}[newold],)
- yield ' ' + line
- if has_newold:
- yield '\n'
-
- def generate_revision_change_log(self, new_commits_list):
- if self.showlog:
- yield '\n'
- yield 'Detailed log of new commits:\n\n'
- for line in read_git_lines(
- ['log', '--no-walk'] +
- self.logopts +
- new_commits_list +
- ['--'],
- keepends=True,
- ):
- yield line
-
- def generate_new_revision_summary(self, tot, new_commits_list, push):
- for line in self.expand_lines(NEW_REVISIONS_TEMPLATE, tot=tot):
- yield line
- for line in self.generate_revision_change_graph(push):
- yield line
- for line in self.generate_revision_change_log(new_commits_list):
- yield line
-
- def generate_revision_change_summary(self, push):
- """Generate a summary of the revisions added/removed by this change."""
-
- if self.new.commit_sha1 and not self.old.commit_sha1:
- # A new reference was created. List the new revisions
- # brought by the new reference (i.e., those revisions that
- # were not in the repository before this reference
- # change).
- sha1s = list(push.get_new_commits(self))
- sha1s.reverse()
- tot = len(sha1s)
- new_revisions = [
- Revision(self, GitObject(sha1), num=i + 1, tot=tot)
- for (i, sha1) in enumerate(sha1s)
- ]
-
- if new_revisions:
- yield self.expand('This %(refname_type)s includes the following new commits:\n')
- yield '\n'
- for r in new_revisions:
- (sha1, subject) = r.rev.get_summary()
- yield r.expand(
- BRIEF_SUMMARY_TEMPLATE, action='new', text=subject,
- )
- yield '\n'
- for line in self.generate_new_revision_summary(
- tot, [r.rev.sha1 for r in new_revisions], push):
- yield line
- else:
- for line in self.expand_lines(NO_NEW_REVISIONS_TEMPLATE):
- yield line
-
- elif self.new.commit_sha1 and self.old.commit_sha1:
- # A reference was changed to point at a different commit.
- # List the revisions that were removed and/or added *from
- # that reference* by this reference change, along with a
- # diff between the trees for its old and new values.
-
- # List of the revisions that were added to the branch by
- # this update. Note this list can include revisions that
- # have already had notification emails; we want such
- # revisions in the summary even though we will not send
- # new notification emails for them.
- adds = list(generate_summaries(
- '--topo-order', '--reverse', '%s..%s'
- % (self.old.commit_sha1, self.new.commit_sha1,)
- ))
-
- # List of the revisions that were removed from the branch
- # by this update. This will be empty except for
- # non-fast-forward updates.
- discards = list(generate_summaries(
- '%s..%s' % (self.new.commit_sha1, self.old.commit_sha1,)
- ))
-
- if adds:
- new_commits_list = push.get_new_commits(self)
- else:
- new_commits_list = []
- new_commits = CommitSet(new_commits_list)
-
- if discards:
- discarded_commits = CommitSet(push.get_discarded_commits(self))
- else:
- discarded_commits = CommitSet([])
-
- if discards and adds:
- for (sha1, subject) in discards:
- if sha1 in discarded_commits:
- action = 'discard'
- else:
- action = 'omit'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
- for (sha1, subject) in adds:
- if sha1 in new_commits:
- action = 'new'
- else:
- action = 'add'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
- yield '\n'
- for line in self.expand_lines(NON_FF_TEMPLATE):
- yield line
-
- elif discards:
- for (sha1, subject) in discards:
- if sha1 in discarded_commits:
- action = 'discard'
- else:
- action = 'omit'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
- yield '\n'
- for line in self.expand_lines(REWIND_ONLY_TEMPLATE):
- yield line
-
- elif adds:
- (sha1, subject) = self.old.get_summary()
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='from',
- rev_short=sha1, text=subject,
- )
- for (sha1, subject) in adds:
- if sha1 in new_commits:
- action = 'new'
- else:
- action = 'add'
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action=action,
- rev_short=sha1, text=subject,
- )
-
- yield '\n'
-
- if new_commits:
- for line in self.generate_new_revision_summary(
- len(new_commits), new_commits_list, push):
- yield line
- else:
- for line in self.expand_lines(NO_NEW_REVISIONS_TEMPLATE):
- yield line
- for line in self.generate_revision_change_graph(push):
- yield line
-
- # The diffstat is shown from the old revision to the new
- # revision. This is to show the truth of what happened in
- # this change. There's no point showing the stat from the
- # base to the new revision because the base is effectively a
- # random revision at this point - the user will be interested
- # in what this revision changed - including the undoing of
- # previous revisions in the case of non-fast-forward updates.
- yield '\n'
- yield 'Summary of changes:\n'
- for line in read_git_lines(
- ['diff-tree'] +
- self.diffopts +
- ['%s..%s' % (self.old.commit_sha1, self.new.commit_sha1,)],
- keepends=True,
- ):
- yield line
-
- elif self.old.commit_sha1 and not self.new.commit_sha1:
- # A reference was deleted. List the revisions that were
- # removed from the repository by this reference change.
-
- sha1s = list(push.get_discarded_commits(self))
- tot = len(sha1s)
- discarded_revisions = [
- Revision(self, GitObject(sha1), num=i + 1, tot=tot)
- for (i, sha1) in enumerate(sha1s)
- ]
-
- if discarded_revisions:
- for line in self.expand_lines(DISCARDED_REVISIONS_TEMPLATE):
- yield line
- yield '\n'
- for r in discarded_revisions:
- (sha1, subject) = r.rev.get_summary()
- yield r.expand(
- BRIEF_SUMMARY_TEMPLATE, action='discard', text=subject,
- )
- for line in self.generate_revision_change_graph(push):
- yield line
- else:
- for line in self.expand_lines(NO_DISCARDED_REVISIONS_TEMPLATE):
- yield line
-
- elif not self.old.commit_sha1 and not self.new.commit_sha1:
- for line in self.expand_lines(NON_COMMIT_UPDATE_TEMPLATE):
- yield line
-
- def generate_create_summary(self, push):
- """Called for the creation of a reference."""
-
- # This is a new reference and so oldrev is not valid
- (sha1, subject) = self.new.get_summary()
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='at',
- rev_short=sha1, text=subject,
- )
- yield '\n'
-
- def generate_update_summary(self, push):
- """Called for the change of a pre-existing branch."""
-
- return iter([])
-
- def generate_delete_summary(self, push):
- """Called for the deletion of any type of reference."""
-
- (sha1, subject) = self.old.get_summary()
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='was',
- rev_short=sha1, text=subject,
- )
- yield '\n'
-
- def get_specific_fromaddr(self):
- return self.environment.from_refchange
-
-
-class BranchChange(ReferenceChange):
- refname_type = 'branch'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_refchange_recipients(self)
- self._single_revision = None
-
- def send_single_combined_email(self, known_added_sha1s):
- if not self.environment.combine_when_single_commit:
- return None
-
- # In the sadly-all-too-frequent usecase of people pushing only
- # one of their commits at a time to a repository, users feel
- # the reference change summary emails are noise rather than
- # important signal. This is because, in this particular
- # usecase, there is a reference change summary email for each
- # new commit, and all these summaries do is point out that
- # there is one new commit (which can readily be inferred by
- # the existence of the individual revision email that is also
- # sent). In such cases, our users prefer there to be a combined
- # reference change summary/new revision email.
- #
- # So, if the change is an update and it doesn't discard any
- # commits, and it adds exactly one non-merge commit (gerrit
- # forces a workflow where every commit is individually merged
- # and the git-multimail hook fired off for just this one
- # change), then we send a combined refchange/revision email.
- try:
- # If this change is a reference update that doesn't discard
- # any commits...
- if self.change_type != 'update':
- return None
-
- if read_git_lines(
- ['merge-base', self.old.sha1, self.new.sha1]
- ) != [self.old.sha1]:
- return None
-
- # Check if this update introduced exactly one non-merge
- # commit:
-
- def split_line(line):
- """Split line into (sha1, [parent,...])."""
-
- words = line.split()
- return (words[0], words[1:])
-
- # Get the new commits introduced by the push as a list of
- # (sha1, [parent,...])
- new_commits = [
- split_line(line)
- for line in read_git_lines(
- [
- 'log', '-3', '--format=%H %P',
- '%s..%s' % (self.old.sha1, self.new.sha1),
- ]
- )
- ]
-
- if not new_commits:
- return None
-
- # If the newest commit is a merge, save it for a later check
- # but otherwise ignore it
- merge = None
- tot = len(new_commits)
- if len(new_commits[0][1]) > 1:
- merge = new_commits[0][0]
- del new_commits[0]
-
- # Our primary check: we can't combine if more than one commit
- # is introduced. We also currently only combine if the new
- # commit is a non-merge commit, though it may make sense to
- # combine if it is a merge as well.
- if not (
- len(new_commits) == 1 and
- len(new_commits[0][1]) == 1 and
- new_commits[0][0] in known_added_sha1s
- ):
- return None
-
- # We do not want to combine revision and refchange emails if
- # those go to separate locations.
- rev = Revision(self, GitObject(new_commits[0][0]), 1, tot)
- if rev.recipients != self.recipients:
- return None
-
- # We ignored the newest commit if it was just a merge of the one
- # commit being introduced. But we don't want to ignore that
- # merge commit it it involved conflict resolutions. Check that.
- if merge and merge != read_git_output(['diff-tree', '--cc', merge]):
- return None
-
- # We can combine the refchange and one new revision emails
- # into one. Return the Revision that a combined email should
- # be sent about.
- return rev
- except CommandError:
- # Cannot determine number of commits in old..new or new..old;
- # don't combine reference/revision emails:
- return None
-
- def generate_combined_email(self, push, revision, body_filter=None, extra_header_values={}):
- values = revision.get_values()
- if extra_header_values:
- values.update(extra_header_values)
- if 'subject' not in extra_header_values:
- values['subject'] = self.expand(COMBINED_REFCHANGE_REVISION_SUBJECT_TEMPLATE, **values)
-
- self._single_revision = revision
- self._contains_diff()
- self.header_template = COMBINED_HEADER_TEMPLATE
- self.intro_template = COMBINED_INTRO_TEMPLATE
- self.footer_template = COMBINED_FOOTER_TEMPLATE
-
- def revision_gen_link(base_url):
- # revision is used only to generate the body, and
- # _content_type is set while generating headers. Get it
- # from the BranchChange object.
- revision._content_type = self._content_type
- return revision.generate_browse_link(base_url)
- self.generate_browse_link = revision_gen_link
- for line in self.generate_email(push, body_filter, values):
- yield line
-
- def generate_email_body(self, push):
- '''Call the appropriate body generation routine.
-
- If this is a combined refchange/revision email, the special logic
- for handling this combined email comes from this function. For
- other cases, we just use the normal handling.'''
-
- # If self._single_revision isn't set; don't override
- if not self._single_revision:
- for line in super(BranchChange, self).generate_email_body(push):
- yield line
- return
-
- # This is a combined refchange/revision email; we first provide
- # some info from the refchange portion, and then call the revision
- # generate_email_body function to handle the revision portion.
- adds = list(generate_summaries(
- '--topo-order', '--reverse', '%s..%s'
- % (self.old.commit_sha1, self.new.commit_sha1,)
- ))
-
- yield self.expand("The following commit(s) were added to %(refname)s by this push:\n")
- for (sha1, subject) in adds:
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='new',
- rev_short=sha1, text=subject,
- )
-
- yield self._single_revision.rev.short + " is described below\n"
- yield '\n'
-
- for line in self._single_revision.generate_email_body(push):
- yield line
-
-
-class AnnotatedTagChange(ReferenceChange):
- refname_type = 'annotated tag'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_announce_recipients(self)
- self.show_shortlog = environment.announce_show_shortlog
-
- ANNOTATED_TAG_FORMAT = (
- '%(*objectname)\n'
- '%(*objecttype)\n'
- '%(taggername)\n'
- '%(taggerdate)'
- )
-
- def describe_tag(self, push):
- """Describe the new value of an annotated tag."""
-
- # Use git for-each-ref to pull out the individual fields from
- # the tag
- [tagobject, tagtype, tagger, tagged] = read_git_lines(
- ['for-each-ref', '--format=%s' % (self.ANNOTATED_TAG_FORMAT,), self.refname],
- )
-
- yield self.expand(
- BRIEF_SUMMARY_TEMPLATE, action='tagging',
- rev_short=tagobject, text='(%s)' % (tagtype,),
- )
- if tagtype == 'commit':
- # If the tagged object is a commit, then we assume this is a
- # release, and so we calculate which tag this tag is
- # replacing
- try:
- prevtag = read_git_output(['describe', '--abbrev=0', '%s^' % (self.new,)])
- except CommandError:
- prevtag = None
- if prevtag:
- yield ' replaces %s\n' % (prevtag,)
- else:
- prevtag = None
- yield ' length %s bytes\n' % (read_git_output(['cat-file', '-s', tagobject]),)
-
- yield ' by %s\n' % (tagger,)
- yield ' on %s\n' % (tagged,)
- yield '\n'
-
- # Show the content of the tag message; this might contain a
- # change log or release notes so is worth displaying.
- yield LOGBEGIN
- contents = list(read_git_lines(['cat-file', 'tag', self.new.sha1], keepends=True))
- contents = contents[contents.index('\n') + 1:]
- if contents and contents[-1][-1:] != '\n':
- contents.append('\n')
- for line in contents:
- yield line
-
- if self.show_shortlog and tagtype == 'commit':
- # Only commit tags make sense to have rev-list operations
- # performed on them
- yield '\n'
- if prevtag:
- # Show changes since the previous release
- revlist = read_git_output(
- ['rev-list', '--pretty=short', '%s..%s' % (prevtag, self.new,)],
- keepends=True,
- )
- else:
- # No previous tag, show all the changes since time
- # began
- revlist = read_git_output(
- ['rev-list', '--pretty=short', '%s' % (self.new,)],
- keepends=True,
- )
- for line in read_git_lines(['shortlog'], input=revlist, keepends=True):
- yield line
-
- yield LOGEND
- yield '\n'
-
- def generate_create_summary(self, push):
- """Called for the creation of an annotated tag."""
-
- for line in self.expand_lines(TAG_CREATED_TEMPLATE):
- yield line
-
- for line in self.describe_tag(push):
- yield line
-
- def generate_update_summary(self, push):
- """Called for the update of an annotated tag.
-
- This is probably a rare event and may not even be allowed."""
-
- for line in self.expand_lines(TAG_UPDATED_TEMPLATE):
- yield line
-
- for line in self.describe_tag(push):
- yield line
-
- def generate_delete_summary(self, push):
- """Called when a non-annotated reference is updated."""
-
- for line in self.expand_lines(TAG_DELETED_TEMPLATE):
- yield line
-
- yield self.expand(' tag was %(oldrev_short)s\n')
- yield '\n'
-
-
-class NonAnnotatedTagChange(ReferenceChange):
- refname_type = 'tag'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=short_refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_refchange_recipients(self)
-
- def generate_create_summary(self, push):
- """Called for the creation of an annotated tag."""
-
- for line in self.expand_lines(TAG_CREATED_TEMPLATE):
- yield line
-
- def generate_update_summary(self, push):
- """Called when a non-annotated reference is updated."""
-
- for line in self.expand_lines(TAG_UPDATED_TEMPLATE):
- yield line
-
- def generate_delete_summary(self, push):
- """Called when a non-annotated reference is updated."""
-
- for line in self.expand_lines(TAG_DELETED_TEMPLATE):
- yield line
-
- for line in ReferenceChange.generate_delete_summary(self, push):
- yield line
-
-
-class OtherReferenceChange(ReferenceChange):
- refname_type = 'reference'
-
- def __init__(self, environment, refname, short_refname, old, new, rev):
- # We use the full refname as short_refname, because otherwise
- # the full name of the reference would not be obvious from the
- # text of the email.
- ReferenceChange.__init__(
- self, environment,
- refname=refname, short_refname=refname,
- old=old, new=new, rev=rev,
- )
- self.recipients = environment.get_refchange_recipients(self)
-
-
-class Mailer(object):
- """An object that can send emails."""
-
- def __init__(self, environment):
- self.environment = environment
-
- def close(self):
- pass
-
- def send(self, lines, to_addrs):
- """Send an email consisting of lines.
-
- lines must be an iterable over the lines constituting the
- header and body of the email. to_addrs is a list of recipient
- addresses (can be needed even if lines already contains a
- "To:" field). It can be either a string (comma-separated list
- of email addresses) or a Python list of individual email
- addresses.
-
- """
-
- raise NotImplementedError()
-
-
-class SendMailer(Mailer):
- """Send emails using 'sendmail -oi -t'."""
-
- SENDMAIL_CANDIDATES = [
- '/usr/sbin/sendmail',
- '/usr/lib/sendmail',
- ]
-
- @staticmethod
- def find_sendmail():
- for path in SendMailer.SENDMAIL_CANDIDATES:
- if os.access(path, os.X_OK):
- return path
- else:
- raise ConfigurationException(
- 'No sendmail executable found. '
- 'Try setting multimailhook.sendmailCommand.'
- )
-
- def __init__(self, environment, command=None, envelopesender=None):
- """Construct a SendMailer instance.
-
- command should be the command and arguments used to invoke
- sendmail, as a list of strings. If an envelopesender is
- provided, it will also be passed to the command, via '-f
- envelopesender'."""
- super(SendMailer, self).__init__(environment)
- if command:
- self.command = command[:]
- else:
- self.command = [self.find_sendmail(), '-oi', '-t']
-
- if envelopesender:
- self.command.extend(['-f', envelopesender])
-
- def send(self, lines, to_addrs):
- try:
- p = subprocess.Popen(self.command, stdin=subprocess.PIPE)
- except OSError:
- self.environment.get_logger().error(
- '*** Cannot execute command: %s\n' % ' '.join(self.command) +
- '*** %s\n' % sys.exc_info()[1] +
- '*** Try setting multimailhook.mailer to "smtp"\n' +
- '*** to send emails without using the sendmail command.\n'
- )
- sys.exit(1)
- try:
- lines = (str_to_bytes(line) for line in lines)
- p.stdin.writelines(lines)
- except Exception:
- self.environment.get_logger().error(
- '*** Error while generating commit email\n'
- '*** - mail sending aborted.\n'
- )
- if hasattr(p, 'terminate'):
- # subprocess.terminate() is not available in Python 2.4
- p.terminate()
- else:
- import signal
- os.kill(p.pid, signal.SIGTERM)
- raise
- else:
- p.stdin.close()
- retcode = p.wait()
- if retcode:
- raise CommandError(self.command, retcode)
-
-
-class SMTPMailer(Mailer):
- """Send emails using Python's smtplib."""
-
- def __init__(self, environment,
- envelopesender, smtpserver,
- smtpservertimeout=10.0, smtpserverdebuglevel=0,
- smtpencryption='none',
- smtpuser='', smtppass='',
- smtpcacerts=''
- ):
- super(SMTPMailer, self).__init__(environment)
- if not envelopesender:
- self.environment.get_logger().error(
- 'fatal: git_multimail: cannot use SMTPMailer without a sender address.\n'
- 'please set either multimailhook.envelopeSender or user.email\n'
- )
- sys.exit(1)
- if smtpencryption == 'ssl' and not (smtpuser and smtppass):
- raise ConfigurationException(
- 'Cannot use SMTPMailer with security option ssl '
- 'without options username and password.'
- )
- self.envelopesender = envelopesender
- self.smtpserver = smtpserver
- self.smtpservertimeout = smtpservertimeout
- self.smtpserverdebuglevel = smtpserverdebuglevel
- self.security = smtpencryption
- self.username = smtpuser
- self.password = smtppass
- self.smtpcacerts = smtpcacerts
- self.loggedin = False
- try:
- def call(klass, server, timeout):
- try:
- return klass(server, timeout=timeout)
- except TypeError:
- # Old Python versions do not have timeout= argument.
- return klass(server)
- if self.security == 'none':
- self.smtp = call(smtplib.SMTP, self.smtpserver, timeout=self.smtpservertimeout)
- elif self.security == 'ssl':
- if self.smtpcacerts:
- raise smtplib.SMTPException(
- "Checking certificate is not supported for ssl, prefer starttls"
- )
- self.smtp = call(smtplib.SMTP_SSL, self.smtpserver, timeout=self.smtpservertimeout)
- elif self.security == 'tls':
- if 'ssl' not in sys.modules:
- self.environment.get_logger().error(
- '*** Your Python version does not have the ssl library installed\n'
- '*** smtpEncryption=tls is not available.\n'
- '*** Either upgrade Python to 2.6 or later\n'
- ' or use git_multimail.py version 1.2.\n')
- if ':' not in self.smtpserver:
- self.smtpserver += ':587' # default port for TLS
- self.smtp = call(smtplib.SMTP, self.smtpserver, timeout=self.smtpservertimeout)
- # start: ehlo + starttls
- # equivalent to
- # self.smtp.ehlo()
- # self.smtp.starttls()
- # with acces to the ssl layer
- self.smtp.ehlo()
- if not self.smtp.has_extn("starttls"):
- raise smtplib.SMTPException("STARTTLS extension not supported by server")
- resp, reply = self.smtp.docmd("STARTTLS")
- if resp != 220:
- raise smtplib.SMTPException("Wrong answer to the STARTTLS command")
- if self.smtpcacerts:
- self.smtp.sock = ssl.wrap_socket(
- self.smtp.sock,
- ca_certs=self.smtpcacerts,
- cert_reqs=ssl.CERT_REQUIRED
- )
- else:
- self.smtp.sock = ssl.wrap_socket(
- self.smtp.sock,
- cert_reqs=ssl.CERT_NONE
- )
- self.environment.get_logger().error(
- '*** Warning, the server certificat is not verified (smtp) ***\n'
- '*** set the option smtpCACerts ***\n'
- )
- if not hasattr(self.smtp.sock, "read"):
- # using httplib.FakeSocket with Python 2.5.x or earlier
- self.smtp.sock.read = self.smtp.sock.recv
- self.smtp.file = smtplib.SSLFakeFile(self.smtp.sock)
- self.smtp.helo_resp = None
- self.smtp.ehlo_resp = None
- self.smtp.esmtp_features = {}
- self.smtp.does_esmtp = 0
- # end: ehlo + starttls
- self.smtp.ehlo()
- else:
- sys.stdout.write('*** Error: Control reached an invalid option. ***')
- sys.exit(1)
- if self.smtpserverdebuglevel > 0:
- sys.stdout.write(
- "*** Setting debug on for SMTP server connection (%s) ***\n"
- % self.smtpserverdebuglevel)
- self.smtp.set_debuglevel(self.smtpserverdebuglevel)
- except Exception:
- self.environment.get_logger().error(
- '*** Error establishing SMTP connection to %s ***\n'
- '*** %s\n'
- % (self.smtpserver, sys.exc_info()[1]))
- sys.exit(1)
-
- def close(self):
- if hasattr(self, 'smtp'):
- self.smtp.quit()
- del self.smtp
-
- def __del__(self):
- self.close()
-
- def send(self, lines, to_addrs):
- try:
- if self.username or self.password:
- if not self.loggedin:
- self.smtp.login(self.username, self.password)
- self.loggedin = True
- msg = ''.join(lines)
- # turn comma-separated list into Python list if needed.
- if is_string(to_addrs):
- to_addrs = [email for (name, email) in getaddresses([to_addrs])]
- self.smtp.sendmail(self.envelopesender, to_addrs, msg)
- except socket.timeout:
- self.environment.get_logger().error(
- '*** Error sending email ***\n'
- '*** SMTP server timed out (timeout is %s)\n'
- % self.smtpservertimeout)
- except smtplib.SMTPResponseException:
- err = sys.exc_info()[1]
- self.environment.get_logger().error(
- '*** Error sending email ***\n'
- '*** Error %d: %s\n'
- % (err.smtp_code, bytes_to_str(err.smtp_error)))
- try:
- smtp = self.smtp
- # delete the field before quit() so that in case of
- # error, self.smtp is deleted anyway.
- del self.smtp
- smtp.quit()
- except:
- self.environment.get_logger().error(
- '*** Error closing the SMTP connection ***\n'
- '*** Exiting anyway ... ***\n'
- '*** %s\n' % sys.exc_info()[1])
- sys.exit(1)
-
-
-class OutputMailer(Mailer):
- """Write emails to an output stream, bracketed by lines of '=' characters.
-
- This is intended for debugging purposes."""
-
- SEPARATOR = '=' * 75 + '\n'
-
- def __init__(self, f, environment=None):
- super(OutputMailer, self).__init__(environment=environment)
- self.f = f
-
- def send(self, lines, to_addrs):
- write_str(self.f, self.SEPARATOR)
- for line in lines:
- write_str(self.f, line)
- write_str(self.f, self.SEPARATOR)
-
-
-def get_git_dir():
- """Determine GIT_DIR.
-
- Determine GIT_DIR either from the GIT_DIR environment variable or
- from the working directory, using Git's usual rules."""
-
- try:
- return read_git_output(['rev-parse', '--git-dir'])
- except CommandError:
- sys.stderr.write('fatal: git_multimail: not in a git directory\n')
- sys.exit(1)
-
-
-class Environment(object):
- """Describes the environment in which the push is occurring.
-
- An Environment object encapsulates information about the local
- environment. For example, it knows how to determine:
-
- * the name of the repository to which the push occurred
-
- * what user did the push
-
- * what users want to be informed about various types of changes.
-
- An Environment object is expected to have the following methods:
-
- get_repo_shortname()
-
- Return a short name for the repository, for display
- purposes.
-
- get_repo_path()
-
- Return the absolute path to the Git repository.
-
- get_emailprefix()
-
- Return a string that will be prefixed to every email's
- subject.
-
- get_pusher()
-
- Return the username of the person who pushed the changes.
- This value is used in the email body to indicate who
- pushed the change.
-
- get_pusher_email() (may return None)
-
- Return the email address of the person who pushed the
- changes. The value should be a single RFC 2822 email
- address as a string; e.g., "Joe User <user@example.com>"
- if available, otherwise "user@example.com". If set, the
- value is used as the Reply-To address for refchange
- emails. If it is impossible to determine the pusher's
- email, this attribute should be set to None (in which case
- no Reply-To header will be output).
-
- get_sender()
-
- Return the address to be used as the 'From' email address
- in the email envelope.
-
- get_fromaddr(change=None)
-
- Return the 'From' email address used in the email 'From:'
- headers. If the change is known when this function is
- called, it is passed in as the 'change' parameter. (May
- be a full RFC 2822 email address like 'Joe User
- <user@example.com>'.)
-
- get_administrator()
-
- Return the name and/or email of the repository
- administrator. This value is used in the footer as the
- person to whom requests to be removed from the
- notification list should be sent. Ideally, it should
- include a valid email address.
-
- get_reply_to_refchange()
- get_reply_to_commit()
-
- Return the address to use in the email "Reply-To" header,
- as a string. These can be an RFC 2822 email address, or
- None to omit the "Reply-To" header.
- get_reply_to_refchange() is used for refchange emails;
- get_reply_to_commit() is used for individual commit
- emails.
-
- get_ref_filter_regex()
-
- Return a tuple -- a compiled regex, and a boolean indicating
- whether the regex picks refs to include (if False, the regex
- matches on refs to exclude).
-
- get_default_ref_ignore_regex()
-
- Return a regex that should be ignored for both what emails
- to send and when computing what commits are considered new
- to the repository. Default is "^refs/notes/".
-
- get_max_subject_length()
-
- Return an int giving the maximal length for the subject
- (git log --oneline).
-
- They should also define the following attributes:
-
- announce_show_shortlog (bool)
-
- True iff announce emails should include a shortlog.
-
- commit_email_format (string)
-
- If "html", generate commit emails in HTML instead of plain text
- used by default.
-
- html_in_intro (bool)
- html_in_footer (bool)
-
- When generating HTML emails, the introduction (respectively,
- the footer) will be HTML-escaped iff html_in_intro (respectively,
- the footer) is true. When false, only the values used to expand
- the template are escaped.
-
- refchange_showgraph (bool)
-
- True iff refchanges emails should include a detailed graph.
-
- refchange_showlog (bool)
-
- True iff refchanges emails should include a detailed log.
-
- diffopts (list of strings)
-
- The options that should be passed to 'git diff' for the
- summary email. The value should be a list of strings
- representing words to be passed to the command.
-
- graphopts (list of strings)
-
- Analogous to diffopts, but contains options passed to
- 'git log --graph' when generating the detailed graph for
- a set of commits (see refchange_showgraph)
-
- logopts (list of strings)
-
- Analogous to diffopts, but contains options passed to
- 'git log' when generating the detailed log for a set of
- commits (see refchange_showlog)
-
- commitlogopts (list of strings)
-
- The options that should be passed to 'git log' for each
- commit mail. The value should be a list of strings
- representing words to be passed to the command.
-
- date_substitute (string)
-
- String to be used in substitution for 'Date:' at start of
- line in the output of 'git log'.
-
- quiet (bool)
- On success do not write to stderr
-
- stdout (bool)
- Write email to stdout rather than emailing. Useful for debugging
-
- combine_when_single_commit (bool)
-
- True if a combined email should be produced when a single
- new commit is pushed to a branch, False otherwise.
-
- from_refchange, from_commit (strings)
-
- Addresses to use for the From: field for refchange emails
- and commit emails respectively. Set from
- multimailhook.fromRefchange and multimailhook.fromCommit
- by ConfigEnvironmentMixin.
-
- log_file, error_log_file, debug_log_file (string)
-
- Name of a file to which logs should be sent.
-
- verbose (int)
-
- How verbose the system should be.
- - 0 (default): show info, errors, ...
- - 1 : show basic debug info
- """
-
- REPO_NAME_RE = re.compile(r'^(?P<name>.+?)(?:\.git)$')
-
- def __init__(self, osenv=None):
- self.osenv = osenv or os.environ
- self.announce_show_shortlog = False
- self.commit_email_format = "text"
- self.html_in_intro = False
- self.html_in_footer = False
- self.commitBrowseURL = None
- self.maxcommitemails = 500
- self.excludemergerevisions = False
- self.diffopts = ['--stat', '--summary', '--find-copies-harder']
- self.graphopts = ['--oneline', '--decorate']
- self.logopts = []
- self.refchange_showgraph = False
- self.refchange_showlog = False
- self.commitlogopts = ['-C', '--stat', '-p', '--cc']
- self.date_substitute = 'AuthorDate: '
- self.quiet = False
- self.stdout = False
- self.combine_when_single_commit = True
- self.logger = None
-
- self.COMPUTED_KEYS = [
- 'administrator',
- 'charset',
- 'emailprefix',
- 'pusher',
- 'pusher_email',
- 'repo_path',
- 'repo_shortname',
- 'sender',
- ]
-
- self._values = None
-
- def get_logger(self):
- """Get (possibly creates) the logger associated to this environment."""
- if self.logger is None:
- self.logger = Logger(self)
- return self.logger
-
- def get_repo_shortname(self):
- """Use the last part of the repo path, with ".git" stripped off if present."""
-
- basename = os.path.basename(os.path.abspath(self.get_repo_path()))
- m = self.REPO_NAME_RE.match(basename)
- if m:
- return m.group('name')
- else:
- return basename
-
- def get_pusher(self):
- raise NotImplementedError()
-
- def get_pusher_email(self):
- return None
-
- def get_fromaddr(self, change=None):
- config = Config('user')
- fromname = config.get('name', default='')
- fromemail = config.get('email', default='')
- if fromemail:
- return formataddr([fromname, fromemail])
- return self.get_sender()
-
- def get_administrator(self):
- return 'the administrator of this repository'
-
- def get_emailprefix(self):
- return ''
-
- def get_repo_path(self):
- if read_git_output(['rev-parse', '--is-bare-repository']) == 'true':
- path = get_git_dir()
- else:
- path = read_git_output(['rev-parse', '--show-toplevel'])
- return os.path.abspath(path)
-
- def get_charset(self):
- return CHARSET
-
- def get_values(self):
- """Return a dictionary {keyword: expansion} for this Environment.
-
- This method is called by Change._compute_values(). The keys
- in the returned dictionary are available to be used in any of
- the templates. The dictionary is created by calling
- self.get_NAME() for each of the attributes named in
- COMPUTED_KEYS and recording those that do not return None.
- The return value is always a new dictionary."""
-
- if self._values is None:
- values = {'': ''} # %()s expands to the empty string.
-
- for key in self.COMPUTED_KEYS:
- value = getattr(self, 'get_%s' % (key,))()
- if value is not None:
- values[key] = value
-
- self._values = values
-
- return self._values.copy()
-
- def get_refchange_recipients(self, refchange):
- """Return the recipients for notifications about refchange.
-
- Return the list of email addresses to which notifications
- about the specified ReferenceChange should be sent."""
-
- raise NotImplementedError()
-
- def get_announce_recipients(self, annotated_tag_change):
- """Return the recipients for notifications about annotated_tag_change.
-
- Return the list of email addresses to which notifications
- about the specified AnnotatedTagChange should be sent."""
-
- raise NotImplementedError()
-
- def get_reply_to_refchange(self, refchange):
- return self.get_pusher_email()
-
- def get_revision_recipients(self, revision):
- """Return the recipients for messages about revision.
-
- Return the list of email addresses to which notifications
- about the specified Revision should be sent. This method
- could be overridden, for example, to take into account the
- contents of the revision when deciding whom to notify about
- it. For example, there could be a scheme for users to express
- interest in particular files or subdirectories, and only
- receive notification emails for revisions that affecting those
- files."""
-
- raise NotImplementedError()
-
- def get_reply_to_commit(self, revision):
- return revision.author
-
- def get_default_ref_ignore_regex(self):
- # The commit messages of git notes are essentially meaningless
- # and "filenames" in git notes commits are an implementational
- # detail that might surprise users at first. As such, we
- # would need a completely different method for handling emails
- # of git notes in order for them to be of benefit for users,
- # which we simply do not have right now.
- return "^refs/notes/"
-
- def get_max_subject_length(self):
- """Return the maximal subject line (git log --oneline) length.
- Longer subject lines will be truncated."""
- raise NotImplementedError()
-
- def filter_body(self, lines):
- """Filter the lines intended for an email body.
-
- lines is an iterable over the lines that would go into the
- email body. Filter it (e.g., limit the number of lines, the
- line length, character set, etc.), returning another iterable.
- See FilterLinesEnvironmentMixin and MaxlinesEnvironmentMixin
- for classes implementing this functionality."""
-
- return lines
-
- def log_msg(self, msg):
- """Write the string msg on a log file or on stderr.
-
- Sends the text to stderr by default, override to change the behavior."""
- self.get_logger().info(msg)
-
- def log_warning(self, msg):
- """Write the string msg on a log file or on stderr.
-
- Sends the text to stderr by default, override to change the behavior."""
- self.get_logger().warning(msg)
-
- def log_error(self, msg):
- """Write the string msg on a log file or on stderr.
-
- Sends the text to stderr by default, override to change the behavior."""
- self.get_logger().error(msg)
-
- def check(self):
- pass
-
-
-class ConfigEnvironmentMixin(Environment):
- """A mixin that sets self.config to its constructor's config argument.
-
- This class's constructor consumes the "config" argument.
-
- Mixins that need to inspect the config should inherit from this
- class (1) to make sure that "config" is still in the constructor
- arguments with its own constructor runs and/or (2) to be sure that
- self.config is set after construction."""
-
- def __init__(self, config, **kw):
- super(ConfigEnvironmentMixin, self).__init__(**kw)
- self.config = config
-
-
-class ConfigOptionsEnvironmentMixin(ConfigEnvironmentMixin):
- """An Environment that reads most of its information from "git config"."""
-
- @staticmethod
- def forbid_field_values(name, value, forbidden):
- for forbidden_val in forbidden:
- if value is not None and value.lower() == forbidden:
- raise ConfigurationException(
- '"%s" is not an allowed setting for %s' % (value, name)
- )
-
- def __init__(self, config, **kw):
- super(ConfigOptionsEnvironmentMixin, self).__init__(
- config=config, **kw
- )
-
- for var, cfg in (
- ('announce_show_shortlog', 'announceshortlog'),
- ('refchange_showgraph', 'refchangeShowGraph'),
- ('refchange_showlog', 'refchangeshowlog'),
- ('quiet', 'quiet'),
- ('stdout', 'stdout'),
- ):
- val = config.get_bool(cfg)
- if val is not None:
- setattr(self, var, val)
-
- commit_email_format = config.get('commitEmailFormat')
- if commit_email_format is not None:
- if commit_email_format != "html" and commit_email_format != "text":
- self.log_warning(
- '*** Unknown value for multimailhook.commitEmailFormat: %s\n' %
- commit_email_format +
- '*** Expected either "text" or "html". Ignoring.\n'
- )
- else:
- self.commit_email_format = commit_email_format
-
- html_in_intro = config.get_bool('htmlInIntro')
- if html_in_intro is not None:
- self.html_in_intro = html_in_intro
-
- html_in_footer = config.get_bool('htmlInFooter')
- if html_in_footer is not None:
- self.html_in_footer = html_in_footer
-
- self.commitBrowseURL = config.get('commitBrowseURL')
-
- self.excludemergerevisions = config.get('excludeMergeRevisions')
-
- maxcommitemails = config.get('maxcommitemails')
- if maxcommitemails is not None:
- try:
- self.maxcommitemails = int(maxcommitemails)
- except ValueError:
- self.log_warning(
- '*** Malformed value for multimailhook.maxCommitEmails: %s\n'
- % maxcommitemails +
- '*** Expected a number. Ignoring.\n'
- )
-
- diffopts = config.get('diffopts')
- if diffopts is not None:
- self.diffopts = shlex.split(diffopts)
-
- graphopts = config.get('graphOpts')
- if graphopts is not None:
- self.graphopts = shlex.split(graphopts)
-
- logopts = config.get('logopts')
- if logopts is not None:
- self.logopts = shlex.split(logopts)
-
- commitlogopts = config.get('commitlogopts')
- if commitlogopts is not None:
- self.commitlogopts = shlex.split(commitlogopts)
-
- date_substitute = config.get('dateSubstitute')
- if date_substitute == 'none':
- self.date_substitute = None
- elif date_substitute is not None:
- self.date_substitute = date_substitute
-
- reply_to = config.get('replyTo')
- self.__reply_to_refchange = config.get('replyToRefchange', default=reply_to)
- self.forbid_field_values('replyToRefchange',
- self.__reply_to_refchange,
- ['author'])
- self.__reply_to_commit = config.get('replyToCommit', default=reply_to)
-
- self.from_refchange = config.get('fromRefchange')
- self.forbid_field_values('fromRefchange',
- self.from_refchange,
- ['author', 'none'])
- self.from_commit = config.get('fromCommit')
- self.forbid_field_values('fromCommit',
- self.from_commit,
- ['none'])
-
- combine = config.get_bool('combineWhenSingleCommit')
- if combine is not None:
- self.combine_when_single_commit = combine
-
- self.log_file = config.get('logFile', default=None)
- self.error_log_file = config.get('errorLogFile', default=None)
- self.debug_log_file = config.get('debugLogFile', default=None)
- if config.get_bool('Verbose', default=False):
- self.verbose = 1
- else:
- self.verbose = 0
-
- def get_administrator(self):
- return (
- self.config.get('administrator') or
- self.get_sender() or
- super(ConfigOptionsEnvironmentMixin, self).get_administrator()
- )
-
- def get_repo_shortname(self):
- return (
- self.config.get('reponame') or
- super(ConfigOptionsEnvironmentMixin, self).get_repo_shortname()
- )
-
- def get_emailprefix(self):
- emailprefix = self.config.get('emailprefix')
- if emailprefix is not None:
- emailprefix = emailprefix.strip()
- if emailprefix:
- emailprefix += ' '
- else:
- emailprefix = '[%(repo_shortname)s] '
- short_name = self.get_repo_shortname()
- try:
- return emailprefix % {'repo_shortname': short_name}
- except:
- self.get_logger().error(
- '*** Invalid multimailhook.emailPrefix: %s\n' % emailprefix +
- '*** %s\n' % sys.exc_info()[1] +
- "*** Only the '%(repo_shortname)s' placeholder is allowed\n"
- )
- raise ConfigurationException(
- '"%s" is not an allowed setting for emailPrefix' % emailprefix
- )
-
- def get_sender(self):
- return self.config.get('envelopesender')
-
- def process_addr(self, addr, change):
- if addr.lower() == 'author':
- if hasattr(change, 'author'):
- return change.author
- else:
- return None
- elif addr.lower() == 'pusher':
- return self.get_pusher_email()
- elif addr.lower() == 'none':
- return None
- else:
- return addr
-
- def get_fromaddr(self, change=None):
- fromaddr = self.config.get('from')
- if change:
- specific_fromaddr = change.get_specific_fromaddr()
- if specific_fromaddr:
- fromaddr = specific_fromaddr
- if fromaddr:
- fromaddr = self.process_addr(fromaddr, change)
- if fromaddr:
- return fromaddr
- return super(ConfigOptionsEnvironmentMixin, self).get_fromaddr(change)
-
- def get_reply_to_refchange(self, refchange):
- if self.__reply_to_refchange is None:
- return super(ConfigOptionsEnvironmentMixin, self).get_reply_to_refchange(refchange)
- else:
- return self.process_addr(self.__reply_to_refchange, refchange)
-
- def get_reply_to_commit(self, revision):
- if self.__reply_to_commit is None:
- return super(ConfigOptionsEnvironmentMixin, self).get_reply_to_commit(revision)
- else:
- return self.process_addr(self.__reply_to_commit, revision)
-
- def get_scancommitforcc(self):
- return self.config.get('scancommitforcc')
-
-
-class FilterLinesEnvironmentMixin(Environment):
- """Handle encoding and maximum line length of body lines.
-
- email_max_line_length (int or None)
-
- The maximum length of any single line in the email body.
- Longer lines are truncated at that length with ' [...]'
- appended.
-
- strict_utf8 (bool)
-
- If this field is set to True, then the email body text is
- expected to be UTF-8. Any invalid characters are
- converted to U+FFFD, the Unicode replacement character
- (encoded as UTF-8, of course).
-
- """
-
- def __init__(self, strict_utf8=True,
- email_max_line_length=500, max_subject_length=500,
- **kw):
- super(FilterLinesEnvironmentMixin, self).__init__(**kw)
- self.__strict_utf8 = strict_utf8
- self.__email_max_line_length = email_max_line_length
- self.__max_subject_length = max_subject_length
-
- def filter_body(self, lines):
- lines = super(FilterLinesEnvironmentMixin, self).filter_body(lines)
- if self.__strict_utf8:
- if not PYTHON3:
- lines = (line.decode(ENCODING, 'replace') for line in lines)
- # Limit the line length in Unicode-space to avoid
- # splitting characters:
- if self.__email_max_line_length > 0:
- lines = limit_linelength(lines, self.__email_max_line_length)
- if not PYTHON3:
- lines = (line.encode(ENCODING, 'replace') for line in lines)
- elif self.__email_max_line_length:
- lines = limit_linelength(lines, self.__email_max_line_length)
-
- return lines
-
- def get_max_subject_length(self):
- return self.__max_subject_length
-
-
-class ConfigFilterLinesEnvironmentMixin(
- ConfigEnvironmentMixin,
- FilterLinesEnvironmentMixin,
- ):
- """Handle encoding and maximum line length based on config."""
-
- def __init__(self, config, **kw):
- strict_utf8 = config.get_bool('emailstrictutf8', default=None)
- if strict_utf8 is not None:
- kw['strict_utf8'] = strict_utf8
-
- email_max_line_length = config.get('emailmaxlinelength')
- if email_max_line_length is not None:
- kw['email_max_line_length'] = int(email_max_line_length)
-
- max_subject_length = config.get('subjectMaxLength', default=email_max_line_length)
- if max_subject_length is not None:
- kw['max_subject_length'] = int(max_subject_length)
-
- super(ConfigFilterLinesEnvironmentMixin, self).__init__(
- config=config, **kw
- )
-
-
-class MaxlinesEnvironmentMixin(Environment):
- """Limit the email body to a specified number of lines."""
-
- def __init__(self, emailmaxlines, **kw):
- super(MaxlinesEnvironmentMixin, self).__init__(**kw)
- self.__emailmaxlines = emailmaxlines
-
- def filter_body(self, lines):
- lines = super(MaxlinesEnvironmentMixin, self).filter_body(lines)
- if self.__emailmaxlines > 0:
- lines = limit_lines(lines, self.__emailmaxlines)
- return lines
-
-
-class ConfigMaxlinesEnvironmentMixin(
- ConfigEnvironmentMixin,
- MaxlinesEnvironmentMixin,
- ):
- """Limit the email body to the number of lines specified in config."""
-
- def __init__(self, config, **kw):
- emailmaxlines = int(config.get('emailmaxlines', default='0'))
- super(ConfigMaxlinesEnvironmentMixin, self).__init__(
- config=config,
- emailmaxlines=emailmaxlines,
- **kw
- )
-
-
-class FQDNEnvironmentMixin(Environment):
- """A mixin that sets the host's FQDN to its constructor argument."""
-
- def __init__(self, fqdn, **kw):
- super(FQDNEnvironmentMixin, self).__init__(**kw)
- self.COMPUTED_KEYS += ['fqdn']
- self.__fqdn = fqdn
-
- def get_fqdn(self):
- """Return the fully-qualified domain name for this host.
-
- Return None if it is unavailable or unwanted."""
-
- return self.__fqdn
-
-
-class ConfigFQDNEnvironmentMixin(
- ConfigEnvironmentMixin,
- FQDNEnvironmentMixin,
- ):
- """Read the FQDN from the config."""
-
- def __init__(self, config, **kw):
- fqdn = config.get('fqdn')
- super(ConfigFQDNEnvironmentMixin, self).__init__(
- config=config,
- fqdn=fqdn,
- **kw
- )
-
-
-class ComputeFQDNEnvironmentMixin(FQDNEnvironmentMixin):
- """Get the FQDN by calling socket.getfqdn()."""
-
- def __init__(self, **kw):
- super(ComputeFQDNEnvironmentMixin, self).__init__(
- fqdn=socket.getfqdn(),
- **kw
- )
-
-
-class PusherDomainEnvironmentMixin(ConfigEnvironmentMixin):
- """Deduce pusher_email from pusher by appending an emaildomain."""
-
- def __init__(self, **kw):
- super(PusherDomainEnvironmentMixin, self).__init__(**kw)
- self.__emaildomain = self.config.get('emaildomain')
-
- def get_pusher_email(self):
- if self.__emaildomain:
- # Derive the pusher's full email address in the default way:
- return '%s@%s' % (self.get_pusher(), self.__emaildomain)
- else:
- return super(PusherDomainEnvironmentMixin, self).get_pusher_email()
-
-
-class StaticRecipientsEnvironmentMixin(Environment):
- """Set recipients statically based on constructor parameters."""
-
- def __init__(
- self,
- refchange_recipients, announce_recipients, revision_recipients, scancommitforcc,
- **kw
- ):
- super(StaticRecipientsEnvironmentMixin, self).__init__(**kw)
-
- # The recipients for various types of notification emails, as
- # RFC 2822 email addresses separated by commas (or the empty
- # string if no recipients are configured). Although there is
- # a mechanism to choose the recipient lists based on on the
- # actual *contents* of the change being reported, we only
- # choose based on the *type* of the change. Therefore we can
- # compute them once and for all:
- self.__refchange_recipients = refchange_recipients
- self.__announce_recipients = announce_recipients
- self.__revision_recipients = revision_recipients
-
- def check(self):
- if not (self.get_refchange_recipients(None) or
- self.get_announce_recipients(None) or
- self.get_revision_recipients(None) or
- self.get_scancommitforcc()):
- raise ConfigurationException('No email recipients configured!')
- super(StaticRecipientsEnvironmentMixin, self).check()
-
- def get_refchange_recipients(self, refchange):
- if self.__refchange_recipients is None:
- return super(StaticRecipientsEnvironmentMixin,
- self).get_refchange_recipients(refchange)
- return self.__refchange_recipients
-
- def get_announce_recipients(self, annotated_tag_change):
- if self.__announce_recipients is None:
- return super(StaticRecipientsEnvironmentMixin,
- self).get_refchange_recipients(annotated_tag_change)
- return self.__announce_recipients
-
- def get_revision_recipients(self, revision):
- if self.__revision_recipients is None:
- return super(StaticRecipientsEnvironmentMixin,
- self).get_refchange_recipients(revision)
- return self.__revision_recipients
-
-
-class CLIRecipientsEnvironmentMixin(Environment):
- """Mixin storing recipients information coming from the
- command-line."""
-
- def __init__(self, cli_recipients=None, **kw):
- super(CLIRecipientsEnvironmentMixin, self).__init__(**kw)
- self.__cli_recipients = cli_recipients
-
- def get_refchange_recipients(self, refchange):
- if self.__cli_recipients is None:
- return super(CLIRecipientsEnvironmentMixin,
- self).get_refchange_recipients(refchange)
- return self.__cli_recipients
-
- def get_announce_recipients(self, annotated_tag_change):
- if self.__cli_recipients is None:
- return super(CLIRecipientsEnvironmentMixin,
- self).get_announce_recipients(annotated_tag_change)
- return self.__cli_recipients
-
- def get_revision_recipients(self, revision):
- if self.__cli_recipients is None:
- return super(CLIRecipientsEnvironmentMixin,
- self).get_revision_recipients(revision)
- return self.__cli_recipients
-
-
-class ConfigRecipientsEnvironmentMixin(
- ConfigEnvironmentMixin,
- StaticRecipientsEnvironmentMixin
- ):
- """Determine recipients statically based on config."""
-
- def __init__(self, config, **kw):
- super(ConfigRecipientsEnvironmentMixin, self).__init__(
- config=config,
- refchange_recipients=self._get_recipients(
- config, 'refchangelist', 'mailinglist',
- ),
- announce_recipients=self._get_recipients(
- config, 'announcelist', 'refchangelist', 'mailinglist',
- ),
- revision_recipients=self._get_recipients(
- config, 'commitlist', 'mailinglist',
- ),
- scancommitforcc=config.get('scancommitforcc'),
- **kw
- )
-
- def _get_recipients(self, config, *names):
- """Return the recipients for a particular type of message.
-
- Return the list of email addresses to which a particular type
- of notification email should be sent, by looking at the config
- value for "multimailhook.$name" for each of names. Use the
- value from the first name that is configured. The return
- value is a (possibly empty) string containing RFC 2822 email
- addresses separated by commas. If no configuration could be
- found, raise a ConfigurationException."""
-
- for name in names:
- lines = config.get_all(name)
- if lines is not None:
- lines = [line.strip() for line in lines]
- # Single "none" is a special value equivalen to empty string.
- if lines == ['none']:
- lines = ['']
- return ', '.join(lines)
- else:
- return ''
-
-
-class StaticRefFilterEnvironmentMixin(Environment):
- """Set branch filter statically based on constructor parameters."""
-
- def __init__(self, ref_filter_incl_regex, ref_filter_excl_regex,
- ref_filter_do_send_regex, ref_filter_dont_send_regex,
- **kw):
- super(StaticRefFilterEnvironmentMixin, self).__init__(**kw)
-
- if ref_filter_incl_regex and ref_filter_excl_regex:
- raise ConfigurationException(
- "Cannot specify both a ref inclusion and exclusion regex.")
- self.__is_inclusion_filter = bool(ref_filter_incl_regex)
- default_exclude = self.get_default_ref_ignore_regex()
- if ref_filter_incl_regex:
- ref_filter_regex = ref_filter_incl_regex
- elif ref_filter_excl_regex:
- ref_filter_regex = ref_filter_excl_regex + '|' + default_exclude
- else:
- ref_filter_regex = default_exclude
- try:
- self.__compiled_regex = re.compile(ref_filter_regex)
- except Exception:
- raise ConfigurationException(
- 'Invalid Ref Filter Regex "%s": %s' % (ref_filter_regex, sys.exc_info()[1]))
-
- if ref_filter_do_send_regex and ref_filter_dont_send_regex:
- raise ConfigurationException(
- "Cannot specify both a ref doSend and dontSend regex.")
- self.__is_do_send_filter = bool(ref_filter_do_send_regex)
- if ref_filter_do_send_regex:
- ref_filter_send_regex = ref_filter_do_send_regex
- elif ref_filter_dont_send_regex:
- ref_filter_send_regex = ref_filter_dont_send_regex
- else:
- ref_filter_send_regex = '.*'
- self.__is_do_send_filter = True
- try:
- self.__send_compiled_regex = re.compile(ref_filter_send_regex)
- except Exception:
- raise ConfigurationException(
- 'Invalid Ref Filter Regex "%s": %s' %
- (ref_filter_send_regex, sys.exc_info()[1]))
-
- def get_ref_filter_regex(self, send_filter=False):
- if send_filter:
- return self.__send_compiled_regex, self.__is_do_send_filter
- else:
- return self.__compiled_regex, self.__is_inclusion_filter
-
-
-class ConfigRefFilterEnvironmentMixin(
- ConfigEnvironmentMixin,
- StaticRefFilterEnvironmentMixin
- ):
- """Determine branch filtering statically based on config."""
-
- def _get_regex(self, config, key):
- """Get a list of whitespace-separated regex. The refFilter* config
- variables are multivalued (hence the use of get_all), and we
- allow each entry to be a whitespace-separated list (hence the
- split on each line). The whole thing is glued into a single regex."""
- values = config.get_all(key)
- if values is None:
- return values
- items = []
- for line in values:
- for i in line.split():
- items.append(i)
- if items == []:
- return None
- return '|'.join(items)
-
- def __init__(self, config, **kw):
- super(ConfigRefFilterEnvironmentMixin, self).__init__(
- config=config,
- ref_filter_incl_regex=self._get_regex(config, 'refFilterInclusionRegex'),
- ref_filter_excl_regex=self._get_regex(config, 'refFilterExclusionRegex'),
- ref_filter_do_send_regex=self._get_regex(config, 'refFilterDoSendRegex'),
- ref_filter_dont_send_regex=self._get_regex(config, 'refFilterDontSendRegex'),
- **kw
- )
-
-
-class ProjectdescEnvironmentMixin(Environment):
- """Make a "projectdesc" value available for templates.
-
- By default, it is set to the first line of $GIT_DIR/description
- (if that file is present and appears to be set meaningfully)."""
-
- def __init__(self, **kw):
- super(ProjectdescEnvironmentMixin, self).__init__(**kw)
- self.COMPUTED_KEYS += ['projectdesc']
-
- def get_projectdesc(self):
- """Return a one-line descripition of the project."""
-
- git_dir = get_git_dir()
- try:
- projectdesc = open(os.path.join(git_dir, 'description')).readline().strip()
- if projectdesc and not projectdesc.startswith('Unnamed repository'):
- return projectdesc
- except IOError:
- pass
-
- return 'UNNAMED PROJECT'
-
-
-class GenericEnvironmentMixin(Environment):
- def get_pusher(self):
- return self.osenv.get('USER', self.osenv.get('USERNAME', 'unknown user'))
-
-
-class GitoliteEnvironmentHighPrecMixin(Environment):
- def get_pusher(self):
- return self.osenv.get('GL_USER', 'unknown user')
-
-
-class GitoliteEnvironmentLowPrecMixin(
- ConfigEnvironmentMixin,
- Environment):
-
- def get_repo_shortname(self):
- # The gitolite environment variable $GL_REPO is a pretty good
- # repo_shortname (though it's probably not as good as a value
- # the user might have explicitly put in his config).
- return (
- self.osenv.get('GL_REPO', None) or
- super(GitoliteEnvironmentLowPrecMixin, self).get_repo_shortname()
- )
-
- @staticmethod
- def _compile_regex(re_template):
- return (
- re.compile(re_template % x)
- for x in (
- r'BEGIN\s+USER\s+EMAILS',
- r'([^\s]+)\s+(.*)',
- r'END\s+USER\s+EMAILS',
- ))
-
- def get_fromaddr(self, change=None):
- GL_USER = self.osenv.get('GL_USER')
- if GL_USER is not None:
- # Find the path to gitolite.conf. Note that gitolite v3
- # did away with the GL_ADMINDIR and GL_CONF environment
- # variables (they are now hard-coded).
- GL_ADMINDIR = self.osenv.get(
- 'GL_ADMINDIR',
- os.path.expanduser(os.path.join('~', '.gitolite')))
- GL_CONF = self.osenv.get(
- 'GL_CONF',
- os.path.join(GL_ADMINDIR, 'conf', 'gitolite.conf'))
-
- mailaddress_map = self.config.get('MailaddressMap')
- # If relative, consider relative to GL_CONF:
- if mailaddress_map:
- mailaddress_map = os.path.join(os.path.dirname(GL_CONF),
- mailaddress_map)
- if os.path.isfile(mailaddress_map):
- f = open(mailaddress_map, 'rU')
- try:
- # Leading '#' is optional
- re_begin, re_user, re_end = self._compile_regex(
- r'^(?:\s*#)?\s*%s\s*$')
- for l in f:
- l = l.rstrip('\n')
- if re_begin.match(l) or re_end.match(l):
- continue # Ignore these lines
- m = re_user.match(l)
- if m:
- if m.group(1) == GL_USER:
- return m.group(2)
- else:
- continue # Not this user, but not an error
- raise ConfigurationException(
- "Syntax error in mail address map.\n"
- "Check file {}.\n"
- "Line: {}".format(mailaddress_map, l))
-
- finally:
- f.close()
-
- if os.path.isfile(GL_CONF):
- f = open(GL_CONF, 'rU')
- try:
- in_user_emails_section = False
- re_begin, re_user, re_end = self._compile_regex(
- r'^\s*#\s*%s\s*$')
- for l in f:
- l = l.rstrip('\n')
- if not in_user_emails_section:
- if re_begin.match(l):
- in_user_emails_section = True
- continue
- if re_end.match(l):
- break
- m = re_user.match(l)
- if m and m.group(1) == GL_USER:
- return m.group(2)
- finally:
- f.close()
- return super(GitoliteEnvironmentLowPrecMixin, self).get_fromaddr(change)
-
-
-class IncrementalDateTime(object):
- """Simple wrapper to give incremental date/times.
-
- Each call will result in a date/time a second later than the
- previous call. This can be used to falsify email headers, to
- increase the likelihood that email clients sort the emails
- correctly."""
-
- def __init__(self):
- self.time = time.time()
- self.next = self.__next__ # Python 2 backward compatibility
-
- def __next__(self):
- formatted = formatdate(self.time, True)
- self.time += 1
- return formatted
-
-
-class StashEnvironmentHighPrecMixin(Environment):
- def __init__(self, user=None, repo=None, **kw):
- super(StashEnvironmentHighPrecMixin,
- self).__init__(user=user, repo=repo, **kw)
- self.__user = user
- self.__repo = repo
-
- def get_pusher(self):
- return re.match(r'(.*?)\s*<', self.__user).group(1)
-
- def get_pusher_email(self):
- return self.__user
-
-
-class StashEnvironmentLowPrecMixin(Environment):
- def __init__(self, user=None, repo=None, **kw):
- super(StashEnvironmentLowPrecMixin, self).__init__(**kw)
- self.__repo = repo
- self.__user = user
-
- def get_repo_shortname(self):
- return self.__repo
-
- def get_fromaddr(self, change=None):
- return self.__user
-
-
-class GerritEnvironmentHighPrecMixin(Environment):
- def __init__(self, project=None, submitter=None, update_method=None, **kw):
- super(GerritEnvironmentHighPrecMixin,
- self).__init__(submitter=submitter, project=project, **kw)
- self.__project = project
- self.__submitter = submitter
- self.__update_method = update_method
- "Make an 'update_method' value available for templates."
- self.COMPUTED_KEYS += ['update_method']
-
- def get_pusher(self):
- if self.__submitter:
- if self.__submitter.find('<') != -1:
- # Submitter has a configured email, we transformed
- # __submitter into an RFC 2822 string already.
- return re.match(r'(.*?)\s*<', self.__submitter).group(1)
- else:
- # Submitter has no configured email, it's just his name.
- return self.__submitter
- else:
- # If we arrive here, this means someone pushed "Submit" from
- # the gerrit web UI for the CR (or used one of the programmatic
- # APIs to do the same, such as gerrit review) and the
- # merge/push was done by the Gerrit user. It was technically
- # triggered by someone else, but sadly we have no way of
- # determining who that someone else is at this point.
- return 'Gerrit' # 'unknown user'?
-
- def get_pusher_email(self):
- if self.__submitter:
- return self.__submitter
- else:
- return super(GerritEnvironmentHighPrecMixin, self).get_pusher_email()
-
- def get_default_ref_ignore_regex(self):
- default = super(GerritEnvironmentHighPrecMixin, self).get_default_ref_ignore_regex()
- return default + '|^refs/changes/|^refs/cache-automerge/|^refs/meta/'
-
- def get_revision_recipients(self, revision):
- # Merge commits created by Gerrit when users hit "Submit this patchset"
- # in the Web UI (or do equivalently with REST APIs or the gerrit review
- # command) are not something users want to see an individual email for.
- # Filter them out.
- committer = read_git_output(['log', '--no-walk', '--format=%cN',
- revision.rev.sha1])
- if committer == 'Gerrit Code Review':
- return []
- else:
- return super(GerritEnvironmentHighPrecMixin, self).get_revision_recipients(revision)
-
- def get_update_method(self):
- return self.__update_method
-
-
-class GerritEnvironmentLowPrecMixin(Environment):
- def __init__(self, project=None, submitter=None, **kw):
- super(GerritEnvironmentLowPrecMixin, self).__init__(**kw)
- self.__project = project
- self.__submitter = submitter
-
- def get_repo_shortname(self):
- return self.__project
-
- def get_fromaddr(self, change=None):
- if self.__submitter and self.__submitter.find('<') != -1:
- return self.__submitter
- else:
- return super(GerritEnvironmentLowPrecMixin, self).get_fromaddr(change)
-
-
-class Push(object):
- """Represent an entire push (i.e., a group of ReferenceChanges).
-
- It is easy to figure out what commits were added to a *branch* by
- a Reference change:
-
- git rev-list change.old..change.new
-
- or removed from a *branch*:
-
- git rev-list change.new..change.old
-
- But it is not quite so trivial to determine which entirely new
- commits were added to the *repository* by a push and which old
- commits were discarded by a push. A big part of the job of this
- class is to figure out these things, and to make sure that new
- commits are only detailed once even if they were added to multiple
- references.
-
- The first step is to determine the "other" references--those
- unaffected by the current push. They are computed by listing all
- references then removing any affected by this push. The results
- are stored in Push._other_ref_sha1s.
-
- The commits contained in the repository before this push were
-
- git rev-list other1 other2 other3 ... change1.old change2.old ...
-
- Where "changeN.old" is the old value of one of the references
- affected by this push.
-
- The commits contained in the repository after this push are
-
- git rev-list other1 other2 other3 ... change1.new change2.new ...
-
- The commits added by this push are the difference between these
- two sets, which can be written
-
- git rev-list \
- ^other1 ^other2 ... \
- ^change1.old ^change2.old ... \
- change1.new change2.new ...
-
- The commits removed by this push can be computed by
-
- git rev-list \
- ^other1 ^other2 ... \
- ^change1.new ^change2.new ... \
- change1.old change2.old ...
-
- The last point is that it is possible that other pushes are
- occurring simultaneously to this one, so reference values can
- change at any time. It is impossible to eliminate all race
- conditions, but we reduce the window of time during which problems
- can occur by translating reference names to SHA1s as soon as
- possible and working with SHA1s thereafter (because SHA1s are
- immutable)."""
-
- # A map {(changeclass, changetype): integer} specifying the order
- # that reference changes will be processed if multiple reference
- # changes are included in a single push. The order is significant
- # mostly because new commit notifications are threaded together
- # with the first reference change that includes the commit. The
- # following order thus causes commits to be grouped with branch
- # changes (as opposed to tag changes) if possible.
- SORT_ORDER = dict(
- (value, i) for (i, value) in enumerate([
- (BranchChange, 'update'),
- (BranchChange, 'create'),
- (AnnotatedTagChange, 'update'),
- (AnnotatedTagChange, 'create'),
- (NonAnnotatedTagChange, 'update'),
- (NonAnnotatedTagChange, 'create'),
- (BranchChange, 'delete'),
- (AnnotatedTagChange, 'delete'),
- (NonAnnotatedTagChange, 'delete'),
- (OtherReferenceChange, 'update'),
- (OtherReferenceChange, 'create'),
- (OtherReferenceChange, 'delete'),
- ])
- )
-
- def __init__(self, environment, changes, ignore_other_refs=False):
- self.changes = sorted(changes, key=self._sort_key)
- self.__other_ref_sha1s = None
- self.__cached_commits_spec = {}
- self.environment = environment
-
- if ignore_other_refs:
- self.__other_ref_sha1s = set()
-
- @classmethod
- def _sort_key(klass, change):
- return (klass.SORT_ORDER[change.__class__, change.change_type], change.refname,)
-
- @property
- def _other_ref_sha1s(self):
- """The GitObjects referred to by references unaffected by this push.
- """
- if self.__other_ref_sha1s is None:
- # The refnames being changed by this push:
- updated_refs = set(
- change.refname
- for change in self.changes
- )
-
- # The SHA-1s of commits referred to by all references in this
- # repository *except* updated_refs:
- sha1s = set()
- fmt = (
- '%(objectname) %(objecttype) %(refname)\n'
- '%(*objectname) %(*objecttype) %(refname)'
- )
- ref_filter_regex, is_inclusion_filter = \
- self.environment.get_ref_filter_regex()
- for line in read_git_lines(
- ['for-each-ref', '--format=%s' % (fmt,)]):
- (sha1, type, name) = line.split(' ', 2)
- if (sha1 and type == 'commit' and
- name not in updated_refs and
- include_ref(name, ref_filter_regex, is_inclusion_filter)):
- sha1s.add(sha1)
-
- self.__other_ref_sha1s = sha1s
-
- return self.__other_ref_sha1s
-
- def _get_commits_spec_incl(self, new_or_old, reference_change=None):
- """Get new or old SHA-1 from one or each of the changed refs.
-
- Return a list of SHA-1 commit identifier strings suitable as
- arguments to 'git rev-list' (or 'git log' or ...). The
- returned identifiers are either the old or new values from one
- or all of the changed references, depending on the values of
- new_or_old and reference_change.
-
- new_or_old is either the string 'new' or the string 'old'. If
- 'new', the returned SHA-1 identifiers are the new values from
- each changed reference. If 'old', the SHA-1 identifiers are
- the old values from each changed reference.
-
- If reference_change is specified and not None, only the new or
- old reference from the specified reference is included in the
- return value.
-
- This function returns None if there are no matching revisions
- (e.g., because a branch was deleted and new_or_old is 'new').
- """
-
- if not reference_change:
- incl_spec = sorted(
- getattr(change, new_or_old).sha1
- for change in self.changes
- if getattr(change, new_or_old)
- )
- if not incl_spec:
- incl_spec = None
- elif not getattr(reference_change, new_or_old).commit_sha1:
- incl_spec = None
- else:
- incl_spec = [getattr(reference_change, new_or_old).commit_sha1]
- return incl_spec
-
- def _get_commits_spec_excl(self, new_or_old):
- """Get exclusion revisions for determining new or discarded commits.
-
- Return a list of strings suitable as arguments to 'git
- rev-list' (or 'git log' or ...) that will exclude all
- commits that, depending on the value of new_or_old, were
- either previously in the repository (useful for determining
- which commits are new to the repository) or currently in the
- repository (useful for determining which commits were
- discarded from the repository).
-
- new_or_old is either the string 'new' or the string 'old'. If
- 'new', the commits to be excluded are those that were in the
- repository before the push. If 'old', the commits to be
- excluded are those that are currently in the repository. """
-
- old_or_new = {'old': 'new', 'new': 'old'}[new_or_old]
- excl_revs = self._other_ref_sha1s.union(
- getattr(change, old_or_new).sha1
- for change in self.changes
- if getattr(change, old_or_new).type in ['commit', 'tag']
- )
- return ['^' + sha1 for sha1 in sorted(excl_revs)]
-
- def get_commits_spec(self, new_or_old, reference_change=None):
- """Get rev-list arguments for added or discarded commits.
-
- Return a list of strings suitable as arguments to 'git
- rev-list' (or 'git log' or ...) that select those commits
- that, depending on the value of new_or_old, are either new to
- the repository or were discarded from the repository.
-
- new_or_old is either the string 'new' or the string 'old'. If
- 'new', the returned list is used to select commits that are
- new to the repository. If 'old', the returned value is used
- to select the commits that have been discarded from the
- repository.
-
- If reference_change is specified and not None, the new or
- discarded commits are limited to those that are reachable from
- the new or old value of the specified reference.
-
- This function returns None if there are no added (or discarded)
- revisions.
- """
- key = (new_or_old, reference_change)
- if key not in self.__cached_commits_spec:
- ret = self._get_commits_spec_incl(new_or_old, reference_change)
- if ret is not None:
- ret.extend(self._get_commits_spec_excl(new_or_old))
- self.__cached_commits_spec[key] = ret
- return self.__cached_commits_spec[key]
-
- def get_new_commits(self, reference_change=None):
- """Return a list of commits added by this push.
-
- Return a list of the object names of commits that were added
- by the part of this push represented by reference_change. If
- reference_change is None, then return a list of *all* commits
- added by this push."""
-
- spec = self.get_commits_spec('new', reference_change)
- return git_rev_list(spec)
-
- def get_discarded_commits(self, reference_change):
- """Return a list of commits discarded by this push.
-
- Return a list of the object names of commits that were
- entirely discarded from the repository by the part of this
- push represented by reference_change."""
-
- spec = self.get_commits_spec('old', reference_change)
- return git_rev_list(spec)
-
- def send_emails(self, mailer, body_filter=None):
- """Use send all of the notification emails needed for this push.
-
- Use send all of the notification emails (including reference
- change emails and commit emails) needed for this push. Send
- the emails using mailer. If body_filter is not None, then use
- it to filter the lines that are intended for the email
- body."""
-
- # The sha1s of commits that were introduced by this push.
- # They will be removed from this set as they are processed, to
- # guarantee that one (and only one) email is generated for
- # each new commit.
- unhandled_sha1s = set(self.get_new_commits())
- send_date = IncrementalDateTime()
- for change in self.changes:
- sha1s = []
- for sha1 in reversed(list(self.get_new_commits(change))):
- if sha1 in unhandled_sha1s:
- sha1s.append(sha1)
- unhandled_sha1s.remove(sha1)
-
- # Check if we've got anyone to send to
- if not change.recipients:
- change.environment.log_warning(
- '*** no recipients configured so no email will be sent\n'
- '*** for %r update %s->%s'
- % (change.refname, change.old.sha1, change.new.sha1,)
- )
- else:
- if not change.environment.quiet:
- change.environment.log_msg(
- 'Sending notification emails to: %s' % (change.recipients,))
- extra_values = {'send_date': next(send_date)}
-
- rev = change.send_single_combined_email(sha1s)
- if rev:
- mailer.send(
- change.generate_combined_email(self, rev, body_filter, extra_values),
- rev.recipients,
- )
- # This change is now fully handled; no need to handle
- # individual revisions any further.
- continue
- else:
- mailer.send(
- change.generate_email(self, body_filter, extra_values),
- change.recipients,
- )
-
- max_emails = change.environment.maxcommitemails
- if max_emails and len(sha1s) > max_emails:
- change.environment.log_warning(
- '*** Too many new commits (%d), not sending commit emails.\n' % len(sha1s) +
- '*** Try setting multimailhook.maxCommitEmails to a greater value\n' +
- '*** Currently, multimailhook.maxCommitEmails=%d' % max_emails
- )
- return
-
- for (num, sha1) in enumerate(sha1s):
- rev = Revision(change, GitObject(sha1), num=num + 1, tot=len(sha1s))
- if len(rev.parents) > 1 and change.environment.excludemergerevisions:
- # skipping a merge commit
- continue
- if not rev.recipients and rev.cc_recipients:
- change.environment.log_msg('*** Replacing Cc: with To:')
- rev.recipients = rev.cc_recipients
- rev.cc_recipients = None
- if rev.recipients:
- extra_values = {'send_date': next(send_date)}
- mailer.send(
- rev.generate_email(self, body_filter, extra_values),
- rev.recipients,
- )
-
- # Consistency check:
- if unhandled_sha1s:
- change.environment.log_error(
- 'ERROR: No emails were sent for the following new commits:\n'
- ' %s'
- % ('\n '.join(sorted(unhandled_sha1s)),)
- )
-
-
-def include_ref(refname, ref_filter_regex, is_inclusion_filter):
- does_match = bool(ref_filter_regex.search(refname))
- if is_inclusion_filter:
- return does_match
- else: # exclusion filter -- we include the ref if the regex doesn't match
- return not does_match
-
-
-def run_as_post_receive_hook(environment, mailer):
- environment.check()
- send_filter_regex, send_is_inclusion_filter = environment.get_ref_filter_regex(True)
- ref_filter_regex, is_inclusion_filter = environment.get_ref_filter_regex(False)
- changes = []
- while True:
- line = read_line(sys.stdin)
- if line == '':
- break
- (oldrev, newrev, refname) = line.strip().split(' ', 2)
- environment.get_logger().debug(
- "run_as_post_receive_hook: oldrev=%s, newrev=%s, refname=%s" %
- (oldrev, newrev, refname))
-
- if not include_ref(refname, ref_filter_regex, is_inclusion_filter):
- continue
- if not include_ref(refname, send_filter_regex, send_is_inclusion_filter):
- continue
- changes.append(
- ReferenceChange.create(environment, oldrev, newrev, refname)
- )
- if not changes:
- mailer.close()
- return
- push = Push(environment, changes)
- try:
- push.send_emails(mailer, body_filter=environment.filter_body)
- finally:
- mailer.close()
-
-
-def run_as_update_hook(environment, mailer, refname, oldrev, newrev, force_send=False):
- environment.check()
- send_filter_regex, send_is_inclusion_filter = environment.get_ref_filter_regex(True)
- ref_filter_regex, is_inclusion_filter = environment.get_ref_filter_regex(False)
- if not include_ref(refname, ref_filter_regex, is_inclusion_filter):
- return
- if not include_ref(refname, send_filter_regex, send_is_inclusion_filter):
- return
- changes = [
- ReferenceChange.create(
- environment,
- read_git_output(['rev-parse', '--verify', oldrev]),
- read_git_output(['rev-parse', '--verify', newrev]),
- refname,
- ),
- ]
- if not changes:
- mailer.close()
- return
- push = Push(environment, changes, force_send)
- try:
- push.send_emails(mailer, body_filter=environment.filter_body)
- finally:
- mailer.close()
-
-
-def check_ref_filter(environment):
- send_filter_regex, send_is_inclusion = environment.get_ref_filter_regex(True)
- ref_filter_regex, ref_is_inclusion = environment.get_ref_filter_regex(False)
-
- def inc_exc_lusion(b):
- if b:
- return 'inclusion'
- else:
- return 'exclusion'
-
- if send_filter_regex:
- sys.stdout.write("DoSend/DontSend filter regex (" +
- (inc_exc_lusion(send_is_inclusion)) +
- '): ' + send_filter_regex.pattern +
- '\n')
- if send_filter_regex:
- sys.stdout.write("Include/Exclude filter regex (" +
- (inc_exc_lusion(ref_is_inclusion)) +
- '): ' + ref_filter_regex.pattern +
- '\n')
- sys.stdout.write(os.linesep)
-
- sys.stdout.write(
- "Refs marked as EXCLUDE are excluded by either refFilterInclusionRegex\n"
- "or refFilterExclusionRegex. No emails will be sent for commits included\n"
- "in these refs.\n"
- "Refs marked as DONT-SEND are excluded by either refFilterDoSendRegex or\n"
- "refFilterDontSendRegex, but not by either refFilterInclusionRegex or\n"
- "refFilterExclusionRegex. Emails will be sent for commits included in these\n"
- "refs only when the commit reaches a ref which isn't excluded.\n"
- "Refs marked as DO-SEND are not excluded by any filter. Emails will\n"
- "be sent normally for commits included in these refs.\n")
-
- sys.stdout.write(os.linesep)
-
- for refname in read_git_lines(['for-each-ref', '--format', '%(refname)']):
- sys.stdout.write(refname)
- if not include_ref(refname, ref_filter_regex, ref_is_inclusion):
- sys.stdout.write(' EXCLUDE')
- elif not include_ref(refname, send_filter_regex, send_is_inclusion):
- sys.stdout.write(' DONT-SEND')
- else:
- sys.stdout.write(' DO-SEND')
-
- sys.stdout.write(os.linesep)
-
-
-def show_env(environment, out):
- out.write('Environment values:\n')
- for (k, v) in sorted(environment.get_values().items()):
- if k: # Don't show the {'' : ''} pair.
- out.write(' %s : %r\n' % (k, v))
- out.write('\n')
- # Flush to avoid interleaving with further log output
- out.flush()
-
-
-def check_setup(environment):
- environment.check()
- show_env(environment, sys.stdout)
- sys.stdout.write("Now, checking that git-multimail's standard input "
- "is properly set ..." + os.linesep)
- sys.stdout.write("Please type some text and then press Return" + os.linesep)
- stdin = sys.stdin.readline()
- sys.stdout.write("You have just entered:" + os.linesep)
- sys.stdout.write(stdin)
- sys.stdout.write("git-multimail seems properly set up." + os.linesep)
-
-
-def choose_mailer(config, environment):
- mailer = config.get('mailer', default='sendmail')
-
- if mailer == 'smtp':
- smtpserver = config.get('smtpserver', default='localhost')
- smtpservertimeout = float(config.get('smtpservertimeout', default=10.0))
- smtpserverdebuglevel = int(config.get('smtpserverdebuglevel', default=0))
- smtpencryption = config.get('smtpencryption', default='none')
- smtpuser = config.get('smtpuser', default='')
- smtppass = config.get('smtppass', default='')
- smtpcacerts = config.get('smtpcacerts', default='')
- mailer = SMTPMailer(
- environment,
- envelopesender=(environment.get_sender() or environment.get_fromaddr()),
- smtpserver=smtpserver, smtpservertimeout=smtpservertimeout,
- smtpserverdebuglevel=smtpserverdebuglevel,
- smtpencryption=smtpencryption,
- smtpuser=smtpuser,
- smtppass=smtppass,
- smtpcacerts=smtpcacerts
- )
- elif mailer == 'sendmail':
- command = config.get('sendmailcommand')
- if command:
- command = shlex.split(command)
- mailer = SendMailer(environment,
- command=command, envelopesender=environment.get_sender())
- else:
- environment.log_error(
- 'fatal: multimailhook.mailer is set to an incorrect value: "%s"\n' % mailer +
- 'please use one of "smtp" or "sendmail".'
- )
- sys.exit(1)
- return mailer
-
-
-KNOWN_ENVIRONMENTS = {
- 'generic': {'highprec': GenericEnvironmentMixin},
- 'gitolite': {'highprec': GitoliteEnvironmentHighPrecMixin,
- 'lowprec': GitoliteEnvironmentLowPrecMixin},
- 'stash': {'highprec': StashEnvironmentHighPrecMixin,
- 'lowprec': StashEnvironmentLowPrecMixin},
- 'gerrit': {'highprec': GerritEnvironmentHighPrecMixin,
- 'lowprec': GerritEnvironmentLowPrecMixin},
- }
-
-
-def choose_environment(config, osenv=None, env=None, recipients=None,
- hook_info=None):
- env_name = choose_environment_name(config, env, osenv)
- environment_klass = build_environment_klass(env_name)
- env = build_environment(environment_klass, env_name, config,
- osenv, recipients, hook_info)
- return env
-
-
-def choose_environment_name(config, env, osenv):
- if not osenv:
- osenv = os.environ
-
- if not env:
- env = config.get('environment')
-
- if not env:
- if 'GL_USER' in osenv and 'GL_REPO' in osenv:
- env = 'gitolite'
- else:
- env = 'generic'
- return env
-
-
-COMMON_ENVIRONMENT_MIXINS = [
- ConfigRecipientsEnvironmentMixin,
- CLIRecipientsEnvironmentMixin,
- ConfigRefFilterEnvironmentMixin,
- ProjectdescEnvironmentMixin,
- ConfigMaxlinesEnvironmentMixin,
- ComputeFQDNEnvironmentMixin,
- ConfigFilterLinesEnvironmentMixin,
- PusherDomainEnvironmentMixin,
- ConfigOptionsEnvironmentMixin,
- ]
-
-
-def build_environment_klass(env_name):
- if 'class' in KNOWN_ENVIRONMENTS[env_name]:
- return KNOWN_ENVIRONMENTS[env_name]['class']
-
- environment_mixins = []
- known_env = KNOWN_ENVIRONMENTS[env_name]
- if 'highprec' in known_env:
- high_prec_mixin = known_env['highprec']
- environment_mixins.append(high_prec_mixin)
- environment_mixins = environment_mixins + COMMON_ENVIRONMENT_MIXINS
- if 'lowprec' in known_env:
- low_prec_mixin = known_env['lowprec']
- environment_mixins.append(low_prec_mixin)
- environment_mixins.append(Environment)
- klass_name = env_name.capitalize() + 'Environment'
- environment_klass = type(
- klass_name,
- tuple(environment_mixins),
- {},
- )
- KNOWN_ENVIRONMENTS[env_name]['class'] = environment_klass
- return environment_klass
-
-
-GerritEnvironment = build_environment_klass('gerrit')
-StashEnvironment = build_environment_klass('stash')
-GitoliteEnvironment = build_environment_klass('gitolite')
-GenericEnvironment = build_environment_klass('generic')
-
-
-def build_environment(environment_klass, env, config,
- osenv, recipients, hook_info):
- environment_kw = {
- 'osenv': osenv,
- 'config': config,
- }
-
- if env == 'stash':
- environment_kw['user'] = hook_info['stash_user']
- environment_kw['repo'] = hook_info['stash_repo']
- elif env == 'gerrit':
- environment_kw['project'] = hook_info['project']
- environment_kw['submitter'] = hook_info['submitter']
- environment_kw['update_method'] = hook_info['update_method']
-
- environment_kw['cli_recipients'] = recipients
-
- return environment_klass(**environment_kw)
-
-
-def get_version():
- oldcwd = os.getcwd()
- try:
- try:
- os.chdir(os.path.dirname(os.path.realpath(__file__)))
- git_version = read_git_output(['describe', '--tags', 'HEAD'])
- if git_version == __version__:
- return git_version
- else:
- return '%s (%s)' % (__version__, git_version)
- except:
- pass
- finally:
- os.chdir(oldcwd)
- return __version__
-
-
-def compute_gerrit_options(options, args, required_gerrit_options,
- raw_refname):
- if None in required_gerrit_options:
- raise SystemExit("Error: Specify all of --oldrev, --newrev, --refname, "
- "and --project; or none of them.")
-
- if options.environment not in (None, 'gerrit'):
- raise SystemExit("Non-gerrit environments incompatible with --oldrev, "
- "--newrev, --refname, and --project")
- options.environment = 'gerrit'
-
- if args:
- raise SystemExit("Error: Positional parameters not allowed with "
- "--oldrev, --newrev, and --refname.")
-
- # Gerrit oddly omits 'refs/heads/' in the refname when calling
- # ref-updated hook; put it back.
- git_dir = get_git_dir()
- if (not os.path.exists(os.path.join(git_dir, raw_refname)) and
- os.path.exists(os.path.join(git_dir, 'refs', 'heads',
- raw_refname))):
- options.refname = 'refs/heads/' + options.refname
-
- # New revisions can appear in a gerrit repository either due to someone
- # pushing directly (in which case options.submitter will be set), or they
- # can press "Submit this patchset" in the web UI for some CR (in which
- # case options.submitter will not be set and gerrit will not have provided
- # us the information about who pressed the button).
- #
- # Note for the nit-picky: I'm lumping in REST API calls and the ssh
- # gerrit review command in with "Submit this patchset" button, since they
- # have the same effect.
- if options.submitter:
- update_method = 'pushed'
- # The submitter argument is almost an RFC 2822 email address; change it
- # from 'User Name (email@domain)' to 'User Name <email@domain>' so it is
- options.submitter = options.submitter.replace('(', '<').replace(')', '>')
- else:
- update_method = 'submitted'
- # Gerrit knew who submitted this patchset, but threw that information
- # away when it invoked this hook. However, *IF* Gerrit created a
- # merge to bring the patchset in (project 'Submit Type' is either
- # "Always Merge", or is "Merge if Necessary" and happens to be
- # necessary for this particular CR), then it will have the committer
- # of that merge be 'Gerrit Code Review' and the author will be the
- # person who requested the submission of the CR. Since this is fairly
- # likely for most gerrit installations (of a reasonable size), it's
- # worth the extra effort to try to determine the actual submitter.
- rev_info = read_git_lines(['log', '--no-walk', '--merges',
- '--format=%cN%n%aN <%aE>', options.newrev])
- if rev_info and rev_info[0] == 'Gerrit Code Review':
- options.submitter = rev_info[1]
-
- # We pass back refname, oldrev, newrev as args because then the
- # gerrit ref-updated hook is much like the git update hook
- return (options,
- [options.refname, options.oldrev, options.newrev],
- {'project': options.project, 'submitter': options.submitter,
- 'update_method': update_method})
-
-
-def check_hook_specific_args(options, args):
- raw_refname = options.refname
- # Convert each string option unicode for Python3.
- if PYTHON3:
- opts = ['environment', 'recipients', 'oldrev', 'newrev', 'refname',
- 'project', 'submitter', 'stash_user', 'stash_repo']
- for opt in opts:
- if not hasattr(options, opt):
- continue
- obj = getattr(options, opt)
- if obj:
- enc = obj.encode('utf-8', 'surrogateescape')
- dec = enc.decode('utf-8', 'replace')
- setattr(options, opt, dec)
-
- # First check for stash arguments
- if (options.stash_user is None) != (options.stash_repo is None):
- raise SystemExit("Error: Specify both of --stash-user and "
- "--stash-repo or neither.")
- if options.stash_user:
- options.environment = 'stash'
- return options, args, {'stash_user': options.stash_user,
- 'stash_repo': options.stash_repo}
-
- # Finally, check for gerrit specific arguments
- required_gerrit_options = (options.oldrev, options.newrev, options.refname,
- options.project)
- if required_gerrit_options != (None,) * 4:
- return compute_gerrit_options(options, args, required_gerrit_options,
- raw_refname)
-
- # No special options in use, just return what we started with
- return options, args, {}
-
-
-class Logger(object):
- def parse_verbose(self, verbose):
- if verbose > 0:
- return logging.DEBUG
- else:
- return logging.INFO
-
- def create_log_file(self, environment, name, path, verbosity):
- log_file = logging.getLogger(name)
- file_handler = logging.FileHandler(path)
- log_fmt = logging.Formatter("%(asctime)s [%(levelname)-5.5s] %(message)s")
- file_handler.setFormatter(log_fmt)
- log_file.addHandler(file_handler)
- log_file.setLevel(verbosity)
- return log_file
-
- def __init__(self, environment):
- self.environment = environment
- self.loggers = []
- stderr_log = logging.getLogger('git_multimail.stderr')
-
- class EncodedStderr(object):
- def write(self, x):
- write_str(sys.stderr, x)
-
- def flush(self):
- sys.stderr.flush()
-
- stderr_handler = logging.StreamHandler(EncodedStderr())
- stderr_log.addHandler(stderr_handler)
- stderr_log.setLevel(self.parse_verbose(environment.verbose))
- self.loggers.append(stderr_log)
-
- if environment.debug_log_file is not None:
- debug_log_file = self.create_log_file(
- environment, 'git_multimail.debug', environment.debug_log_file, logging.DEBUG)
- self.loggers.append(debug_log_file)
-
- if environment.log_file is not None:
- log_file = self.create_log_file(
- environment, 'git_multimail.file', environment.log_file, logging.INFO)
- self.loggers.append(log_file)
-
- if environment.error_log_file is not None:
- error_log_file = self.create_log_file(
- environment, 'git_multimail.error', environment.error_log_file, logging.ERROR)
- self.loggers.append(error_log_file)
-
- def info(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.info(msg, *args, **kwargs)
-
- def debug(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.debug(msg, *args, **kwargs)
-
- def warning(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.warning(msg, *args, **kwargs)
-
- def error(self, msg, *args, **kwargs):
- for l in self.loggers:
- l.error(msg, *args, **kwargs)
-
-
-def main(args):
- parser = optparse.OptionParser(
- description=__doc__,
- usage='%prog [OPTIONS]\n or: %prog [OPTIONS] REFNAME OLDREV NEWREV',
- )
-
- parser.add_option(
- '--environment', '--env', action='store', type='choice',
- choices=list(KNOWN_ENVIRONMENTS.keys()), default=None,
- help=(
- 'Choose type of environment is in use. Default is taken from '
- 'multimailhook.environment if set; otherwise "generic".'
- ),
- )
- parser.add_option(
- '--stdout', action='store_true', default=False,
- help='Output emails to stdout rather than sending them.',
- )
- parser.add_option(
- '--recipients', action='store', default=None,
- help='Set list of email recipients for all types of emails.',
- )
- parser.add_option(
- '--show-env', action='store_true', default=False,
- help=(
- 'Write to stderr the values determined for the environment '
- '(intended for debugging purposes), then proceed normally.'
- ),
- )
- parser.add_option(
- '--force-send', action='store_true', default=False,
- help=(
- 'Force sending refchange email when using as an update hook. '
- 'This is useful to work around the unreliable new commits '
- 'detection in this mode.'
- ),
- )
- parser.add_option(
- '-c', metavar="<name>=<value>", action='append',
- help=(
- 'Pass a configuration parameter through to git. The value given '
- 'will override values from configuration files. See the -c option '
- 'of git(1) for more details. (Only works with git >= 1.7.3)'
- ),
- )
- parser.add_option(
- '--version', '-v', action='store_true', default=False,
- help=(
- "Display git-multimail's version"
- ),
- )
-
- parser.add_option(
- '--python-version', action='store_true', default=False,
- help=(
- "Display the version of Python used by git-multimail"
- ),
- )
-
- parser.add_option(
- '--check-ref-filter', action='store_true', default=False,
- help=(
- 'List refs and show information on how git-multimail '
- 'will process them.'
- )
- )
-
- # The following options permit this script to be run as a gerrit
- # ref-updated hook. See e.g.
- # code.google.com/p/gerrit/source/browse/Documentation/config-hooks.txt
- # We suppress help for these items, since these are specific to gerrit,
- # and we don't want users directly using them any way other than how the
- # gerrit ref-updated hook is called.
- parser.add_option('--oldrev', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--newrev', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--refname', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--project', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--submitter', action='store', help=optparse.SUPPRESS_HELP)
-
- # The following allow this to be run as a stash asynchronous post-receive
- # hook (almost identical to a git post-receive hook but triggered also for
- # merges of pull requests from the UI). We suppress help for these items,
- # since these are specific to stash.
- parser.add_option('--stash-user', action='store', help=optparse.SUPPRESS_HELP)
- parser.add_option('--stash-repo', action='store', help=optparse.SUPPRESS_HELP)
-
- (options, args) = parser.parse_args(args)
- (options, args, hook_info) = check_hook_specific_args(options, args)
-
- if options.version:
- sys.stdout.write('git-multimail version ' + get_version() + '\n')
- return
-
- if options.python_version:
- sys.stdout.write('Python version ' + sys.version + '\n')
- return
-
- if options.c:
- Config.add_config_parameters(options.c)
-
- config = Config('multimailhook')
-
- environment = None
- try:
- environment = choose_environment(
- config, osenv=os.environ,
- env=options.environment,
- recipients=options.recipients,
- hook_info=hook_info,
- )
-
- if options.show_env:
- show_env(environment, sys.stderr)
-
- if options.stdout or environment.stdout:
- mailer = OutputMailer(sys.stdout, environment)
- else:
- mailer = choose_mailer(config, environment)
-
- must_check_setup = os.environ.get('GIT_MULTIMAIL_CHECK_SETUP')
- if must_check_setup == '':
- must_check_setup = False
- if options.check_ref_filter:
- check_ref_filter(environment)
- elif must_check_setup:
- check_setup(environment)
- # Dual mode: if arguments were specified on the command line, run
- # like an update hook; otherwise, run as a post-receive hook.
- elif args:
- if len(args) != 3:
- parser.error('Need zero or three non-option arguments')
- (refname, oldrev, newrev) = args
- environment.get_logger().debug(
- "run_as_update_hook: refname=%s, oldrev=%s, newrev=%s, force_send=%s" %
- (refname, oldrev, newrev, options.force_send))
- run_as_update_hook(environment, mailer, refname, oldrev, newrev, options.force_send)
- else:
- run_as_post_receive_hook(environment, mailer)
- except ConfigurationException:
- sys.exit(sys.exc_info()[1])
- except SystemExit:
- raise
- except Exception:
- t, e, tb = sys.exc_info()
- import traceback
- sys.stderr.write('\n') # Avoid mixing message with previous output
- msg = (
- 'Exception \'' + t.__name__ +
- '\' raised. Please report this as a bug to\n'
- 'https://github.com/git-multimail/git-multimail/issues\n'
- 'with the information below:\n\n'
- 'git-multimail version ' + get_version() + '\n'
- 'Python version ' + sys.version + '\n' +
- traceback.format_exc())
- try:
- environment.get_logger().error(msg)
- except:
- sys.stderr.write(msg)
- sys.exit(1)
-
-
-if __name__ == '__main__':
- main(sys.argv[1:])
diff --git a/contrib/hooks/multimail/migrate-mailhook-config b/contrib/hooks/multimail/migrate-mailhook-config
deleted file mode 100755
index 241ba22..0000000
--- a/contrib/hooks/multimail/migrate-mailhook-config
+++ /dev/null
@@ -1,274 +0,0 @@
-#! /usr/bin/env python
-
-"""Migrate a post-receive-email configuration to be usable with git_multimail.py.
-
-See README.migrate-from-post-receive-email for more information.
-
-"""
-
-import sys
-import optparse
-
-from git_multimail import CommandError
-from git_multimail import Config
-from git_multimail import read_output
-
-
-OLD_NAMES = [
- 'mailinglist',
- 'announcelist',
- 'envelopesender',
- 'emailprefix',
- 'showrev',
- 'emailmaxlines',
- 'diffopts',
- 'scancommitforcc',
- ]
-
-NEW_NAMES = [
- 'environment',
- 'reponame',
- 'mailinglist',
- 'refchangelist',
- 'commitlist',
- 'announcelist',
- 'announceshortlog',
- 'envelopesender',
- 'administrator',
- 'emailprefix',
- 'emailmaxlines',
- 'diffopts',
- 'emaildomain',
- 'scancommitforcc',
- ]
-
-
-INFO = """\
-
-SUCCESS!
-
-Your post-receive-email configuration has been converted to
-git-multimail format. Please see README and
-README.migrate-from-post-receive-email to learn about other
-git-multimail configuration possibilities.
-
-For example, git-multimail has the following new options with no
-equivalent in post-receive-email. You might want to read about them
-to see if they would be useful in your situation:
-
-"""
-
-
-def _check_old_config_exists(old):
- """Check that at least one old configuration value is set."""
-
- for name in OLD_NAMES:
- if name in old:
- return True
-
- return False
-
-
-def _check_new_config_clear(new):
- """Check that none of the new configuration names are set."""
-
- retval = True
- for name in NEW_NAMES:
- if name in new:
- if retval:
- sys.stderr.write('INFO: The following configuration values already exist:\n\n')
- sys.stderr.write(' "%s.%s"\n' % (new.section, name))
- retval = False
-
- return retval
-
-
-def erase_values(config, names):
- for name in names:
- if name in config:
- try:
- sys.stderr.write('...unsetting "%s.%s"\n' % (config.section, name))
- config.unset_all(name)
- except CommandError:
- sys.stderr.write(
- '\nWARNING: could not unset "%s.%s". '
- 'Perhaps it is not set at the --local level?\n\n'
- % (config.section, name)
- )
-
-
-def is_section_empty(section, local):
- """Return True iff the specified configuration section is empty.
-
- Iff local is True, use the --local option when invoking 'git
- config'."""
-
- if local:
- local_option = ['--local']
- else:
- local_option = []
-
- try:
- read_output(
- ['git', 'config'] +
- local_option +
- ['--get-regexp', '^%s\.' % (section,)]
- )
- except CommandError:
- t, e, traceback = sys.exc_info()
- if e.retcode == 1:
- # This means that no settings were found.
- return True
- else:
- raise
- else:
- return False
-
-
-def remove_section_if_empty(section):
- """If the specified configuration section is empty, delete it."""
-
- try:
- empty = is_section_empty(section, local=True)
- except CommandError:
- # Older versions of git do not support the --local option, so
- # if the first attempt fails, try without --local.
- try:
- empty = is_section_empty(section, local=False)
- except CommandError:
- sys.stderr.write(
- '\nINFO: If configuration section "%s.*" is empty, you might want '
- 'to delete it.\n\n'
- % (section,)
- )
- return
-
- if empty:
- sys.stderr.write('...removing section "%s.*"\n' % (section,))
- read_output(['git', 'config', '--remove-section', section])
- else:
- sys.stderr.write(
- '\nINFO: Configuration section "%s.*" still has contents. '
- 'It will not be deleted.\n\n'
- % (section,)
- )
-
-
-def migrate_config(strict=False, retain=False, overwrite=False):
- old = Config('hooks')
- new = Config('multimailhook')
- if not _check_old_config_exists(old):
- sys.exit(
- 'Your repository has no post-receive-email configuration. '
- 'Nothing to do.'
- )
- if not _check_new_config_clear(new):
- if overwrite:
- sys.stderr.write('\nWARNING: Erasing the above values...\n\n')
- erase_values(new, NEW_NAMES)
- else:
- sys.exit(
- '\nERROR: Refusing to overwrite existing values. Use the --overwrite\n'
- 'option to continue anyway.'
- )
-
- name = 'showrev'
- if name in old:
- msg = 'git-multimail does not support "%s.%s"' % (old.section, name,)
- if strict:
- sys.exit(
- 'ERROR: %s.\n'
- 'Please unset that value then try again, or run without --strict.'
- % (msg,)
- )
- else:
- sys.stderr.write('\nWARNING: %s (ignoring).\n\n' % (msg,))
-
- for name in ['mailinglist', 'announcelist']:
- if name in old:
- sys.stderr.write(
- '...copying "%s.%s" to "%s.%s"\n' % (old.section, name, new.section, name)
- )
- old_recipients = old.get_all(name, default=None)
- old_recipients = ', '.join(o.strip() for o in old_recipients)
- new.set_recipients(name, old_recipients)
-
- if strict:
- sys.stderr.write(
- '...setting "%s.commitlist" to the empty string\n' % (new.section,)
- )
- new.set_recipients('commitlist', '')
- sys.stderr.write(
- '...setting "%s.announceshortlog" to "true"\n' % (new.section,)
- )
- new.set('announceshortlog', 'true')
-
- for name in ['envelopesender', 'emailmaxlines', 'diffopts', 'scancommitforcc']:
- if name in old:
- sys.stderr.write(
- '...copying "%s.%s" to "%s.%s"\n' % (old.section, name, new.section, name)
- )
- new.set(name, old.get(name))
-
- name = 'emailprefix'
- if name in old:
- sys.stderr.write(
- '...copying "%s.%s" to "%s.%s"\n' % (old.section, name, new.section, name)
- )
- new.set(name, old.get(name))
- elif strict:
- sys.stderr.write(
- '...setting "%s.%s" to "[SCM]" to preserve old subject lines\n'
- % (new.section, name)
- )
- new.set(name, '[SCM]')
-
- if not retain:
- erase_values(old, OLD_NAMES)
- remove_section_if_empty(old.section)
-
- sys.stderr.write(INFO)
- for name in NEW_NAMES:
- if name not in OLD_NAMES:
- sys.stderr.write(' "%s.%s"\n' % (new.section, name,))
- sys.stderr.write('\n')
-
-
-def main(args):
- parser = optparse.OptionParser(
- description=__doc__,
- usage='%prog [OPTIONS]',
- )
-
- parser.add_option(
- '--strict', action='store_true', default=False,
- help=(
- 'Slavishly configure git-multimail as closely as possible to '
- 'the post-receive-email configuration. Default is to turn '
- 'on some new features that have no equivalent in post-receive-email.'
- ),
- )
- parser.add_option(
- '--retain', action='store_true', default=False,
- help=(
- 'Retain the post-receive-email configuration values. '
- 'Default is to delete them after the new values are set.'
- ),
- )
- parser.add_option(
- '--overwrite', action='store_true', default=False,
- help=(
- 'Overwrite any existing git-multimail configuration settings. '
- 'Default is to abort if such settings already exist.'
- ),
- )
-
- (options, args) = parser.parse_args(args)
-
- if args:
- parser.error('Unexpected arguments: %s' % (' '.join(args),))
-
- migrate_config(strict=options.strict, retain=options.retain, overwrite=options.overwrite)
-
-
-main(sys.argv[1:])
diff --git a/contrib/hooks/multimail/post-receive.example b/contrib/hooks/multimail/post-receive.example
deleted file mode 100755
index b9bb118..0000000
--- a/contrib/hooks/multimail/post-receive.example
+++ /dev/null
@@ -1,101 +0,0 @@
-#! /usr/bin/env python
-
-"""Example post-receive hook based on git-multimail.
-
-The simplest way to use git-multimail is to use the script
-git_multimail.py directly as a post-receive hook, and to configure it
-using Git's configuration files and command-line parameters. You can
-also write your own Python wrapper for more advanced configurability,
-using git_multimail.py as a Python module.
-
-This script is a simple example of such a post-receive hook. It is
-intended to be customized before use; see the comments in the script
-to help you get started.
-
-Using git-multimail as a Python module as done here provides more
-flexibility. It has the following advantages:
-
-* The tool's behavior can be customized using arbitrary Python code,
- without having to edit git_multimail.py.
-
-* Configuration settings can be read from other sources; for example,
- user names and email addresses could be read from LDAP or from a
- database. Or the settings can even be hardcoded in the importing
- Python script, if this is preferred.
-
-This script is a very basic example of how to use git_multimail.py as
-a module. The comments below explain some of the points at which the
-script's behavior could be changed or customized.
-
-"""
-
-import sys
-
-# If necessary, add the path to the directory containing
-# git_multimail.py to the Python path as follows. (This is not
-# necessary if git_multimail.py is in the same directory as this
-# script):
-
-#LIBDIR = 'path/to/directory/containing/module'
-#sys.path.insert(0, LIBDIR)
-
-import git_multimail
-
-# It is possible to modify the output templates here; e.g.:
-
-#git_multimail.FOOTER_TEMPLATE = """\
-#
-#-- \n\
-#This email was generated by the wonderful git-multimail tool.
-#"""
-
-
-# Specify which "git config" section contains the configuration for
-# git-multimail:
-config = git_multimail.Config('multimailhook')
-
-# Set some Git configuration variables. Equivalent to passing var=val
-# to "git -c var=val" each time git is called, or to adding the
-# configuration in .git/config (must come before instanciating the
-# environment) :
-#git_multimail.Config.add_config_parameters('multimailhook.commitEmailFormat=html')
-#git_multimail.Config.add_config_parameters(('user.name=foo', 'user.email=foo@example.com'))
-
-# Select the type of environment:
-try:
- environment = git_multimail.GenericEnvironment(config=config)
- #environment = git_multimail.GitoliteEnvironment(config=config)
-except git_multimail.ConfigurationException:
- sys.stderr.write('*** %s\n' % sys.exc_info()[1])
- sys.exit(1)
-
-
-# Choose the method of sending emails based on the git config:
-mailer = git_multimail.choose_mailer(config, environment)
-
-# Alternatively, you may hardcode the mailer using code like one of
-# the following:
-
-# Use "/usr/sbin/sendmail -oi -t" to send emails. The envelopesender
-# argument is optional:
-#mailer = git_multimail.SendMailer(
-# command=['/usr/sbin/sendmail', '-oi', '-t'],
-# envelopesender='git-repo@example.com',
-# )
-
-# Use Python's smtplib to send emails. Both arguments are required.
-#mailer = git_multimail.SMTPMailer(
-# environment=environment,
-# envelopesender='git-repo@example.com',
-# # The smtpserver argument can also include a port number; e.g.,
-# # smtpserver='mail.example.com:25'
-# smtpserver='mail.example.com',
-# )
-
-# OutputMailer is intended only for testing; it writes the emails to
-# the specified file stream.
-#mailer = git_multimail.OutputMailer(sys.stdout)
-
-
-# Read changes from stdin and send notification emails:
-git_multimail.run_as_post_receive_hook(environment, mailer)
diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email
index 8747b84..ff565eb 100755
--- a/contrib/hooks/post-receive-email
+++ b/contrib/hooks/post-receive-email
@@ -329,7 +329,7 @@ generate_update_branch_email()
#
# git rev-parse --not --all | grep -v $(git rev-parse $refname)
#
- # Get's us to something pretty safe (apart from the small time
+ # Gets us to something pretty safe (apart from the small time
# between refname being read, and git rev-parse running - for that,
# I give up)
#
diff --git a/contrib/hooks/update-paranoid b/contrib/hooks/update-paranoid
index d18b317..0092d67 100755
--- a/contrib/hooks/update-paranoid
+++ b/contrib/hooks/update-paranoid
@@ -49,7 +49,7 @@ opcode.
Repository sections are matched on the basename of the repository
(after removing the .git suffix).
-The opcode abbrevations are:
+The opcode abbreviations are:
C: create new ref
D: delete existing ref
diff --git a/contrib/mw-to-git/.perlcriticrc b/contrib/mw-to-git/.perlcriticrc
index 158958d..b733326 100644
--- a/contrib/mw-to-git/.perlcriticrc
+++ b/contrib/mw-to-git/.perlcriticrc
@@ -14,7 +14,7 @@
# This rule states that each system call should have its return value checked
# The problem is that it includes the print call. Checking every print call's
-# return value would be harmful to the code readabilty.
+# return value would be harmful to the code readability.
# This configuration keeps all default function but print.
[InputOutput::RequireCheckedSyscalls]
functions = open say close
diff --git a/contrib/mw-to-git/Git/Mediawiki.pm b/contrib/mw-to-git/Git/Mediawiki.pm
index 917d9e2..ff78112 100644
--- a/contrib/mw-to-git/Git/Mediawiki.pm
+++ b/contrib/mw-to-git/Git/Mediawiki.pm
@@ -1,6 +1,6 @@
package Git::Mediawiki;
-use 5.008;
+use 5.008001;
use strict;
use POSIX;
use Git;
diff --git a/contrib/mw-to-git/git-mw.perl b/contrib/mw-to-git/git-mw.perl
index 28df3ee..eb52a53 100755
--- a/contrib/mw-to-git/git-mw.perl
+++ b/contrib/mw-to-git/git-mw.perl
@@ -6,7 +6,7 @@
# License: GPL v2 or later
# Set of tools for git repo with a mediawiki remote.
-# Documentation & bugtracker: https://github.com/moy/Git-Mediawiki/
+# Documentation & bugtracker: https://github.com/Git-Mediawiki/Git-Mediawiki
use strict;
use warnings;
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index af9cbc9..a562441 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -9,7 +9,7 @@
# License: GPL v2 or later
# Gateway between Git and MediaWiki.
-# Documentation & bugtracker: https://github.com/moy/Git-Mediawiki/
+# Documentation & bugtracker: https://github.com/Git-Mediawiki/Git-Mediawiki
use strict;
use MediaWiki::API;
@@ -56,38 +56,38 @@ my $url = $ARGV[1];
# Accept both space-separated and multiple keys in config file.
# Spaces should be written as _ anyway because we'll use chomp.
-my @tracked_pages = split(/[ \n]/, run_git("config --get-all remote.${remotename}.pages"));
+my @tracked_pages = split(/[ \n]/, run_git_quoted(["config", "--get-all", "remote.${remotename}.pages"]));
chomp(@tracked_pages);
# Just like @tracked_pages, but for MediaWiki categories.
-my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.${remotename}.categories"));
+my @tracked_categories = split(/[ \n]/, run_git_quoted(["config", "--get-all", "remote.${remotename}.categories"]));
chomp(@tracked_categories);
# Just like @tracked_categories, but for MediaWiki namespaces.
-my @tracked_namespaces = split(/[ \n]/, run_git("config --get-all remote.${remotename}.namespaces"));
+my @tracked_namespaces = split(/[ \n]/, run_git_quoted(["config", "--get-all", "remote.${remotename}.namespaces"]));
for (@tracked_namespaces) { s/_/ /g; }
chomp(@tracked_namespaces);
# Import media files on pull
-my $import_media = run_git("config --get --bool remote.${remotename}.mediaimport");
+my $import_media = run_git_quoted(["config", "--get", "--bool", "remote.${remotename}.mediaimport"]);
chomp($import_media);
$import_media = ($import_media eq 'true');
# Export media files on push
-my $export_media = run_git("config --get --bool remote.${remotename}.mediaexport");
+my $export_media = run_git_quoted(["config", "--get", "--bool", "remote.${remotename}.mediaexport"]);
chomp($export_media);
$export_media = !($export_media eq 'false');
-my $wiki_login = run_git("config --get remote.${remotename}.mwLogin");
-# Note: mwPassword is discourraged. Use the credential system instead.
-my $wiki_passwd = run_git("config --get remote.${remotename}.mwPassword");
-my $wiki_domain = run_git("config --get remote.${remotename}.mwDomain");
+my $wiki_login = run_git_quoted(["config", "--get", "remote.${remotename}.mwLogin"]);
+# Note: mwPassword is discouraged. Use the credential system instead.
+my $wiki_passwd = run_git_quoted(["config", "--get", "remote.${remotename}.mwPassword"]);
+my $wiki_domain = run_git_quoted(["config", "--get", "remote.${remotename}.mwDomain"]);
chomp($wiki_login);
chomp($wiki_passwd);
chomp($wiki_domain);
# Import only last revisions (both for clone and fetch)
-my $shallow_import = run_git("config --get --bool remote.${remotename}.shallow");
+my $shallow_import = run_git_quoted(["config", "--get", "--bool", "remote.${remotename}.shallow"]);
chomp($shallow_import);
$shallow_import = ($shallow_import eq 'true');
@@ -97,9 +97,9 @@ $shallow_import = ($shallow_import eq 'true');
# Possible values:
# - by_rev: perform one query per new revision on the remote wiki
# - by_page: query each tracked page for new revision
-my $fetch_strategy = run_git("config --get remote.${remotename}.fetchStrategy");
+my $fetch_strategy = run_git_quoted(["config", "--get", "remote.${remotename}.fetchStrategy"]);
if (!$fetch_strategy) {
- $fetch_strategy = run_git('config --get mediawiki.fetchStrategy');
+ $fetch_strategy = run_git_quoted(["config", "--get", "mediawiki.fetchStrategy"]);
}
chomp($fetch_strategy);
if (!$fetch_strategy) {
@@ -123,9 +123,9 @@ my %basetimestamps;
# will get the history with information lost). If the import is
# deterministic, this means everybody gets the same sha1 for each
# MediaWiki revision.
-my $dumb_push = run_git("config --get --bool remote.${remotename}.dumbPush");
+my $dumb_push = run_git_quoted(["config", "--get", "--bool", "remote.${remotename}.dumbPush"]);
if (!$dumb_push) {
- $dumb_push = run_git('config --get --bool mediawiki.dumbPush');
+ $dumb_push = run_git_quoted(["config", "--get", "--bool", "mediawiki.dumbPush"]);
}
chomp($dumb_push);
$dumb_push = ($dumb_push eq 'true');
@@ -369,12 +369,14 @@ sub get_mw_pages {
return %pages;
}
-# usage: $out = run_git("command args");
-# $out = run_git("command args", "raw"); # don't interpret output as UTF-8.
-sub run_git {
+# usage: $out = run_git_quoted(["command", "args", ...]);
+# $out = run_git_quoted(["command", "args", ...], "raw"); # don't interpret output as UTF-8.
+# $out = run_git_quoted_nostderr(["command", "args", ...]); # discard stderr
+# $out = run_git_quoted_nostderr(["command", "args", ...], "raw"); # ditto but raw instead of UTF-8 as above
+sub _run_git {
my $args = shift;
my $encoding = (shift || 'encoding(UTF-8)');
- open(my $git, "-|:${encoding}", "git ${args}")
+ open(my $git, "-|:${encoding}", @$args)
or die "Unable to fork: $!\n";
my $res = do {
local $/ = undef;
@@ -385,6 +387,13 @@ sub run_git {
return $res;
}
+sub run_git_quoted {
+ _run_git(["git", @{$_[0]}], $_[1]);
+}
+
+sub run_git_quoted_nostderr {
+ _run_git(['sh', '-c', 'git "$@" 2>/dev/null', '--', @{$_[0]}], $_[1]);
+}
sub get_all_mediafiles {
my $pages = shift;
@@ -511,8 +520,9 @@ sub download_mw_mediafile {
}
sub get_last_local_revision {
- # Get note regarding last mediawiki revision
- my $note = run_git("notes --ref=${remotename}/mediawiki show refs/mediawiki/${remotename}/master 2>/dev/null");
+ # Get note regarding last mediawiki revision.
+ my $note = run_git_quoted_nostderr(["notes", "--ref=${remotename}/mediawiki",
+ "show", "refs/mediawiki/${remotename}/master"]);
my @note_info = split(/ /, $note);
my $lastrevision_number;
@@ -807,7 +817,10 @@ sub get_more_refs {
sub mw_import {
# multiple import commands can follow each other.
my @refs = (shift, get_more_refs('import'));
+ my $processedRefs;
foreach my $ref (@refs) {
+ next if $processedRefs->{$ref}; # skip duplicates: "import refs/heads/master" being issued twice; TODO: why?
+ $processedRefs->{$ref} = 1;
mw_import_ref($ref);
}
print {*STDOUT} "done\n";
@@ -970,7 +983,7 @@ sub mw_import_revids {
}
sub error_non_fast_forward {
- my $advice = run_git('config --bool advice.pushNonFastForward');
+ my $advice = run_git_quoted(["config", "--bool", "advice.pushNonFastForward"]);
chomp($advice);
if ($advice ne 'false') {
# Native git-push would show this after the summary.
@@ -1014,7 +1027,7 @@ sub mw_upload_file {
}
} else {
# Don't let perl try to interpret file content as UTF-8 => use "raw"
- my $content = run_git("cat-file blob ${new_sha1}", 'raw');
+ my $content = run_git_quoted(["cat-file", "blob", $new_sha1], 'raw');
if ($content ne EMPTY) {
$mediawiki = connect_maybe($mediawiki, $remotename, $url);
$mediawiki->{config}->{upload_url} =
@@ -1084,7 +1097,7 @@ sub mw_push_file {
# with this content instead:
$file_content = DELETED_CONTENT;
} else {
- $file_content = run_git("cat-file blob ${new_sha1}");
+ $file_content = run_git_quoted(["cat-file", "blob", $new_sha1]);
}
$mediawiki = connect_maybe($mediawiki, $remotename, $url);
@@ -1174,10 +1187,10 @@ sub mw_push_revision {
my $mw_revision = $last_remote_revid;
# Get sha1 of commit pointed by local HEAD
- my $HEAD_sha1 = run_git("rev-parse ${local} 2>/dev/null");
+ my $HEAD_sha1 = run_git_quoted_nostderr(["rev-parse", $local]);
chomp($HEAD_sha1);
# Get sha1 of commit pointed by remotes/$remotename/master
- my $remoteorigin_sha1 = run_git("rev-parse refs/remotes/${remotename}/master 2>/dev/null");
+ my $remoteorigin_sha1 = run_git_quoted_nostderr(["rev-parse", "refs/remotes/${remotename}/master"]);
chomp($remoteorigin_sha1);
if ($last_local_revid > 0 &&
@@ -1197,7 +1210,7 @@ sub mw_push_revision {
my $parsed_sha1 = $remoteorigin_sha1;
# Find a path from last MediaWiki commit to pushed commit
print {*STDERR} "Computing path from local to remote ...\n";
- my @local_ancestry = split(/\n/, run_git("rev-list --boundary --parents ${local} ^${parsed_sha1}"));
+ my @local_ancestry = split(/\n/, run_git_quoted(["rev-list", "--boundary", "--parents", $local, "^${parsed_sha1}"]));
my %local_ancestry;
foreach my $line (@local_ancestry) {
if (my ($child, $parents) = $line =~ /^-?([a-f0-9]+) ([a-f0-9 ]+)/) {
@@ -1221,7 +1234,7 @@ sub mw_push_revision {
# No remote mediawiki revision. Export the whole
# history (linearized with --first-parent)
print {*STDERR} "Warning: no common ancestor, pushing complete history\n";
- my $history = run_git("rev-list --first-parent --children ${local}");
+ my $history = run_git_quoted(["rev-list", "--first-parent", "--children", $local]);
my @history = split(/\n/, $history);
@history = @history[1..$#history];
foreach my $line (reverse @history) {
@@ -1233,12 +1246,12 @@ sub mw_push_revision {
foreach my $commit_info_split (@commit_pairs) {
my $sha1_child = @{$commit_info_split}[0];
my $sha1_commit = @{$commit_info_split}[1];
- my $diff_infos = run_git("diff-tree -r --raw -z ${sha1_child} ${sha1_commit}");
+ my $diff_infos = run_git_quoted(["diff-tree", "-r", "--raw", "-z", $sha1_child, $sha1_commit]);
# TODO: we could detect rename, and encode them with a #redirect on the wiki.
# TODO: for now, it's just a delete+add
my @diff_info_list = split(/\0/, $diff_infos);
# Keep the subject line of the commit message as mediawiki comment for the revision
- my $commit_msg = run_git(qq(log --no-walk --format="%s" ${sha1_commit}));
+ my $commit_msg = run_git_quoted(["log", "--no-walk", '--format="%s"', $sha1_commit]);
chomp($commit_msg);
# Push every blob
while (@diff_info_list) {
@@ -1263,7 +1276,10 @@ sub mw_push_revision {
}
}
if (!$dumb_push) {
- run_git(qq(notes --ref=${remotename}/mediawiki add -f -m "mediawiki_revision: ${mw_revision}" ${sha1_commit}));
+ run_git_quoted(["notes", "--ref=${remotename}/mediawiki",
+ "add", "-f", "-m",
+ "mediawiki_revision: ${mw_revision}",
+ $sha1_commit]);
}
}
@@ -1304,7 +1320,7 @@ sub get_mw_namespace_id {
# already cached. Namespaces are stored in form:
# "Name_of_namespace:Id_namespace", ex.: "File:6".
my @temp = split(/\n/,
- run_git("config --get-all remote.${remotename}.namespaceCache"));
+ run_git_quoted(["config", "--get-all", "remote.${remotename}.namespaceCache"]));
chomp(@temp);
foreach my $ns (@temp) {
my ($n, $id) = split(/:/, $ns);
@@ -1358,7 +1374,7 @@ sub get_mw_namespace_id {
# Store explicitly requested namespaces on disk
if (!exists $cached_mw_namespace_id{$name}) {
- run_git(qq(config --add remote.${remotename}.namespaceCache "${name}:${store_id}"));
+ run_git_quoted(["config", "--add", "remote.${remotename}.namespaceCache", "${name}:${store_id}"]);
$cached_mw_namespace_id{$name} = 1;
}
return $id;
diff --git a/contrib/mw-to-git/git-remote-mediawiki.txt b/contrib/mw-to-git/git-remote-mediawiki.txt
index 23b7ef9..5da825f 100644
--- a/contrib/mw-to-git/git-remote-mediawiki.txt
+++ b/contrib/mw-to-git/git-remote-mediawiki.txt
@@ -4,4 +4,4 @@ objects from mediawiki just as one would do with a classic git
repository thanks to remote-helpers.
For more information, visit the wiki at
-https://github.com/moy/Git-Mediawiki/wiki
+https://github.com/Git-Mediawiki/Git-Mediawiki
diff --git a/contrib/mw-to-git/t/.gitignore b/contrib/mw-to-git/t/.gitignore
index a7a40b4..2b8dc30 100644
--- a/contrib/mw-to-git/t/.gitignore
+++ b/contrib/mw-to-git/t/.gitignore
@@ -1,4 +1,4 @@
WEB/
-wiki/
+mediawiki/
trash directory.t*/
test-results/
diff --git a/contrib/mw-to-git/t/README b/contrib/mw-to-git/t/README
index 2ee34be..72c4889 100644
--- a/contrib/mw-to-git/t/README
+++ b/contrib/mw-to-git/t/README
@@ -14,11 +14,11 @@ install the following packages (Debian/Ubuntu names, may need to be
adapted for another distribution):
* lighttpd
-* php5
-* php5-cgi
-* php5-cli
-* php5-curl
-* php5-sqlite
+* php
+* php-cgi
+* php-cli
+* php-curl
+* php-sqlite
Principles and Technical Choices
--------------------------------
diff --git a/contrib/mw-to-git/t/install-wiki/.gitignore b/contrib/mw-to-git/t/install-wiki/.gitignore
deleted file mode 100644
index b5a2a44..0000000
--- a/contrib/mw-to-git/t/install-wiki/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-wikidb.sqlite
diff --git a/contrib/mw-to-git/t/install-wiki/LocalSettings.php b/contrib/mw-to-git/t/install-wiki/LocalSettings.php
deleted file mode 100644
index 745e47e..0000000
--- a/contrib/mw-to-git/t/install-wiki/LocalSettings.php
+++ /dev/null
@@ -1,129 +0,0 @@
-<?php
-# This file was automatically generated by the MediaWiki 1.19.0
-# installer. If you make manual changes, please keep track in case you
-# need to recreate them later.
-#
-# See includes/DefaultSettings.php for all configurable settings
-# and their default values, but don't forget to make changes in _this_
-# file, not there.
-#
-# Further documentation for configuration settings may be found at:
-# http://www.mediawiki.org/wiki/Manual:Configuration_settings
-
-# Protect against web entry
-if ( !defined( 'MEDIAWIKI' ) ) {
- exit;
-}
-
-## Uncomment this to disable output compression
-# $wgDisableOutputCompression = true;
-
-$wgSitename = "Git-MediaWiki-Test";
-$wgMetaNamespace = "Git-MediaWiki-Test";
-
-## The URL base path to the directory containing the wiki;
-## defaults for all runtime URL paths are based off of this.
-## For more information on customizing the URLs please see:
-## http://www.mediawiki.org/wiki/Manual:Short_URL
-$wgScriptPath = "@WG_SCRIPT_PATH@";
-$wgScriptExtension = ".php";
-
-## The protocol and server name to use in fully-qualified URLs
-$wgServer = "@WG_SERVER@";
-
-## The relative URL path to the skins directory
-$wgStylePath = "$wgScriptPath/skins";
-
-## The relative URL path to the logo. Make sure you change this from the default,
-## or else you'll overwrite your logo when you upgrade!
-$wgLogo = "$wgStylePath/common/images/wiki.png";
-
-## UPO means: this is also a user preference option
-
-$wgEnableEmail = true;
-$wgEnableUserEmail = true; # UPO
-
-$wgEmergencyContact = "apache@localhost";
-$wgPasswordSender = "apache@localhost";
-
-$wgEnotifUserTalk = false; # UPO
-$wgEnotifWatchlist = false; # UPO
-$wgEmailAuthentication = true;
-
-## Database settings
-$wgDBtype = "sqlite";
-$wgDBserver = "";
-$wgDBname = "@WG_SQLITE_DATAFILE@";
-$wgDBuser = "";
-$wgDBpassword = "";
-
-# SQLite-specific settings
-$wgSQLiteDataDir = "@WG_SQLITE_DATADIR@";
-
-
-## Shared memory settings
-$wgMainCacheType = CACHE_NONE;
-$wgMemCachedServers = array();
-
-## To enable image uploads, make sure the 'images' directory
-## is writable, then set this to true:
-$wgEnableUploads = true;
-$wgUseImageMagick = true;
-$wgImageMagickConvertCommand ="@CONVERT@";
-$wgFileExtensions[] = 'txt';
-
-# InstantCommons allows wiki to use images from http://commons.wikimedia.org
-$wgUseInstantCommons = false;
-
-## If you use ImageMagick (or any other shell command) on a
-## Linux server, this will need to be set to the name of an
-## available UTF-8 locale
-$wgShellLocale = "en_US.utf8";
-
-## If you want to use image uploads under safe mode,
-## create the directories images/archive, images/thumb and
-## images/temp, and make them all writable. Then uncomment
-## this, if it's not already uncommented:
-#$wgHashedUploadDirectory = false;
-
-## Set $wgCacheDirectory to a writable directory on the web server
-## to make your wiki go slightly faster. The directory should not
-## be publicly accessible from the web.
-#$wgCacheDirectory = "$IP/cache";
-
-# Site language code, should be one of the list in ./languages/Names.php
-$wgLanguageCode = "en";
-
-$wgSecretKey = "1c912bfe3519fb70f5dc523ecc698111cd43d81a11c585b3eefb28f29c2699b7";
-#$wgSecretKey = "@SECRETKEY@";
-
-
-# Site upgrade key. Must be set to a string (default provided) to turn on the
-# web installer while LocalSettings.php is in place
-$wgUpgradeKey = "ddae7dc87cd0a645";
-
-## Default skin: you can change the default skin. Use the internal symbolic
-## names, ie 'standard', 'nostalgia', 'cologneblue', 'monobook', 'vector':
-$wgDefaultSkin = "vector";
-
-## For attaching licensing metadata to pages, and displaying an
-## appropriate copyright notice / icon. GNU Free Documentation
-## License and Creative Commons licenses are supported so far.
-$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
-$wgRightsUrl = "";
-$wgRightsText = "";
-$wgRightsIcon = "";
-
-# Path to the GNU diff3 utility. Used for conflict resolution.
-$wgDiff3 = "/usr/bin/diff3";
-
-# Query string length limit for ResourceLoader. You should only set this if
-# your web server has a query string length limit (then set it to that limit),
-# or if you have suhosin.get.max_value_length set in php.ini (then set it to
-# that value)
-$wgResourceLoaderMaxQueryLength = -1;
-
-
-
-# End of automatically generated settings.
-# Add more configuration options below.
diff --git a/contrib/mw-to-git/t/install-wiki/db_install.php b/contrib/mw-to-git/t/install-wiki/db_install.php
deleted file mode 100644
index 0f3f4e0..0000000
--- a/contrib/mw-to-git/t/install-wiki/db_install.php
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-/**
- * This script generates a SQLite database for a MediaWiki version 1.19.0
- * You must specify the login of the admin (argument 1) and its
- * password (argument 2) and the folder where the database file
- * is located (absolute path in argument 3).
- * It is used by the script install-wiki.sh in order to make easy the
- * installation of a MediaWiki.
- *
- * In order to generate a SQLite database file, MediaWiki ask the user
- * to submit some forms in its web browser. This script simulates this
- * behavior though the functions <get> and <submit>
- *
- */
-$argc = $_SERVER['argc'];
-$argv = $_SERVER['argv'];
-
-$login = $argv[2];
-$pass = $argv[3];
-$tmp = $argv[4];
-$port = $argv[5];
-
-$url = 'http://localhost:'.$port.'/wiki/mw-config/index.php';
-$db_dir = urlencode($tmp);
-$tmp_cookie = tempnam($tmp, "COOKIE_");
-/*
- * Fetchs a page with cURL.
- */
-function get($page_name = "") {
- $curl = curl_init();
- $page_name_add = "";
- if ($page_name != "") {
- $page_name_add = '?page='.$page_name;
- }
- $url = $GLOBALS['url'].$page_name_add;
- $tmp_cookie = $GLOBALS['tmp_cookie'];
- curl_setopt($curl, CURLOPT_COOKIEJAR, $tmp_cookie);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_COOKIEFILE, $tmp_cookie);
- curl_setopt($curl, CURLOPT_HEADER, true);
- curl_setopt($curl, CURLOPT_URL, $url);
-
- $page = curl_exec($curl);
- if (!$page) {
- die("Could not get page: $url\n");
- }
- curl_close($curl);
- return $page;
-}
-
-/*
- * Submits a form with cURL.
- */
-function submit($page_name, $option = "") {
- $curl = curl_init();
- $datapost = 'submit-continue=Continue+%E2%86%92';
- if ($option != "") {
- $datapost = $option.'&'.$datapost;
- }
- $url = $GLOBALS['url'].'?page='.$page_name;
- $tmp_cookie = $GLOBALS['tmp_cookie'];
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $datapost);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_COOKIEJAR, $tmp_cookie);
- curl_setopt($curl, CURLOPT_COOKIEFILE, $tmp_cookie);
-
- $page = curl_exec($curl);
- if (!$page) {
- die("Could not get page: $url\n");
- }
- curl_close($curl);
- return "$page";
-}
-
-/*
- * Here starts this script: simulates the behavior of the user
- * submitting forms to generates the database file.
- * Note this simulation was made for the MediaWiki version 1.19.0,
- * we can't assume it works with other versions.
- *
- */
-
-$page = get();
-if (!preg_match('/input type="hidden" value="([0-9]+)" name="LanguageRequestTime"/',
- $page, $matches)) {
- echo "Unexpected content for page downloaded:\n";
- echo "$page";
- die;
-};
-$timestamp = $matches[1];
-$language = "LanguageRequestTime=$timestamp&uselang=en&ContLang=en";
-$page = submit('Language', $language);
-
-submit('Welcome');
-
-$db_config = 'DBType=sqlite';
-$db_config = $db_config.'&sqlite_wgSQLiteDataDir='.$db_dir;
-$db_config = $db_config.'&sqlite_wgDBname='.$argv[1];
-submit('DBConnect', $db_config);
-
-$wiki_config = 'config_wgSitename=TEST';
-$wiki_config = $wiki_config.'&config__NamespaceType=site-name';
-$wiki_config = $wiki_config.'&config_wgMetaNamespace=MyWiki';
-$wiki_config = $wiki_config.'&config__AdminName='.$login;
-
-$wiki_config = $wiki_config.'&config__AdminPassword='.$pass;
-$wiki_config = $wiki_config.'&config__AdminPassword2='.$pass;
-
-$wiki_config = $wiki_config.'&wiki__configEmail=email%40email.org';
-$wiki_config = $wiki_config.'&config__SkipOptional=skip';
-submit('Name', $wiki_config);
-submit('Install');
-submit('Install');
-
-unlink($tmp_cookie);
-?>
diff --git a/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh b/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh
index cfbfe7d..f08890d 100755
--- a/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh
+++ b/contrib/mw-to-git/t/t9360-mw-to-git-clone.sh
@@ -28,7 +28,7 @@ test_expect_success 'Git clone creates the expected git log with one file' '
git log --format=%s HEAD^..HEAD >log.tmp
) &&
echo "this must be the same" >msg.tmp &&
- diff -b mw_dir_1/log.tmp msg.tmp
+ test_cmp msg.tmp mw_dir_1/log.tmp
'
@@ -50,8 +50,8 @@ test_expect_success 'Git clone creates the expected git log with multiple files'
echo "this must be the same" >>msgDaddy.tmp &&
echo "identical too" >msgDj.tmp &&
echo "identical" >>msgDj.tmp &&
- diff -b mw_dir_2/logDaddy.tmp msgDaddy.tmp &&
- diff -b mw_dir_2/logDj.tmp msgDj.tmp
+ test_cmp msgDaddy.tmp mw_dir_2/logDaddy.tmp &&
+ test_cmp msgDj.tmp mw_dir_2/logDj.tmp
'
@@ -86,7 +86,7 @@ test_expect_success 'Git clone works with page added' '
test_expect_success 'Git clone works with an edited page ' '
wiki_reset &&
wiki_editpage foo "this page will be edited" \
- false -s "first edition of page foo"&&
+ false -s "first edition of page foo" &&
wiki_editpage foo "this page has been edited and must be on the clone " true &&
git clone mediawiki::'"$WIKI_URL"' mw_dir_6 &&
test_path_is_file mw_dir_6/Foo.mw &&
@@ -135,7 +135,7 @@ test_expect_success 'Git clone works with one specific page cloned ' '
cd mw_dir_8 &&
echo "this log must stay" >msg.tmp &&
git log --format=%s >log.tmp &&
- diff -b msg.tmp log.tmp
+ test_cmp msg.tmp log.tmp
) &&
wiki_check_content mw_dir_8/Namnam.mw Namnam
'
@@ -143,7 +143,7 @@ test_expect_success 'Git clone works with one specific page cloned ' '
test_expect_success 'Git clone works with multiple specific page cloned ' '
wiki_reset &&
wiki_editpage foo "I will be there" false &&
- wiki_editpage bar "I will not disapear" false &&
+ wiki_editpage bar "I will not disappear" false &&
wiki_editpage namnam "I be erased" false &&
wiki_editpage nyancat "nyan nyan nyan you will not erase me" false &&
wiki_delete_page namnam &&
diff --git a/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh b/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
index 6b0dbda..526d928 100755
--- a/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
+++ b/contrib/mw-to-git/t/t9362-mw-to-git-utf8.sh
@@ -287,7 +287,7 @@ test_expect_success 'git push with \' '
git add \\ko\\o.mw &&
git commit -m " \\ko\\o added" &&
git push
- )&&
+ ) &&
wiki_page_exist \\ko\\o &&
wiki_check_content mw_dir_18/\\ko\\o.mw \\ko\\o
@@ -311,7 +311,7 @@ test_expect_success 'git push with \ in format control' '
git add \\fo\\o.mw &&
git commit -m " \\fo\\o added" &&
git push
- )&&
+ ) &&
wiki_page_exist \\fo\\o &&
wiki_check_content mw_dir_20/\\fo\\o.mw \\fo\\o
diff --git a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
index 3ff3a09..7139995 100755
--- a/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
+++ b/contrib/mw-to-git/t/t9363-mw-to-git-export-import.sh
@@ -27,12 +27,12 @@ test_git_reimport () {
# Don't bother with permissions, be administrator by default
test_expect_success 'setup config' '
- git config --global remote.origin.mwLogin WikiAdmin &&
- git config --global remote.origin.mwPassword AdminPass &&
+ git config --global remote.origin.mwLogin "$WIKI_ADMIN" &&
+ git config --global remote.origin.mwPassword "$WIKI_PASSW" &&
test_might_fail git config --global --unset remote.origin.mediaImport
'
-test_expect_success 'git push can upload media (File:) files' '
+test_expect_failure 'git push can upload media (File:) files' '
wiki_reset &&
git clone mediawiki::'"$WIKI_URL"' mw_dir &&
(
@@ -48,13 +48,14 @@ test_expect_success 'git push can upload media (File:) files' '
)
'
-test_expect_success 'git clone works on previously created wiki with media files' '
+test_expect_failure 'git clone works on previously created wiki with media files' '
test_when_finished "rm -rf mw_dir mw_dir_clone" &&
git clone -c remote.origin.mediaimport=true \
mediawiki::'"$WIKI_URL"' mw_dir_clone &&
test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt &&
(cd mw_dir_clone && git checkout HEAD^) &&
(cd mw_dir && git checkout HEAD^) &&
+ test_path_is_file mw_dir_clone/Foo.txt &&
test_cmp mw_dir_clone/Foo.txt mw_dir/Foo.txt
'
@@ -160,7 +161,7 @@ test_expect_success 'git push properly warns about insufficient permissions' '
git add foo.forbidden &&
git commit -m "add a file" &&
git push 2>actual &&
- test_i18ngrep "foo.forbidden is not a permitted file" actual
+ test_grep "foo.forbidden is not a permitted file" actual
)
'
diff --git a/contrib/mw-to-git/t/t9365-continuing-queries.sh b/contrib/mw-to-git/t/t9365-continuing-queries.sh
index 0164547..d3e7312 100755
--- a/contrib/mw-to-git/t/t9365-continuing-queries.sh
+++ b/contrib/mw-to-git/t/t9365-continuing-queries.sh
@@ -12,7 +12,7 @@ test_expect_success 'creating page w/ >500 revisions' '
for i in $(test_seq 501)
do
echo "creating revision $i" &&
- wiki_editpage foo "revision $i<br/>" true
+ wiki_editpage foo "revision $i<br/>" true || return 1
done
'
diff --git a/contrib/mw-to-git/t/test-gitmw-lib.sh b/contrib/mw-to-git/t/test-gitmw-lib.sh
index 6546294..64e46c1 100755
--- a/contrib/mw-to-git/t/test-gitmw-lib.sh
+++ b/contrib/mw-to-git/t/test-gitmw-lib.sh
@@ -13,7 +13,8 @@
. ./test.config
-WIKI_URL=http://"$SERVER_ADDR:$PORT/$WIKI_DIR_NAME"
+WIKI_BASE_URL=http://$SERVER_ADDR:$PORT
+WIKI_URL=$WIKI_BASE_URL/$WIKI_DIR_NAME
CURR_DIR=$(pwd)
TEST_OUTPUT_DIRECTORY=$(pwd)
TEST_DIRECTORY="$CURR_DIR"/../../../t
@@ -65,7 +66,7 @@ test_check_precond () {
GIT_EXEC_PATH=$(cd "$(dirname "$0")" && cd "../.." && pwd)
PATH="$GIT_EXEC_PATH"'/bin-wrapper:'"$PATH"
- if [ ! -d "$WIKI_DIR_INST/$WIKI_DIR_NAME" ];
+ if ! test -d "$WIKI_DIR_INST/$WIKI_DIR_NAME"
then
skip_all='skipping gateway git-mw tests, no mediawiki found'
test_done
@@ -279,7 +280,7 @@ start_lighttpd () {
"$LIGHTTPD_DIR"/lighttpd -f "$WEB"/lighttpd.conf
if test $? -ne 0 ; then
- echo "Could not execute http deamon lighttpd"
+ echo "Could not execute http daemon lighttpd"
exit 1
fi
}
@@ -291,27 +292,59 @@ stop_lighttpd () {
test -f "$WEB_TMP/pid" && kill $(cat "$WEB_TMP/pid")
}
-# Create the SQLite database of the MediaWiki. If the database file already
-# exists, it will be deleted.
-# This script should be runned from the directory where $FILES_FOLDER is
-# located.
-create_db () {
- rm -f "$TMP/$DB_FILE"
-
- echo "Generating the SQLite database file. It can take some time ..."
- # Run the php script to generate the SQLite database file
- # with cURL calls.
- php "$FILES_FOLDER/$DB_INSTALL_SCRIPT" $(basename "$DB_FILE" .sqlite) \
- "$WIKI_ADMIN" "$WIKI_PASSW" "$TMP" "$PORT"
-
- if [ ! -f "$TMP/$DB_FILE" ] ; then
- error "Can't create database file $TMP/$DB_FILE. Try to run ./install-wiki.sh delete first."
+wiki_delete_db () {
+ rm -rf \
+ "$FILES_FOLDER_DB"/* || error "Couldn't delete $FILES_FOLDER_DB/"
+}
+
+wiki_delete_db_backup () {
+ rm -rf \
+ "$FILES_FOLDER_POST_INSTALL_DB"/* || error "Couldn't delete $FILES_FOLDER_POST_INSTALL_DB/"
+}
+
+# Install MediaWiki using its install.php script. If the database file
+# already exists, it will be deleted.
+install_mediawiki () {
+
+ localsettings="$WIKI_DIR_INST/$WIKI_DIR_NAME/LocalSettings.php"
+ if test -f "$localsettings"
+ then
+ error "We already installed the wiki, since $localsettings exists" \
+ "perhaps you wanted to run 'delete' first?"
fi
- # Copy the generated database file into the directory the
- # user indicated.
- cp "$TMP/$DB_FILE" "$FILES_FOLDER" ||
- error "Unable to copy $TMP/$DB_FILE to $FILES_FOLDER"
+ wiki_delete_db
+ wiki_delete_db_backup
+ mkdir \
+ "$FILES_FOLDER_DB/" \
+ "$FILES_FOLDER_POST_INSTALL_DB/"
+
+ install_script="$WIKI_DIR_INST/$WIKI_DIR_NAME/maintenance/install.php"
+ echo "Installing MediaWiki using $install_script. This may take some time ..."
+
+ php "$WIKI_DIR_INST/$WIKI_DIR_NAME/maintenance/install.php" \
+ --server $WIKI_BASE_URL \
+ --scriptpath /wiki \
+ --lang en \
+ --dbtype sqlite \
+ --dbpath $PWD/$FILES_FOLDER_DB/ \
+ --pass "$WIKI_PASSW" \
+ Git-MediaWiki-Test \
+ "$WIKI_ADMIN" ||
+ error "Couldn't run $install_script, see errors above. Try to run ./install-wiki.sh delete first."
+ cat <<-'EOF' >>$localsettings
+# Custom settings added by test-gitmw-lib.sh
+#
+# Uploading text files is needed for
+# t9363-mw-to-git-export-import.sh
+$wgEnableUploads = true;
+$wgFileExtensions[] = 'txt';
+EOF
+
+ # Copy the initially generated database file into our backup
+ # folder
+ cp -R "$FILES_FOLDER_DB/"* "$FILES_FOLDER_POST_INSTALL_DB/" ||
+ error "Unable to copy $FILES_FOLDER_DB/* to $FILES_FOLDER_POST_INSTALL_DB/*"
}
# Install a wiki in your web server directory.
@@ -320,30 +353,33 @@ wiki_install () {
start_lighttpd
fi
- SERVER_ADDR=$SERVER_ADDR:$PORT
# In this part, we change directory to $TMP in order to download,
# unpack and copy the files of MediaWiki
(
mkdir -p "$WIKI_DIR_INST/$WIKI_DIR_NAME"
- if [ ! -d "$WIKI_DIR_INST/$WIKI_DIR_NAME" ] ; then
+ if ! test -d "$WIKI_DIR_INST/$WIKI_DIR_NAME"
+ then
error "Folder $WIKI_DIR_INST/$WIKI_DIR_NAME doesn't exist.
Please create it and launch the script again."
fi
- # Fetch MediaWiki's archive if not already present in the TMP directory
+ # Fetch MediaWiki's archive if not already present in the
+ # download directory
+ mkdir -p "$FILES_FOLDER_DOWNLOAD"
MW_FILENAME="mediawiki-$MW_VERSION_MAJOR.$MW_VERSION_MINOR.tar.gz"
- cd "$TMP"
- if [ ! -f $MW_FILENAME ] ; then
+ cd "$FILES_FOLDER_DOWNLOAD"
+ if ! test -f $MW_FILENAME
+ then
echo "Downloading $MW_VERSION_MAJOR.$MW_VERSION_MINOR sources ..."
wget "http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/$MW_FILENAME" ||
error "Unable to download "\
"http://download.wikimedia.org/mediawiki/$MW_VERSION_MAJOR/"\
"$MW_FILENAME. "\
"Please fix your connection and launch the script again."
- echo "$MW_FILENAME downloaded in $(pwd). "\
- "You can delete it later if you want."
+ echo "$MW_FILENAME downloaded in $(pwd)/;" \
+ "you can delete it later if you want."
else
- echo "Reusing existing $MW_FILENAME downloaded in $(pwd)."
+ echo "Reusing existing $MW_FILENAME downloaded in $(pwd)/"
fi
archive_abs_path=$(pwd)/$MW_FILENAME
cd "$WIKI_DIR_INST/$WIKI_DIR_NAME/" ||
@@ -352,48 +388,12 @@ wiki_install () {
error "Unable to extract WikiMedia's files from $archive_abs_path to "\
"$WIKI_DIR_INST/$WIKI_DIR_NAME"
) || exit 1
+ echo Extracted in "$WIKI_DIR_INST/$WIKI_DIR_NAME"
- create_db
-
- # Copy the generic LocalSettings.php in the web server's directory
- # And modify parameters according to the ones set at the top
- # of this script.
- # Note that LocalSettings.php is never modified.
- if [ ! -f "$FILES_FOLDER/LocalSettings.php" ] ; then
- error "Can't find $FILES_FOLDER/LocalSettings.php " \
- "in the current folder. "\
- "Please run the script inside its folder."
- fi
- cp "$FILES_FOLDER/LocalSettings.php" \
- "$FILES_FOLDER/LocalSettings-tmp.php" ||
- error "Unable to copy $FILES_FOLDER/LocalSettings.php " \
- "to $FILES_FOLDER/LocalSettings-tmp.php"
-
- # Parse and set the LocalSettings file of the user according to the
- # CONFIGURATION VARIABLES section at the beginning of this script
- file_swap="$FILES_FOLDER/LocalSettings-swap.php"
- sed "s,@WG_SCRIPT_PATH@,/$WIKI_DIR_NAME," \
- "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
- mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
- sed "s,@WG_SERVER@,http://$SERVER_ADDR," \
- "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
- mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
- sed "s,@WG_SQLITE_DATADIR@,$TMP," \
- "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
- mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
- sed "s,@WG_SQLITE_DATAFILE@,$( basename $DB_FILE .sqlite)," \
- "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
- mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
-
- mv "$FILES_FOLDER/LocalSettings-tmp.php" \
- "$WIKI_DIR_INST/$WIKI_DIR_NAME/LocalSettings.php" ||
- error "Unable to move $FILES_FOLDER/LocalSettings-tmp.php" \
- "in $WIKI_DIR_INST/$WIKI_DIR_NAME"
- echo "File $FILES_FOLDER/LocalSettings.php is set in" \
- " $WIKI_DIR_INST/$WIKI_DIR_NAME"
+ install_mediawiki
echo "Your wiki has been installed. You can check it at
- http://$SERVER_ADDR/$WIKI_DIR_NAME"
+ $WIKI_URL"
}
# Reset the database of the wiki and the password of the admin
@@ -401,12 +401,18 @@ wiki_install () {
# Warning: This function must be called only in a subdirectory of t/ directory
wiki_reset () {
# Copy initial database of the wiki
- if [ ! -f "../$FILES_FOLDER/$DB_FILE" ] ; then
- error "Can't find ../$FILES_FOLDER/$DB_FILE in the current folder."
+ if ! test -d "../$FILES_FOLDER_DB"
+ then
+ error "No wiki database at ../$FILES_FOLDER_DB, not installed yet?"
+ fi
+ if ! test -d "../$FILES_FOLDER_POST_INSTALL_DB"
+ then
+ error "No wiki backup database at ../$FILES_FOLDER_POST_INSTALL_DB, failed installation?"
fi
- cp "../$FILES_FOLDER/$DB_FILE" "$TMP" ||
- error "Can't copy ../$FILES_FOLDER/$DB_FILE in $TMP"
- echo "File $FILES_FOLDER/$DB_FILE is set in $TMP"
+ wiki_delete_db
+ cp -R "../$FILES_FOLDER_POST_INSTALL_DB/"* "../$FILES_FOLDER_DB/" ||
+ error "Can't copy ../$FILES_FOLDER_POST_INSTALL_DB/* to ../$FILES_FOLDER_DB/*"
+ echo "File $FILES_FOLDER_DB/* has been reset"
}
# Delete the wiki created in the web server's directory and all its content
@@ -420,13 +426,7 @@ wiki_delete () {
rm -rf "$WIKI_DIR_INST/$WIKI_DIR_NAME" ||
error "Wiki's directory $WIKI_DIR_INST/" \
"$WIKI_DIR_NAME could not be deleted"
- # Delete the wiki's SQLite database.
- rm -f "$TMP/$DB_FILE" ||
- error "Database $TMP/$DB_FILE could not be deleted."
fi
-
- # Delete the wiki's SQLite database
- rm -f "$TMP/$DB_FILE" || error "Database $TMP/$DB_FILE could not be deleted."
- rm -f "$FILES_FOLDER/$DB_FILE"
- rm -rf "$TMP/mediawiki-$MW_VERSION_MAJOR.$MW_VERSION_MINOR.tar.gz"
+ wiki_delete_db
+ wiki_delete_db_backup
}
diff --git a/contrib/mw-to-git/t/test-gitmw.pl b/contrib/mw-to-git/t/test-gitmw.pl
index 0ff7625..c5d687f 100755
--- a/contrib/mw-to-git/t/test-gitmw.pl
+++ b/contrib/mw-to-git/t/test-gitmw.pl
@@ -24,9 +24,7 @@
use MediaWiki::API;
use Getopt::Long;
-use encoding 'utf8';
use DateTime::Format::ISO8601;
-use open ':encoding(utf8)';
use constant SLASH_REPLACEMENT => "%2F";
#Parsing of the config file
@@ -87,7 +85,7 @@ sub wiki_getpage {
# Replace spaces by underscore in the page name
$pagename =~ s/ /_/g;
$pagename =~ s/\//%2F/g;
- open(my $file, ">$destdir/$pagename.mw");
+ open(my $file, ">:encoding(UTF-8)", "$destdir/$pagename.mw");
print $file "$content";
close ($file);
@@ -172,7 +170,7 @@ sub wiki_getallpagename {
cmlimit => 500 },
)
|| die $mw->{error}->{code}.": ".$mw->{error}->{details};
- open(my $file, ">all.txt");
+ open(my $file, ">:encoding(UTF-8)", "all.txt");
foreach my $page (@{$mw_pages}) {
print $file "$page->{title}\n";
}
@@ -185,7 +183,7 @@ sub wiki_getallpagename {
aplimit => 500,
})
|| die $mw->{error}->{code}.": ".$mw->{error}->{details};
- open(my $file, ">all.txt");
+ open(my $file, ">:encoding(UTF-8)", "all.txt");
foreach my $page (@{$mw_pages}) {
print $file "$page->{title}\n";
}
@@ -214,12 +212,12 @@ my $fct_to_call = shift;
wiki_login($wiki_admin, $wiki_admin_pass);
-my %functions_to_call = qw(
- upload_file wiki_upload_file
- get_page wiki_getpage
- delete_page wiki_delete_page
- edit_page wiki_editpage
- getallpagename wiki_getallpagename
+my %functions_to_call = (
+ upload_file => \&wiki_upload_file,
+ get_page => \&wiki_getpage,
+ delete_page => \&wiki_delete_page,
+ edit_page => \&wiki_editpage,
+ getallpagename => \&wiki_getallpagename,
);
die "$0 ERROR: wrong argument" unless exists $functions_to_call{$fct_to_call};
-&{$functions_to_call{$fct_to_call}}(@ARGV);
+$functions_to_call{$fct_to_call}->(map { utf8::decode($_); $_ } @ARGV);
diff --git a/contrib/mw-to-git/t/test.config b/contrib/mw-to-git/t/test.config
index 5ba0684..ed10b3e 100644
--- a/contrib/mw-to-git/t/test.config
+++ b/contrib/mw-to-git/t/test.config
@@ -3,15 +3,11 @@ WIKI_DIR_NAME=wiki
# Login and password of the wiki's admin
WIKI_ADMIN=WikiAdmin
-WIKI_PASSW=AdminPass
+WIKI_PASSW=AdminPass1
# Address of the web server
SERVER_ADDR=localhost
-# SQLite database of the wiki, named DB_FILE, is located in TMP
-TMP=/tmp
-DB_FILE=wikidb.sqlite
-
# If LIGHTTPD is not set to true, the script will use the default
# web server running in WIKI_DIR_INST.
WIKI_DIR_INST=/var/www
@@ -28,10 +24,17 @@ WEB=WEB
WEB_TMP=$WEB/tmp
WEB_WWW=$WEB/www
+# Where our configuration for the wiki is located
+FILES_FOLDER=mediawiki
+FILES_FOLDER_DOWNLOAD=$FILES_FOLDER/download
+FILES_FOLDER_DB=$FILES_FOLDER/db
+FILES_FOLDER_POST_INSTALL_DB=$FILES_FOLDER/post-install-db
+
# The variables below are used by the script to install a wiki.
# You should not modify these unless you are modifying the script itself.
-# tested versions: 1.19.X -> 1.21.1
-MW_VERSION_MAJOR=1.21
-MW_VERSION_MINOR=1
-FILES_FOLDER=install-wiki
-DB_INSTALL_SCRIPT=db_install.php
+# tested versions: 1.19.X -> 1.21.1 -> 1.34.2
+#
+# See https://www.mediawiki.org/wiki/Download for what the latest
+# version is.
+MW_VERSION_MAJOR=1.34
+MW_VERSION_MINOR=2
diff --git a/contrib/rerere-train.sh b/contrib/rerere-train.sh
index eeee45d..bd01e43 100755
--- a/contrib/rerere-train.sh
+++ b/contrib/rerere-train.sh
@@ -75,7 +75,7 @@ do
continue
fi
git checkout -q "$parent1^0"
- if git merge $other_parents >/dev/null 2>&1
+ if git merge --no-gpg-sign $other_parents >/dev/null 2>&1
then
# Cleanly merges
continue
@@ -86,12 +86,12 @@ do
fi
if test -s "$GIT_DIR/MERGE_RR"
then
- git show -s --pretty=format:"Learning from %h %s" "$commit"
+ git --no-pager show -s --format="Learning from %h %s" "$commit"
git rerere
git checkout -q $commit -- .
git rerere
fi
- git reset -q --hard
+ git reset -q --hard # Might nuke untracked files...
done
if test -z "$branch"
diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile
index 6906aae..6fa7496 100644
--- a/contrib/subtree/Makefile
+++ b/contrib/subtree/Makefile
@@ -25,14 +25,16 @@ ASCIIDOC_HTML = xhtml11
ASCIIDOC_DOCBOOK = docbook
ASCIIDOC_EXTRA =
XMLTO = xmlto
+XMLTO_EXTRA =
ifdef USE_ASCIIDOCTOR
ASCIIDOC = asciidoctor
ASCIIDOC_CONF =
ASCIIDOC_HTML = xhtml5
-ASCIIDOC_DOCBOOK = docbook45
+ASCIIDOC_DOCBOOK = docbook
ASCIIDOC_EXTRA += -I../../Documentation -rasciidoctor-extensions
ASCIIDOC_EXTRA += -alitdd='&\#x2d;&\#x2d;'
+XMLTO_EXTRA += --skip-validation
endif
ifndef SHELL_PATH
@@ -78,7 +80,7 @@ install-html: $(GIT_SUBTREE_HTML)
$(INSTALL) -m 644 $^ $(DESTDIR)$(htmldir)
$(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML)
- $(XMLTO) -m $(MANPAGE_XSL) man $^
+ $(XMLTO) -m $(MANPAGE_XSL) $(XMLTO_EXTRA) man $^
$(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT)
$(ASCIIDOC) -b $(ASCIIDOC_DOCBOOK) -d manpage $(ASCIIDOC_CONF) \
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 868e18b..5dab3f5 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -4,218 +4,293 @@
#
# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
#
-if test $# -eq 0
+
+if test -z "$GIT_EXEC_PATH" || ! test -f "$GIT_EXEC_PATH/git-sh-setup" || {
+ test "${PATH#"${GIT_EXEC_PATH}:"}" = "$PATH" &&
+ test ! "$GIT_EXEC_PATH" -ef "${PATH%%:*}" 2>/dev/null
+}
then
- set -- -h
+ basename=${0##*[/\\]}
+ echo >&2 'It looks like either your git installation or your'
+ echo >&2 'git-subtree installation is broken.'
+ echo >&2
+ echo >&2 "Tips:"
+ echo >&2 " - If \`git --exec-path\` does not print the correct path to"
+ echo >&2 " your git install directory, then set the GIT_EXEC_PATH"
+ echo >&2 " environment variable to the correct directory."
+ echo >&2 " - Make sure that your \`$basename\` file is either in your"
+ echo >&2 " PATH or in your git exec path (\`$(git --exec-path)\`)."
+ echo >&2 " - You should run git-subtree as \`git ${basename#git-}\`,"
+ echo >&2 " not as \`$basename\`." >&2
+ exit 126
fi
+
OPTS_SPEC="\
git subtree add --prefix=<prefix> <commit>
git subtree add --prefix=<prefix> <repository> <ref>
git subtree merge --prefix=<prefix> <commit>
+git subtree split --prefix=<prefix> [<commit>]
git subtree pull --prefix=<prefix> <repository> <ref>
-git subtree push --prefix=<prefix> <repository> <ref>
-git subtree split --prefix=<prefix> <commit>
+git subtree push --prefix=<prefix> <repository> <refspec>
--
-h,help show the help
-q quiet
-d show debug messages
+h,help! show the help
+q,quiet! quiet
+d,debug! show debug messages
P,prefix= the name of the subdir to split out
-m,message= use the given message as the commit message for the merge commit
- options for 'split'
+ options for 'split' (also: 'push')
annotate= add a prefix to commit message of new commits
-b,branch= create a new branch from the split subtree
+b,branch!= create a new branch from the split subtree
ignore-joins ignore prior --rejoin commits
onto= try connecting new tree to an existing one
rejoin merge the new branch back into HEAD
- options for 'add', 'merge', and 'pull'
+ options for 'add' and 'merge' (also: 'pull', 'split --rejoin', and 'push --rejoin')
squash merge subtree changes as a single commit
+m,message!= use the given message as the commit message for the merge commit
"
-eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
-PATH=$PATH:$(git --exec-path)
-. git-sh-setup
+indent=0
-require_work_tree
-
-quiet=
-branch=
-debug=
-command=
-onto=
-rejoin=
-ignore_joins=
-annotate=
-squash=
-message=
-prefix=
-
-debug () {
- if test -n "$debug"
+# Usage: say [MSG...]
+say () {
+ if test -z "$arg_quiet"
then
- printf "%s\n" "$*" >&2
+ printf '%s\n' "$*"
fi
}
-say () {
- if test -z "$quiet"
+# Usage: debug [MSG...]
+debug () {
+ if test -n "$arg_debug"
then
- printf "%s\n" "$*" >&2
+ printf "%$(($indent * 2))s%s\n" '' "$*" >&2
fi
}
+# Usage: progress [MSG...]
progress () {
- if test -z "$quiet"
+ if test -z "$arg_quiet"
then
- printf "%s\r" "$*" >&2
+ if test -z "$arg_debug"
+ then
+ # Debug mode is off.
+ #
+ # Print one progress line that we keep updating (use
+ # "\r" to return to the beginning of the line, rather
+ # than "\n" to start a new line). This only really
+ # works when stderr is a terminal.
+ printf "%s\r" "$*" >&2
+ else
+ # Debug mode is on. The `debug` function is regularly
+ # printing to stderr.
+ #
+ # Don't do the one-line-with-"\r" thing, because on a
+ # terminal the debug output would overwrite and hide the
+ # progress output. Add a "progress:" prefix to make the
+ # progress output and the debug output easy to
+ # distinguish. This ensures maximum readability whether
+ # stderr is a terminal or a file.
+ printf "progress: %s\n" "$*" >&2
+ fi
fi
}
+# Usage: assert CMD...
assert () {
if ! "$@"
then
- die "assertion failed: " "$@"
- fi
-}
-
-ensure_single_rev () {
- if test $# -ne 1
- then
- die "You must provide exactly one revision. Got: '$@'"
+ die "fatal: assertion failed: $*"
fi
}
-while test $# -gt 0
-do
+# Usage: die_incompatible_opt OPTION COMMAND
+die_incompatible_opt () {
+ assert test "$#" = 2
opt="$1"
- shift
+ arg_command="$2"
+ die "fatal: the '$opt' flag does not make sense with 'git subtree $arg_command'."
+}
- case "$opt" in
- -q)
- quiet=1
- ;;
- -d)
- debug=1
- ;;
- --annotate)
- annotate="$1"
- shift
- ;;
- --no-annotate)
- annotate=
- ;;
- -b)
- branch="$1"
- shift
- ;;
- -P)
- prefix="${1%/}"
+main () {
+ if test $# -eq 0
+ then
+ set -- -h
+ fi
+ set_args="$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
+ eval "$set_args"
+ . git-sh-setup
+ require_work_tree
+
+ # First figure out the command and whether we use --rejoin, so
+ # that we can provide more helpful validation when we do the
+ # "real" flag parsing.
+ arg_split_rejoin=
+ allow_split=
+ allow_addmerge=
+ while test $# -gt 0
+ do
+ opt="$1"
shift
+ case "$opt" in
+ --annotate|-b|-P|-m|--onto)
+ shift
+ ;;
+ --rejoin)
+ arg_split_rejoin=1
+ ;;
+ --no-rejoin)
+ arg_split_rejoin=
+ ;;
+ --)
+ break
+ ;;
+ esac
+ done
+ arg_command=$1
+ case "$arg_command" in
+ add|merge|pull)
+ allow_addmerge=1
;;
- -m)
- message="$1"
- shift
+ split|push)
+ allow_split=1
+ allow_addmerge=$arg_split_rejoin
;;
- --no-prefix)
- prefix=
+ *)
+ die "fatal: unknown command '$arg_command'"
;;
- --onto)
- onto="$1"
+ esac
+ # Reset the arguments array for "real" flag parsing.
+ eval "$set_args"
+
+ # Begin "real" flag parsing.
+ arg_quiet=
+ arg_debug=
+ arg_prefix=
+ arg_split_branch=
+ arg_split_onto=
+ arg_split_ignore_joins=
+ arg_split_annotate=
+ arg_addmerge_squash=
+ arg_addmerge_message=
+ while test $# -gt 0
+ do
+ opt="$1"
shift
- ;;
- --no-onto)
- onto=
- ;;
- --rejoin)
- rejoin=1
- ;;
- --no-rejoin)
- rejoin=
- ;;
- --ignore-joins)
- ignore_joins=1
- ;;
- --no-ignore-joins)
- ignore_joins=
- ;;
- --squash)
- squash=1
- ;;
- --no-squash)
- squash=
- ;;
- --)
- break
+
+ case "$opt" in
+ -q)
+ arg_quiet=1
+ ;;
+ -d)
+ arg_debug=1
+ ;;
+ --annotate)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ arg_split_annotate="$1"
+ shift
+ ;;
+ --no-annotate)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ arg_split_annotate=
+ ;;
+ -b)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ arg_split_branch="$1"
+ shift
+ ;;
+ -P)
+ arg_prefix="${1%/}"
+ shift
+ ;;
+ -m)
+ test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
+ arg_addmerge_message="$1"
+ shift
+ ;;
+ --no-prefix)
+ arg_prefix=
+ ;;
+ --onto)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ arg_split_onto="$1"
+ shift
+ ;;
+ --no-onto)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ arg_split_onto=
+ ;;
+ --rejoin)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ ;;
+ --no-rejoin)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ ;;
+ --ignore-joins)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ arg_split_ignore_joins=1
+ ;;
+ --no-ignore-joins)
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
+ arg_split_ignore_joins=
+ ;;
+ --squash)
+ test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
+ arg_addmerge_squash=1
+ ;;
+ --no-squash)
+ test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
+ arg_addmerge_squash=
+ ;;
+ --)
+ break
+ ;;
+ *)
+ die "fatal: unexpected option: $opt"
+ ;;
+ esac
+ done
+ shift
+
+ if test -z "$arg_prefix"
+ then
+ die "fatal: you must provide the --prefix option."
+ fi
+
+ case "$arg_command" in
+ add)
+ test -e "$arg_prefix" &&
+ die "fatal: prefix '$arg_prefix' already exists."
;;
*)
- die "Unexpected option: $opt"
+ test -e "$arg_prefix" ||
+ die "fatal: '$arg_prefix' does not exist; use 'git subtree add'"
;;
esac
-done
-
-command="$1"
-shift
-
-case "$command" in
-add|merge|pull)
- default=
- ;;
-split|push)
- default="--default HEAD"
- ;;
-*)
- die "Unknown command '$command'"
- ;;
-esac
-
-if test -z "$prefix"
-then
- die "You must provide the --prefix option."
-fi
-case "$command" in
-add)
- test -e "$prefix" &&
- die "prefix '$prefix' already exists."
- ;;
-*)
- test -e "$prefix" ||
- die "'$prefix' does not exist; use 'git subtree add'"
- ;;
-esac
-
-dir="$(dirname "$prefix/.")"
-
-if test "$command" != "pull" &&
- test "$command" != "add" &&
- test "$command" != "push"
-then
- revs=$(git rev-parse $default --revs-only "$@") || exit $?
- dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
- ensure_single_rev $revs
- if test -n "$dirs"
- then
- die "Error: Use --prefix instead of bare filenames."
- fi
-fi
+ dir="$(dirname "$arg_prefix/.")"
-debug "command: {$command}"
-debug "quiet: {$quiet}"
-debug "revs: {$revs}"
-debug "dir: {$dir}"
-debug "opts: {$*}"
-debug
+ debug "command: {$arg_command}"
+ debug "quiet: {$arg_quiet}"
+ debug "dir: {$dir}"
+ debug "opts: {$*}"
+ debug
+ "cmd_$arg_command" "$@"
+}
+
+# Usage: cache_setup
cache_setup () {
+ assert test $# = 0
cachedir="$GIT_DIR/subtree-cache/$$"
rm -rf "$cachedir" ||
- die "Can't delete old cachedir: $cachedir"
+ die "fatal: can't delete old cachedir: $cachedir"
mkdir -p "$cachedir" ||
- die "Can't create new cachedir: $cachedir"
+ die "fatal: can't create new cachedir: $cachedir"
mkdir -p "$cachedir/notree" ||
- die "Can't create new cachedir: $cachedir/notree"
+ die "fatal: can't create new cachedir: $cachedir/notree"
debug "Using cachedir: $cachedir" >&2
}
+# Usage: cache_get [REVS...]
cache_get () {
for oldrev in "$@"
do
@@ -227,6 +302,7 @@ cache_get () {
done
}
+# Usage: cache_miss [REVS...]
cache_miss () {
for oldrev in "$@"
do
@@ -237,36 +313,43 @@ cache_miss () {
done
}
+# Usage: check_parents [REVS...]
check_parents () {
- missed=$(cache_miss "$1")
- local indent=$(($2 + 1))
+ missed=$(cache_miss "$@") || exit $?
+ local indent=$(($indent + 1))
for miss in $missed
do
if ! test -r "$cachedir/notree/$miss"
then
- debug " incorrect order: $miss"
- process_split_commit "$miss" "" "$indent"
+ debug "incorrect order: $miss"
+ process_split_commit "$miss" ""
fi
done
}
+# Usage: set_notree REV
set_notree () {
+ assert test $# = 1
echo "1" > "$cachedir/notree/$1"
}
+# Usage: cache_set OLDREV NEWREV
cache_set () {
+ assert test $# = 2
oldrev="$1"
newrev="$2"
if test "$oldrev" != "latest_old" &&
test "$oldrev" != "latest_new" &&
test -e "$cachedir/$oldrev"
then
- die "cache for $oldrev already exists!"
+ die "fatal: cache for $oldrev already exists!"
fi
echo "$newrev" >"$cachedir/$oldrev"
}
+# Usage: rev_exists REV
rev_exists () {
+ assert test $# = 1
if git rev-parse "$1" >/dev/null 2>&1
then
return 0
@@ -275,33 +358,62 @@ rev_exists () {
fi
}
-rev_is_descendant_of_branch () {
- newrev="$1"
- branch="$2"
- branch_hash=$(git rev-parse "$branch")
- match=$(git rev-list -1 "$branch_hash" "^$newrev")
-
- if test -z "$match"
- then
- return 0
- else
- return 1
- fi
-}
-
-# if a commit doesn't have a parent, this might not work. But we only want
+# Usage: try_remove_previous REV
+#
+# If a commit doesn't have a parent, this might not work. But we only want
# to remove the parent from the rev-list, and since it doesn't exist, it won't
# be there anyway, so do nothing in that case.
try_remove_previous () {
+ assert test $# = 1
if rev_exists "$1^"
then
echo "^$1^"
fi
}
+# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY]
+process_subtree_split_trailer () {
+ assert test $# -ge 2
+ assert test $# -le 3
+ b="$1"
+ sq="$2"
+ repository=""
+ if test "$#" = 3
+ then
+ repository="$3"
+ fi
+ fail_msg="fatal: could not rev-parse split hash $b from commit $sq"
+ if ! sub="$(git rev-parse --verify --quiet "$b^{commit}")"
+ then
+ # if 'repository' was given, try to fetch the 'git-subtree-split' hash
+ # before 'rev-parse'-ing it again, as it might be a tag that we do not have locally
+ if test -n "${repository}"
+ then
+ git fetch "$repository" "$b"
+ sub="$(git rev-parse --verify --quiet "$b^{commit}")" ||
+ die "$fail_msg"
+ else
+ hint1=$(printf "hint: hash might be a tag, try fetching it from the subtree repository:")
+ hint2=$(printf "hint: git fetch <subtree-repository> $b")
+ fail_msg=$(printf "$fail_msg\n$hint1\n$hint2")
+ die "$fail_msg"
+ fi
+ fi
+}
+
+# Usage: find_latest_squash DIR [REPOSITORY]
find_latest_squash () {
- debug "Looking for latest squash ($dir)..."
+ assert test $# -ge 1
+ assert test $# -le 2
dir="$1"
+ repository=""
+ if test "$#" = 2
+ then
+ repository="$2"
+ fi
+ debug "Looking for latest squash (dir=$dir, repository=$repository)..."
+ local indent=$(($indent + 1))
+
sq=
main=
sub=
@@ -319,8 +431,7 @@ find_latest_squash () {
main="$b"
;;
git-subtree-split:)
- sub="$(git rev-parse "$b^0")" ||
- die "could not rev-parse split hash $b from commit $sq"
+ process_subtree_split_trailer "$b" "$sq" "$repository"
;;
END)
if test -n "$sub"
@@ -329,7 +440,8 @@ find_latest_squash () {
then
# a rejoin commit?
# Pretend its sub was a squash.
- sq="$sub"
+ sq=$(git rev-parse --verify "$sq^2") ||
+ die
fi
debug "Squash found: $sq $sub"
echo "$sq" "$sub"
@@ -340,22 +452,32 @@ find_latest_squash () {
sub=
;;
esac
- done
+ done || exit $?
}
+# Usage: find_existing_splits DIR REV [REPOSITORY]
find_existing_splits () {
+ assert test $# -ge 2
+ assert test $# -le 3
debug "Looking for prior splits..."
+ local indent=$(($indent + 1))
+
dir="$1"
- revs="$2"
+ rev="$2"
+ repository=""
+ if test "$#" = 3
+ then
+ repository="$3"
+ fi
main=
sub=
local grep_format="^git-subtree-dir: $dir/*\$"
- if test -n "$ignore_joins"
+ if test -n "$arg_split_ignore_joins"
then
grep_format="^Add '$dir/' from commit '"
fi
git log --grep="$grep_format" \
- --no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
+ --no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' "$rev" |
while read a b junk
do
case "$a" in
@@ -366,18 +488,17 @@ find_existing_splits () {
main="$b"
;;
git-subtree-split:)
- sub="$(git rev-parse "$b^0")" ||
- die "could not rev-parse split hash $b from commit $sq"
+ process_subtree_split_trailer "$b" "$sq" "$repository"
;;
END)
- debug " Main is: '$main'"
- if test -z "$main" -a -n "$sub"
+ debug "Main is: '$main'"
+ if test -z "$main" && test -n "$sub"
then
# squash commits refer to a subtree
debug " Squash: $sq from $sub"
cache_set "$sq" "$sub"
fi
- if test -n "$main" -a -n "$sub"
+ if test -n "$main" && test -n "$sub"
then
debug " Prior: $main -> $sub"
cache_set $main $sub
@@ -389,10 +510,12 @@ find_existing_splits () {
sub=
;;
esac
- done
+ done || exit $?
}
+# Usage: copy_commit REV TREE FLAGS_STR
copy_commit () {
+ assert test $# = 3
# We're going to set some environment vars here, so
# do it in a subshell to get rid of them safely later
debug copy_commit "{$1}" "{$2}" "{$3}"
@@ -411,23 +534,32 @@ copy_commit () {
GIT_COMMITTER_EMAIL \
GIT_COMMITTER_DATE
(
- printf "%s" "$annotate"
+ printf "%s" "$arg_split_annotate"
cat
) |
git commit-tree "$2" $3 # reads the rest of stdin
- ) || die "Can't copy commit $1"
+ ) || die "fatal: can't copy commit $1"
}
+# Usage: add_msg DIR LATEST_OLD LATEST_NEW
add_msg () {
+ assert test $# = 3
dir="$1"
latest_old="$2"
latest_new="$3"
- if test -n "$message"
+ if test -n "$arg_addmerge_message"
then
- commit_message="$message"
+ commit_message="$arg_addmerge_message"
else
commit_message="Add '$dir/' from commit '$latest_new'"
fi
+ if test -n "$arg_split_rejoin"
+ then
+ # If this is from a --rejoin, then rejoin_msg has
+ # already inserted the `git-subtree-xxx:` tags
+ echo "$commit_message"
+ return
+ fi
cat <<-EOF
$commit_message
@@ -437,22 +569,26 @@ add_msg () {
EOF
}
+# Usage: add_squashed_msg REV DIR
add_squashed_msg () {
- if test -n "$message"
+ assert test $# = 2
+ if test -n "$arg_addmerge_message"
then
- echo "$message"
+ echo "$arg_addmerge_message"
else
echo "Merge commit '$1' as '$2'"
fi
}
+# Usage: rejoin_msg DIR LATEST_OLD LATEST_NEW
rejoin_msg () {
+ assert test $# = 3
dir="$1"
latest_old="$2"
latest_new="$3"
- if test -n "$message"
+ if test -n "$arg_addmerge_message"
then
- commit_message="$message"
+ commit_message="$arg_addmerge_message"
else
commit_message="Split '$dir/' into commit '$latest_new'"
fi
@@ -465,7 +601,9 @@ rejoin_msg () {
EOF
}
+# Usage: squash_msg DIR OLD_SUBTREE_COMMIT NEW_SUBTREE_COMMIT
squash_msg () {
+ assert test $# = 3
dir="$1"
oldsub="$2"
newsub="$3"
@@ -487,33 +625,45 @@ squash_msg () {
echo "git-subtree-split: $newsub"
}
+# Usage: toptree_for_commit COMMIT
toptree_for_commit () {
+ assert test $# = 1
commit="$1"
git rev-parse --verify "$commit^{tree}" || exit $?
}
+# Usage: subtree_for_commit COMMIT DIR
subtree_for_commit () {
+ assert test $# = 2
commit="$1"
dir="$2"
git ls-tree "$commit" -- "$dir" |
while read mode type tree name
do
assert test "$name" = "$dir"
- assert test "$type" = "tree" -o "$type" = "commit"
- test "$type" = "commit" && continue # ignore submodules
- echo $tree
- break
- done
+
+ case "$type" in
+ commit)
+ continue;; # ignore submodules
+ tree)
+ echo $tree
+ break;;
+ *)
+ die "fatal: tree entry is of type ${type}, expected tree or commit";;
+ esac
+ done || exit $?
}
+# Usage: tree_changed TREE [PARENTS...]
tree_changed () {
+ assert test $# -gt 0
tree=$1
shift
if test $# -ne 1
then
return 0 # weird parents, consider it changed
else
- ptree=$(toptree_for_commit $1)
+ ptree=$(toptree_for_commit $1) || exit $?
if test "$ptree" != "$tree"
then
return 0 # changed
@@ -523,7 +673,9 @@ tree_changed () {
fi
}
+# Usage: new_squash_commit OLD_SQUASHED_COMMIT OLD_NONSQUASHED_COMMIT NEW_NONSQUASHED_COMMIT
new_squash_commit () {
+ assert test $# = 3
old="$1"
oldsub="$2"
newsub="$3"
@@ -538,7 +690,9 @@ new_squash_commit () {
fi
}
+# Usage: copy_or_skip REV TREE NEWPARENTS
copy_or_skip () {
+ assert test $# = 3
rev="$1"
tree="$2"
newparents="$3"
@@ -613,26 +767,47 @@ copy_or_skip () {
fi
}
+# Usage: ensure_clean
ensure_clean () {
+ assert test $# = 0
if ! git diff-index HEAD --exit-code --quiet 2>&1
then
- die "Working tree has modifications. Cannot add."
+ die "fatal: working tree has modifications. Cannot add."
fi
if ! git diff-index --cached HEAD --exit-code --quiet 2>&1
then
- die "Index has modifications. Cannot add."
+ die "fatal: index has modifications. Cannot add."
fi
}
+# Usage: ensure_valid_ref_format REF
ensure_valid_ref_format () {
+ assert test $# = 1
git check-ref-format "refs/heads/$1" ||
- die "'$1' does not look like a ref"
+ die "fatal: '$1' does not look like a ref"
+}
+
+# Usage: check if a commit from another subtree should be
+# ignored from processing for splits
+should_ignore_subtree_split_commit () {
+ assert test $# = 1
+ local rev="$1"
+ if test -n "$(git log -1 --grep="git-subtree-dir:" $rev)"
+ then
+ if test -z "$(git log -1 --grep="git-subtree-mainline:" $rev)" &&
+ test -z "$(git log -1 --grep="git-subtree-dir: $arg_prefix$" $rev)"
+ then
+ return 0
+ fi
+ fi
+ return 1
}
+# Usage: process_split_commit REV PARENTS
process_split_commit () {
+ assert test $# = 2
local rev="$1"
local parents="$2"
- local indent=$3
if test $indent -eq 0
then
@@ -647,20 +822,21 @@ process_split_commit () {
progress "$revcount/$revmax ($createcount) [$extracount]"
debug "Processing commit: $rev"
- exists=$(cache_get "$rev")
+ local indent=$(($indent + 1))
+ exists=$(cache_get "$rev") || exit $?
if test -n "$exists"
then
- debug " prior: $exists"
+ debug "prior: $exists"
return
fi
createcount=$(($createcount + 1))
- debug " parents: $parents"
- check_parents "$parents" "$indent"
- newparents=$(cache_get $parents)
- debug " newparents: $newparents"
+ debug "parents: $parents"
+ check_parents $parents
+ newparents=$(cache_get $parents) || exit $?
+ debug "newparents: $newparents"
- tree=$(subtree_for_commit "$rev" "$dir")
- debug " tree is: $tree"
+ tree=$(subtree_for_commit "$rev" "$dir") || exit $?
+ debug "tree is: $tree"
# ugly. is there no better way to tell if this is a subtree
# vs. a mainline commit? Does it matter?
@@ -675,24 +851,22 @@ process_split_commit () {
fi
newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
- debug " newrev is: $newrev"
+ debug "newrev is: $newrev"
cache_set "$rev" "$newrev"
cache_set latest_new "$newrev"
cache_set latest_old "$rev"
}
+# Usage: cmd_add REV
+# Or: cmd_add REPOSITORY REF
cmd_add () {
- if test -e "$dir"
- then
- die "'$dir' already exists. Cannot add."
- fi
ensure_clean
if test $# -eq 1
then
git rev-parse -q --verify "$1^{commit}" >/dev/null ||
- die "'$1' does not refer to a commit"
+ die "fatal: '$1' does not refer to a commit"
cmd_add_commit "$@"
@@ -707,31 +881,39 @@ cmd_add () {
cmd_add_repository "$@"
else
- say "error: parameters were '$@'"
+ say >&2 "fatal: parameters were '$*'"
die "Provide either a commit or a repository and commit."
fi
}
+# Usage: cmd_add_repository REPOSITORY REFSPEC
cmd_add_repository () {
+ assert test $# = 2
echo "git fetch" "$@"
repository=$1
refspec=$2
git fetch "$@" || exit $?
- revs=FETCH_HEAD
- set -- $revs
- cmd_add_commit "$@"
+ cmd_add_commit FETCH_HEAD
}
+# Usage: cmd_add_commit REV
cmd_add_commit () {
- rev=$(git rev-parse $default --revs-only "$@") || exit $?
- ensure_single_rev $rev
+ # The rev has already been validated by cmd_add(), we just
+ # need to normalize it.
+ assert test $# = 1
+ rev=$(git rev-parse --verify "$1^{commit}") || exit $?
debug "Adding $dir as '$rev'..."
- git read-tree --prefix="$dir" $rev || exit $?
+ if test -z "$arg_split_rejoin"
+ then
+ # Only bother doing this if this is a genuine 'add',
+ # not a synthetic 'add' from '--rejoin'.
+ git read-tree --prefix="$dir" $rev || exit $?
+ fi
git checkout -- "$dir" || exit $?
tree=$(git write-tree) || exit $?
- headrev=$(git rev-parse HEAD) || exit $?
+ headrev=$(git rev-parse --verify HEAD) || exit $?
if test -n "$headrev" && test "$headrev" != "$rev"
then
headp="-p $headrev"
@@ -739,44 +921,66 @@ cmd_add_commit () {
headp=
fi
- if test -n "$squash"
+ if test -n "$arg_addmerge_squash"
then
rev=$(new_squash_commit "" "" "$rev") || exit $?
commit=$(add_squashed_msg "$rev" "$dir" |
git commit-tree "$tree" $headp -p "$rev") || exit $?
else
- revp=$(peel_committish "$rev") &&
+ revp=$(peel_committish "$rev") || exit $?
commit=$(add_msg "$dir" $headrev "$rev" |
git commit-tree "$tree" $headp -p "$revp") || exit $?
fi
git reset "$commit" || exit $?
- say "Added dir '$dir'"
+ say >&2 "Added dir '$dir'"
}
+# Usage: cmd_split [REV] [REPOSITORY]
cmd_split () {
+ if test $# -eq 0
+ then
+ rev=$(git rev-parse HEAD)
+ elif test $# -eq 1 || test $# -eq 2
+ then
+ rev=$(git rev-parse -q --verify "$1^{commit}") ||
+ die "fatal: '$1' does not refer to a commit"
+ else
+ die "fatal: you must provide exactly one revision, and optionnally a repository. Got: '$*'"
+ fi
+ repository=""
+ if test "$#" = 2
+ then
+ repository="$2"
+ fi
+
+ if test -n "$arg_split_rejoin"
+ then
+ ensure_clean
+ fi
+
debug "Splitting $dir..."
cache_setup || exit $?
- if test -n "$onto"
+ if test -n "$arg_split_onto"
then
- debug "Reading history for --onto=$onto..."
- git rev-list $onto |
+ debug "Reading history for --onto=$arg_split_onto..."
+ git rev-list $arg_split_onto |
while read rev
do
# the 'onto' history is already just the subdir, so
# any parent we find there can be used verbatim
- debug " cache: $rev"
+ debug "cache: $rev"
cache_set "$rev" "$rev"
- done
+ done || exit $?
fi
- unrevs="$(find_existing_splits "$dir" "$revs")"
+ unrevs="$(find_existing_splits "$dir" "$rev" "$repository")" || exit $?
# We can't restrict rev-list to only $dir here, because some of our
# parents have the $dir contents the root, and those won't match.
# (and rev-list --follow doesn't seem to solve this)
- grl='git rev-list --topo-order --reverse --parents $revs $unrevs'
+ grl='git rev-list --topo-order --reverse --parents $rev $unrevs'
revmax=$(eval "$grl" | wc -l)
revcount=0
createcount=0
@@ -784,62 +988,88 @@ cmd_split () {
eval "$grl" |
while read rev parents
do
- process_split_commit "$rev" "$parents" 0
+ if should_ignore_subtree_split_commit "$rev"
+ then
+ continue
+ fi
+ parsedparents=''
+ for parent in $parents
+ do
+ if ! should_ignore_subtree_split_commit "$parent"
+ then
+ parsedparents="$parsedparents$parent "
+ fi
+ done
+ process_split_commit "$rev" "$parsedparents"
done || exit $?
- latest_new=$(cache_get latest_new)
+ latest_new=$(cache_get latest_new) || exit $?
if test -z "$latest_new"
then
- die "No new revisions were found"
+ die "fatal: no new revisions were found"
fi
- if test -n "$rejoin"
+ if test -n "$arg_split_rejoin"
then
debug "Merging split branch into HEAD..."
- latest_old=$(cache_get latest_old)
- git merge -s ours \
- --allow-unrelated-histories \
- -m "$(rejoin_msg "$dir" "$latest_old" "$latest_new")" \
- "$latest_new" >&2 || exit $?
+ latest_old=$(cache_get latest_old) || exit $?
+ arg_addmerge_message="$(rejoin_msg "$dir" "$latest_old" "$latest_new")" || exit $?
+ if test -z "$(find_latest_squash "$dir")"
+ then
+ cmd_add "$latest_new" >&2 || exit $?
+ else
+ cmd_merge "$latest_new" >&2 || exit $?
+ fi
fi
- if test -n "$branch"
+ if test -n "$arg_split_branch"
then
- if rev_exists "refs/heads/$branch"
+ if rev_exists "refs/heads/$arg_split_branch"
then
- if ! rev_is_descendant_of_branch "$latest_new" "$branch"
+ if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new"
then
- die "Branch '$branch' is not an ancestor of commit '$latest_new'."
+ die "fatal: branch '$arg_split_branch' is not an ancestor of commit '$latest_new'."
fi
action='Updated'
else
action='Created'
fi
git update-ref -m 'subtree split' \
- "refs/heads/$branch" "$latest_new" || exit $?
- say "$action branch '$branch'"
+ "refs/heads/$arg_split_branch" "$latest_new" || exit $?
+ say >&2 "$action branch '$arg_split_branch'"
fi
echo "$latest_new"
exit 0
}
+# Usage: cmd_merge REV [REPOSITORY]
cmd_merge () {
- rev=$(git rev-parse $default --revs-only "$@") || exit $?
- ensure_single_rev $rev
+ if test $# -lt 1 || test $# -gt 2
+ then
+ die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
+ fi
+
+ rev=$(git rev-parse -q --verify "$1^{commit}") ||
+ die "fatal: '$1' does not refer to a commit"
+ repository=""
+ if test "$#" = 2
+ then
+ repository="$2"
+ fi
ensure_clean
- if test -n "$squash"
+ if test -n "$arg_addmerge_squash"
then
- first_split="$(find_latest_squash "$dir")"
+ first_split="$(find_latest_squash "$dir" "$repository")" || exit $?
if test -z "$first_split"
then
- die "Can't squash-merge: '$dir' was never added."
+ die "fatal: can't squash-merge: '$dir' was never added."
fi
set $first_split
old=$1
sub=$2
if test "$sub" = "$rev"
then
- say "Subtree is already at commit $rev."
+ say >&2 "Subtree is already at commit $rev."
exit 0
fi
new=$(new_squash_commit "$old" "$sub" "$rev") || exit $?
@@ -847,55 +1077,56 @@ cmd_merge () {
rev="$new"
fi
- version=$(git version)
- if test "$version" \< "git version 1.7"
+ if test -n "$arg_addmerge_message"
then
- if test -n "$message"
- then
- git merge -s subtree --message="$message" "$rev"
- else
- git merge -s subtree "$rev"
- fi
+ git merge --no-ff -Xsubtree="$arg_prefix" \
+ --message="$arg_addmerge_message" "$rev"
else
- if test -n "$message"
- then
- git merge -Xsubtree="$prefix" \
- --message="$message" "$rev"
- else
- git merge -Xsubtree="$prefix" $rev
- fi
+ git merge --no-ff -Xsubtree="$arg_prefix" $rev
fi
}
+# Usage: cmd_pull REPOSITORY REMOTEREF
cmd_pull () {
if test $# -ne 2
then
- die "You must provide <repository> <ref>"
+ die "fatal: you must provide <repository> <ref>"
fi
+ repository="$1"
+ ref="$2"
ensure_clean
- ensure_valid_ref_format "$2"
- git fetch "$@" || exit $?
- revs=FETCH_HEAD
- set -- $revs
- cmd_merge "$@"
+ ensure_valid_ref_format "$ref"
+ git fetch "$repository" "$ref" || exit $?
+ cmd_merge FETCH_HEAD "$repository"
}
+# Usage: cmd_push REPOSITORY [+][LOCALREV:]REMOTEREF
cmd_push () {
if test $# -ne 2
then
- die "You must provide <repository> <ref>"
+ die "fatal: you must provide <repository> <refspec>"
fi
- ensure_valid_ref_format "$2"
if test -e "$dir"
then
repository=$1
- refspec=$2
+ refspec=${2#+}
+ remoteref=${refspec#*:}
+ if test "$remoteref" = "$refspec"
+ then
+ localrevname_presplit=HEAD
+ else
+ localrevname_presplit=${refspec%%:*}
+ fi
+ ensure_valid_ref_format "$remoteref"
+ localrev_presplit=$(git rev-parse -q --verify "$localrevname_presplit^{commit}") ||
+ die "fatal: '$localrevname_presplit' does not refer to a commit"
+
echo "git push using: " "$repository" "$refspec"
- localrev=$(git subtree split --prefix="$prefix") || die
- git push "$repository" "$localrev":"refs/heads/$refspec"
+ localrev=$(cmd_split "$localrev_presplit" "$repository") || die
+ git push "$repository" "$localrev":"refs/heads/$remoteref"
else
- die "'$dir' must already exist. Try 'git subtree add'."
+ die "fatal: '$dir' must already exist. Try 'git subtree add'."
fi
}
-"cmd_$command" "$@"
+main "$@"
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 352deda..004abf4 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,13 +9,14 @@ git-subtree - Merge subtrees together and split repository into subtrees
SYNOPSIS
--------
[verse]
-'git subtree' add -P <prefix> <commit>
-'git subtree' add -P <prefix> <repository> <ref>
-'git subtree' pull -P <prefix> <repository> <ref>
-'git subtree' push -P <prefix> <repository> <ref>
-'git subtree' merge -P <prefix> <commit>
-'git subtree' split -P <prefix> [OPTIONS] [<commit>]
+'git subtree' [<options>] -P <prefix> add <local-commit>
+'git subtree' [<options>] -P <prefix> add <repository> <remote-ref>
+'git subtree' [<options>] -P <prefix> merge <local-commit> [<repository>]
+'git subtree' [<options>] -P <prefix> split [<local-commit>]
+[verse]
+'git subtree' [<options>] -P <prefix> pull <repository> <remote-ref>
+'git subtree' [<options>] -P <prefix> push <repository> <refspec>
DESCRIPTION
-----------
@@ -28,7 +29,7 @@ as a subdirectory of your application.
Subtrees are not to be confused with submodules, which are meant for
the same task. Unlike submodules, subtrees do not need any special
-constructions (like .gitmodules files or gitlinks) be present in
+constructions (like '.gitmodules' files or gitlinks) be present in
your repository, and do not force end-users of your
repository to do anything special or to understand how subtrees
work. A subtree is just a subdirectory that can be
@@ -59,70 +60,81 @@ project as much as possible. That is, if you make a change that
affects both the library and the main application, commit it in
two pieces. That way, when you split the library commits out
later, their descriptions will still make sense. But if this
-isn't important to you, it's not *necessary*. git subtree will
+isn't important to you, it's not *necessary*. 'git subtree' will
simply leave out the non-library-related parts of the commit
when it splits it out into the subproject later.
COMMANDS
--------
-add::
+add <local-commit>::
+add <repository> <remote-ref>::
Create the <prefix> subtree by importing its contents
- from the given <commit> or <repository> and remote <ref>.
+ from the given <local-commit> or <repository> and <remote-ref>.
A new commit is created automatically, joining the imported
- project's history with your own. With '--squash', imports
+ project's history with your own. With '--squash', import
only a single commit from the subproject, rather than its
entire history.
-merge::
- Merge recent changes up to <commit> into the <prefix>
+merge <local-commit> [<repository>]::
+ Merge recent changes up to <local-commit> into the <prefix>
subtree. As with normal 'git merge', this doesn't
remove your own local changes; it just merges those
- changes into the latest <commit>. With '--squash',
- creates only one commit that contains all the changes,
+ changes into the latest <local-commit>. With '--squash',
+ create only one commit that contains all the changes,
rather than merging in the entire history.
+
If you use '--squash', the merge direction doesn't always have to be
forward; you can use this command to go back in time from v2.5 to v2.4,
for example. If your merge introduces a conflict, you can resolve it in
the usual ways.
-
-pull::
- Exactly like 'merge', but parallels 'git pull' in that
- it fetches the given ref from the specified remote
- repository.
-
-push::
- Does a 'split' (see below) using the <prefix> supplied
- and then does a 'git push' to push the result to the
- repository and ref. This can be used to push your
- subtree to different branches of the remote repository.
-
-split::
++
+When using '--squash', and the previous merge with '--squash' merged an
+annotated tag of the subtree repository, that tag needs to be available locally.
+If <repository> is given, a missing tag will automatically be fetched from that
+repository.
+
+split [<local-commit>] [<repository>]::
Extract a new, synthetic project history from the
- history of the <prefix> subtree. The new history
+ history of the <prefix> subtree of <local-commit>, or of
+ HEAD if no <local-commit> is given. The new history
includes only the commits (including merges) that
affected <prefix>, and each of those commits now has the
contents of <prefix> at the root of the project instead
of in a subdirectory. Thus, the newly created history
is suitable for export as a separate git repository.
+
-After splitting successfully, a single commit id is printed to stdout.
+After splitting successfully, a single commit ID is printed to stdout.
This corresponds to the HEAD of the newly created tree, which you can
manipulate however you want.
+
Repeated splits of exactly the same history are guaranteed to be
-identical (i.e. to produce the same commit ids). Because of this, if
-you add new commits and then re-split, the new commits will be attached
-as commits on top of the history you generated last time, so 'git merge'
-and friends will work as expected.
+identical (i.e. to produce the same commit IDs) as long as the
+settings passed to 'split' (such as '--annotate') are the same.
+Because of this, if you add new commits and then re-split, the new
+commits will be attached as commits on top of the history you
+generated last time, so 'git merge' and friends will work as expected.
+
-Note that if you use '--squash' when you merge, you should usually not
-just '--rejoin' when you split.
+When a previous merge with '--squash' merged an annotated tag of the
+subtree repository, that tag needs to be available locally.
+If <repository> is given, a missing tag will automatically be fetched from that
+repository.
+
+pull <repository> <remote-ref>::
+ Exactly like 'merge', but parallels 'git pull' in that
+ it fetches the given ref from the specified remote
+ repository.
+push <repository> [+][<local-commit>:]<remote-ref>::
+ Does a 'split' using the <prefix> subtree of <local-commit>
+ and then does a 'git push' to push the result to the
+ <repository> and <remote-ref>. This can be used to push your
+ subtree to different branches of the remote repository. Just
+ as with 'split', if no <local-commit> is given, then HEAD is
+ used. The optional leading '+' is ignored.
-OPTIONS
--------
+OPTIONS FOR ALL COMMANDS
+------------------------
-q::
--quiet::
Suppress unnecessary output messages on stderr.
@@ -137,21 +149,16 @@ OPTIONS
want to manipulate. This option is mandatory
for all commands.
--m <message>::
---message=<message>::
- This option is only valid for add, merge and pull (unsure).
- Specify <message> as the commit message for the merge commit.
-
+OPTIONS FOR 'add' AND 'merge' (ALSO: 'pull', 'split --rejoin', AND 'push --rejoin')
+-----------------------------------------------------------------------------------
+These options for 'add' and 'merge' may also be given to 'pull' (which
+wraps 'merge'), 'split --rejoin' (which wraps either 'add' or 'merge'
+as appropriate), and 'push --rejoin' (which wraps 'split --rejoin').
-OPTIONS FOR add, merge, push, pull
-----------------------------------
--squash::
- This option is only valid for add, merge, and pull
- commands.
-+
-Instead of merging the entire history from the subtree project, produce
-only a single commit that contains all the differences you want to
-merge, and then merge that new commit into your project.
+ Instead of merging the entire history from the subtree project, produce
+ only a single commit that contains all the differences you want to
+ merge, and then merge that new commit into your project.
+
Using this option helps to reduce log clutter. People rarely want to see
every change that happened between v1.0 and v1.1 of the library they're
@@ -174,57 +181,53 @@ Whether or not you use '--squash', changes made in your local repository
remain intact and can be later split and send upstream to the
subproject.
+-m <message>::
+--message=<message>::
+ Specify <message> as the commit message for the merge commit.
+
+OPTIONS FOR 'split' (ALSO: 'push')
+----------------------------------
+These options for 'split' may also be given to 'push' (which wraps
+'split').
-OPTIONS FOR split
------------------
--annotate=<annotation>::
- This option is only valid for the split command.
-+
-When generating synthetic history, add <annotation> as a prefix to each
-commit message. Since we're creating new commits with the same commit
-message, but possibly different content, from the original commits, this
-can help to differentiate them and avoid confusion.
+ When generating synthetic history, add <annotation> as a prefix to each
+ commit message. Since we're creating new commits with the same commit
+ message, but possibly different content, from the original commits, this
+ can help to differentiate them and avoid confusion.
+
Whenever you split, you need to use the same <annotation>, or else you
don't have a guarantee that the new re-created history will be identical
to the old one. That will prevent merging from working correctly. git
-subtree tries to make it work anyway, particularly if you use --rejoin,
+subtree tries to make it work anyway, particularly if you use '--rejoin',
but it may not always be effective.
-b <branch>::
--branch=<branch>::
- This option is only valid for the split command.
-+
-After generating the synthetic history, create a new branch called
-<branch> that contains the new history. This is suitable for immediate
-pushing upstream. <branch> must not already exist.
+ After generating the synthetic history, create a new branch called
+ <branch> that contains the new history. This is suitable for immediate
+ pushing upstream. <branch> must not already exist.
--ignore-joins::
- This option is only valid for the split command.
-+
-If you use '--rejoin', git subtree attempts to optimize its history
-reconstruction to generate only the new commits since the last
-'--rejoin'. '--ignore-join' disables this behaviour, forcing it to
-regenerate the entire history. In a large project, this can take a long
-time.
+ If you use '--rejoin', git subtree attempts to optimize its history
+ reconstruction to generate only the new commits since the last
+ '--rejoin'. '--ignore-joins' disables this behavior, forcing it to
+ regenerate the entire history. In a large project, this can take a long
+ time.
--onto=<onto>::
- This option is only valid for the split command.
-+
-If your subtree was originally imported using something other than git
-subtree, its history may not match what git subtree is expecting. In
-that case, you can specify the commit id <onto> that corresponds to the
-first revision of the subproject's history that was imported into your
-project, and git subtree will attempt to build its history from there.
+ If your subtree was originally imported using something other than git
+ subtree, its history may not match what git subtree is expecting. In
+ that case, you can specify the commit ID <onto> that corresponds to the
+ first revision of the subproject's history that was imported into your
+ project, and git subtree will attempt to build its history from there.
+
If you used 'git subtree add', you should never need this option.
--rejoin::
- This option is only valid for the split command.
-+
-After splitting, merge the newly created synthetic history back into
-your main project. That way, future splits can search only the part of
-history that has been added since the most recent --rejoin.
+ After splitting, merge the newly created synthetic history back into
+ your main project. That way, future splits can search only the part of
+ history that has been added since the most recent '--rejoin'.
+
If your split commits end up merged into the upstream subproject, and
then you want to get the latest upstream version, this will allow git's
@@ -235,13 +238,12 @@ Unfortunately, using this option results in 'git log' showing an extra
copy of every new commit that was created (the original, and the
synthetic one).
+
-If you do all your merges with '--squash', don't use '--rejoin' when you
-split, because you don't want the subproject's history to be part of
-your project anyway.
+If you do all your merges with '--squash', make sure you also use
+'--squash' when you 'split --rejoin'.
-EXAMPLE 1. Add command
-----------------------
+EXAMPLE 1. 'add' command
+------------------------
Let's assume that you have a local repository that you would like
to add an external vendor library to. In this case we will add the
git-subtree repository as a subdirectory of your already existing
@@ -253,15 +255,15 @@ git-extensions repository in ~/git-extensions/:
'master' needs to be a valid remote ref and can be a different branch
name
-You can omit the --squash flag, but doing so will increase the number
+You can omit the '--squash' flag, but doing so will increase the number
of commits that are included in your local repository.
We now have a ~/git-extensions/git-subtree directory containing code
from the master branch of git://github.com/apenwarr/git-subtree.git
in our git-extensions repository.
-EXAMPLE 2. Extract a subtree using commit, merge and pull
----------------------------------------------------------
+EXAMPLE 2. Extract a subtree using 'commit', 'merge' and 'pull'
+---------------------------------------------------------------
Let's use the repository for the git source code as an example.
First, get your own copy of the git.git repository:
@@ -269,7 +271,7 @@ First, get your own copy of the git.git repository:
$ cd test-git
gitweb (commit 1130ef3) was merged into git as of commit
-0a8f4f0, after which it was no longer maintained separately.
+0a8f4f0, after which it was no longer maintained separately.
But imagine it had been maintained separately, and we wanted to
extract git's changes to gitweb since that time, to share with
the upstream. You could do this:
@@ -279,14 +281,14 @@ the upstream. You could do this:
--branch gitweb-latest
$ gitk gitweb-latest
$ git push git@github.com:whatever/gitweb.git gitweb-latest:master
-
+
(We use '0a8f4f0^..' because that means "all the changes from
0a8f4f0 to the current version, including 0a8f4f0 itself.")
If gitweb had originally been merged using 'git subtree add' (or
-a previous split had already been done with --rejoin specified)
+a previous split had already been done with '--rejoin' specified)
then you can do all your splits without having to remember any
-weird commit ids:
+weird commit IDs:
$ git subtree split --prefix=gitweb --annotate='(split) ' --rejoin \
--branch gitweb-latest2
@@ -313,7 +315,7 @@ And fast forward again:
$ git subtree merge --prefix=gitweb --squash gitweb-latest
And notice that your change is still intact:
-
+
$ ls -l gitweb/myfile
And you can split it out and look at your changes versus
@@ -321,8 +323,8 @@ the standard gitweb:
git log gitweb-latest..$(git subtree split --prefix=gitweb)
-EXAMPLE 3. Extract a subtree using branch
------------------------------------------
+EXAMPLE 3. Extract a subtree using a branch
+-------------------------------------------
Suppose you have a source directory with many files and
subdirectories, and you want to extract the lib directory to its own
git project. Here's a short way to do it:
diff --git a/contrib/subtree/t/Makefile b/contrib/subtree/t/Makefile
index 276898e..093399c 100644
--- a/contrib/subtree/t/Makefile
+++ b/contrib/subtree/t/Makefile
@@ -47,10 +47,11 @@ pre-clean:
$(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
clean-except-prove-cache:
- $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
+ $(RM) -r 'trash directory'.*
$(RM) -r valgrind/bin
clean: clean-except-prove-cache
+ $(RM) -r '$(TEST_RESULTS_DIRECTORY_SQ)'
$(RM) .prove
test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax
@@ -73,9 +74,7 @@ aggregate-results-and-cleanup: $(T)
$(MAKE) clean
aggregate-results:
- for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
- echo "$$f"; \
- done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh
+ @'$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh '$(TEST_RESULTS_DIRECTORY_SQ)'
valgrind:
$(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 57ff4b2..c3bd2a5 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -5,72 +5,24 @@
#
test_description='Basic porcelain support for subtrees
-This test verifies the basic operation of the add, pull, merge
-and split subcommands of git subtree.
+This test verifies the basic operation of the add, merge, split, pull,
+and push subcommands of git subtree.
'
TEST_DIRECTORY=$(pwd)/../../../t
-export TEST_DIRECTORY
+. "$TEST_DIRECTORY"/test-lib.sh
-. ../../../t/test-lib.sh
-
-subtree_test_create_repo()
-{
+# Use our own wrapper around test-lib.sh's test_create_repo, in order
+# to set log.date=relative. `git subtree` parses the output of `git
+# log`, and so it must be careful to not be affected by settings that
+# change the `git log` output. We test this by setting
+# log.date=relative for every repo in the tests.
+subtree_test_create_repo () {
test_create_repo "$1" &&
- (
- cd "$1" &&
- git config log.date relative
- )
-}
-
-create()
-{
- echo "$1" >"$1" &&
- git add "$1"
-}
-
-check_equal()
-{
- test_debug 'echo'
- test_debug "echo \"check a:\" \"{$1}\""
- test_debug "echo \" b:\" \"{$2}\""
- if [ "$1" = "$2" ]; then
- return 0
- else
- return 1
- fi
-}
-
-undo()
-{
- git reset --hard HEAD~
+ git -C "$1" config log.date relative
}
-# Make sure no patch changes more than one file.
-# The original set of commits changed only one file each.
-# A multi-file change would imply that we pruned commits
-# too aggressively.
-join_commits()
-{
- commit=
- all=
- while read x y; do
- if [ -z "$x" ]; then
- continue
- elif [ "$x" = "commit:" ]; then
- if [ -n "$commit" ]; then
- echo "$commit $all"
- all=
- fi
- commit="$y"
- else
- all="$all $y"
- fi
- done
- echo "$commit $all"
-}
-
-test_create_commit() (
+test_create_commit () (
repo=$1 &&
commit=$2 &&
cd "$repo" &&
@@ -81,98 +33,140 @@ test_create_commit() (
git commit -m "$commit" || error "Could not commit"
)
-last_commit_message()
-{
+test_wrong_flag() {
+ test_must_fail "$@" >out 2>err &&
+ test_must_be_empty out &&
+ grep "flag does not make sense with" err
+}
+
+last_commit_subject () {
git log --pretty=format:%s -1
}
-subtree_test_count=0
-next_test() {
- subtree_test_count=$(($subtree_test_count+1))
+# Upon 'git subtree add|merge --squash' of an annotated tag,
+# pre-2.32.0 versions of 'git subtree' would write the hash of the tag
+# (sub1 below), instead of the commit (sub1^{commit}) in the
+# "git-subtree-split" trailer.
+# We immitate this behaviour below using a replace ref.
+# This function creates 3 repositories:
+# - $1
+# - $1-sub (added as subtree "sub" in $1)
+# - $1-clone (clone of $1)
+test_create_pre2_32_repo () {
+ subtree_test_create_repo "$1" &&
+ subtree_test_create_repo "$1-sub" &&
+ test_commit -C "$1" main1 &&
+ test_commit -C "$1-sub" --annotate sub1 &&
+ git -C "$1" subtree add --prefix="sub" --squash "../$1-sub" sub1 &&
+ tag=$(git -C "$1" rev-parse FETCH_HEAD) &&
+ commit=$(git -C "$1" rev-parse FETCH_HEAD^{commit}) &&
+ git -C "$1" log -1 --format=%B HEAD^2 >msg &&
+ test_commit -C "$1-sub" --annotate sub2 &&
+ git clone --no-local "$1" "$1-clone" &&
+ new_commit=$(sed -e "s/$commit/$tag/" msg | git -C "$1-clone" commit-tree HEAD^2^{tree}) &&
+ git -C "$1-clone" replace HEAD^2 $new_commit
}
+test_expect_success 'shows short help text for -h' '
+ test_expect_code 129 git subtree -h >out 2>err &&
+ test_must_be_empty err &&
+ grep -e "^ *or: git subtree pull" out &&
+ grep -F -e "--[no-]annotate" out
+'
+
#
# Tests for 'git subtree add'
#
-next_test
test_expect_success 'no merge from non-existent subtree' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
test_must_fail git subtree merge --prefix="sub dir" FETCH_HEAD
)
'
-next_test
test_expect_success 'no pull from non-existent subtree' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD
+ )
+'
+
+test_expect_success 'add rejects flags for split' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
- test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" master
- )'
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ test_wrong_flag git subtree add --prefix="sub dir" --annotate=foo FETCH_HEAD &&
+ test_wrong_flag git subtree add --prefix="sub dir" --branch=foo FETCH_HEAD &&
+ test_wrong_flag git subtree add --prefix="sub dir" --ignore-joins FETCH_HEAD &&
+ test_wrong_flag git subtree add --prefix="sub dir" --onto=foo FETCH_HEAD &&
+ test_wrong_flag git subtree add --prefix="sub dir" --rejoin FETCH_HEAD
+ )
+'
-next_test
test_expect_success 'add subproj as subtree into sub dir/ with --prefix' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
+ test "$(last_commit_subject)" = "Add '\''sub dir/'\'' from commit '\''$(git rev-parse FETCH_HEAD)'\''"
)
'
-next_test
test_expect_success 'add subproj as subtree into sub dir/ with --prefix and --message' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" --message="Added subproject" FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Added subproject"
+ test "$(last_commit_subject)" = "Added subproject"
)
'
-next_test
test_expect_success 'add subproj as subtree into sub dir/ with --prefix as -P and --message as -m' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add -P "sub dir" -m "Added subproject" FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Added subproject"
+ test "$(last_commit_subject)" = "Added subproject"
)
'
-next_test
test_expect_success 'add subproj as subtree into sub dir/ with --squash and --prefix and --message' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" --message="Added subproject with squash" --squash FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Added subproject with squash"
+ test "$(last_commit_subject)" = "Added subproject with squash"
)
'
@@ -180,119 +174,142 @@ test_expect_success 'add subproj as subtree into sub dir/ with --squash and --pr
# Tests for 'git subtree merge'
#
-next_test
+test_expect_success 'merge rejects flags for split' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ test_wrong_flag git subtree merge --prefix="sub dir" --annotate=foo FETCH_HEAD &&
+ test_wrong_flag git subtree merge --prefix="sub dir" --branch=foo FETCH_HEAD &&
+ test_wrong_flag git subtree merge --prefix="sub dir" --ignore-joins FETCH_HEAD &&
+ test_wrong_flag git subtree merge --prefix="sub dir" --onto=foo FETCH_HEAD &&
+ test_wrong_flag git subtree merge --prefix="sub dir" --rejoin FETCH_HEAD
+ )
+'
+
test_expect_success 'merge new subproj history into sub dir/ with --prefix' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+ test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
)
'
-next_test
test_expect_success 'merge new subproj history into sub dir/ with --prefix and --message' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" --message="Merged changes from subproject" FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Merged changes from subproject"
+ test "$(last_commit_subject)" = "Merged changes from subproject"
)
'
-next_test
test_expect_success 'merge new subproj history into sub dir/ with --squash and --prefix and --message' '
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- subtree_test_create_repo "$subtree_test_count" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ subtree_test_create_repo "$test_count" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" --message="Merged changes from subproject using squash" --squash FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Merged changes from subproject using squash"
+ test "$(last_commit_subject)" = "Merged changes from subproject using squash"
)
'
-next_test
test_expect_success 'merge the added subproj again, should do nothing' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD &&
# this shouldn not actually do anything, since FETCH_HEAD
# is already a parent
result=$(git merge -s ours -m "merge -s -ours" FETCH_HEAD) &&
- check_equal "${result}" "Already up to date."
+ test "${result}" = "Already up to date."
)
'
-next_test
test_expect_success 'merge new subproj history into subdir/ with a slash appended to the argument of --prefix' '
- test_create_repo "$test_count" &&
- test_create_repo "$test_count/subproj" &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/subproj" &&
test_create_commit "$test_count" main1 &&
test_create_commit "$test_count/subproj" sub1 &&
(
cd "$test_count" &&
- git fetch ./subproj master &&
+ git fetch ./subproj HEAD &&
git subtree add --prefix=subdir/ FETCH_HEAD
) &&
test_create_commit "$test_count/subproj" sub2 &&
(
cd "$test_count" &&
- git fetch ./subproj master &&
+ git fetch ./subproj HEAD &&
git subtree merge --prefix=subdir/ FETCH_HEAD &&
- check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
+ test "$(last_commit_subject)" = "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''"
)
'
+test_expect_success 'merge with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' '
+ test_create_pre2_32_repo "$test_count" &&
+ git -C "$test_count-clone" fetch "../$test_count-sub" sub2 &&
+ test_must_fail git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD &&
+ git -C "$test_count-clone" subtree merge --prefix="sub" --squash FETCH_HEAD "../$test_count-sub"
+'
+
#
# Tests for 'git subtree split'
#
-next_test
test_expect_success 'split requires option --prefix' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD &&
- echo "You must provide the --prefix option." > expected &&
- test_must_fail git subtree split > actual 2>&1 &&
+ echo "fatal: you must provide the --prefix option." >expected &&
+ test_must_fail git subtree split >actual 2>&1 &&
test_debug "printf '"expected: "'" &&
test_debug "cat expected" &&
test_debug "printf '"actual: "'" &&
@@ -301,18 +318,17 @@ test_expect_success 'split requires option --prefix' '
)
'
-next_test
test_expect_success 'split requires path given by option --prefix must exist' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD &&
- echo "'\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" > expected &&
- test_must_fail git subtree split --prefix=non-existent-directory > actual 2>&1 &&
+ echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
+ test_must_fail git subtree split --prefix=non-existent-directory >actual 2>&1 &&
test_debug "printf '"expected: "'" &&
test_debug "cat expected" &&
test_debug "printf '"actual: "'" &&
@@ -321,222 +337,753 @@ test_expect_success 'split requires path given by option --prefix must exist' '
)
'
-next_test
+test_expect_success 'split rejects flags for add' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
+ test_wrong_flag git subtree split --prefix="sub dir" --squash &&
+ test_wrong_flag git subtree split --prefix="sub dir" --message=foo
+ )
+'
+
test_expect_success 'split sub dir/ with --rejoin' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
git subtree split --prefix="sub dir" --annotate="*" --rejoin &&
- check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
+ test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
)
- '
+'
+
+# Tests that commits from other subtrees are not processed as
+# part of a split.
+#
+# This test performs the following:
+# - Creates Repo with subtrees 'subA' and 'subB'
+# - Creates commits in the repo including changes to subtrees
+# - Runs the following 'split' and commit' commands in order:
+# - Perform 'split' on subtree A
+# - Perform 'split' on subtree B
+# - Create new commits with changes to subtree A and B
+# - Perform split on subtree A
+# - Check that the commits in subtree B are not processed
+# as part of the subtree A split
+test_expect_success 'split with multiple subtrees' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/subA" &&
+ subtree_test_create_repo "$test_count/subB" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/subA" subA1 &&
+ test_create_commit "$test_count/subA" subA2 &&
+ test_create_commit "$test_count/subA" subA3 &&
+ test_create_commit "$test_count/subB" subB1 &&
+ git -C "$test_count" fetch ./subA HEAD &&
+ git -C "$test_count" subtree add --prefix=subADir FETCH_HEAD &&
+ git -C "$test_count" fetch ./subB HEAD &&
+ git -C "$test_count" subtree add --prefix=subBDir FETCH_HEAD &&
+ test_create_commit "$test_count" subADir/main-subA1 &&
+ test_create_commit "$test_count" subBDir/main-subB1 &&
+ git -C "$test_count" subtree split --prefix=subADir \
+ --squash --rejoin -m "Sub A Split 1" &&
+ git -C "$test_count" subtree split --prefix=subBDir \
+ --squash --rejoin -m "Sub B Split 1" &&
+ test_create_commit "$test_count" subADir/main-subA2 &&
+ test_create_commit "$test_count" subBDir/main-subB2 &&
+ git -C "$test_count" subtree split --prefix=subADir \
+ --squash --rejoin -m "Sub A Split 2" &&
+ test "$(git -C "$test_count" subtree split --prefix=subBDir \
+ --squash --rejoin -d -m "Sub B Split 1" 2>&1 | grep -w "\[1\]")" = ""
+'
-next_test
test_expect_success 'split sub dir/ with --rejoin from scratch' '
- subtree_test_create_repo "$subtree_test_count" &&
- test_create_commit "$subtree_test_count" main1 &&
+ subtree_test_create_repo "$test_count" &&
+ test_create_commit "$test_count" main1 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
mkdir "sub dir" &&
echo file >"sub dir"/file &&
git add "sub dir/file" &&
git commit -m"sub dir file" &&
split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
git subtree split --prefix="sub dir" --rejoin &&
- check_equal "$(last_commit_message)" "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
+ test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''"
)
- '
+'
-next_test
test_expect_success 'split sub dir/ with --rejoin and --message' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
git subtree split --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin &&
- check_equal "$(last_commit_message)" "Split & rejoin"
+ test "$(last_commit_subject)" = "Split & rejoin"
)
'
-next_test
+test_expect_success 'split "sub dir"/ with --rejoin and --squash' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" --squash FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD &&
+ MAIN=$(git rev-parse --verify HEAD) &&
+ SUB=$(git -C "sub proj" rev-parse --verify HEAD) &&
+
+ SPLIT=$(git subtree split --prefix="sub dir" --annotate="*" --rejoin --squash) &&
+
+ test_must_fail git merge-base --is-ancestor $SUB HEAD &&
+ test_must_fail git merge-base --is-ancestor $SPLIT HEAD &&
+ git rev-list HEAD ^$MAIN >commit-list &&
+ test_line_count = 2 commit-list &&
+ test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" &&
+ test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" &&
+ test "$(git rev-parse --verify HEAD^1)" = $MAIN &&
+ test "$(git rev-parse --verify HEAD^2)" != $SPLIT &&
+ test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" &&
+ test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''"
+ )
+'
+
+test_expect_success 'split then pull "sub dir"/ with --rejoin and --squash' '
+ # 1. "add"
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ git -C "$test_count" subtree --prefix="sub dir" add --squash ./"sub proj" HEAD &&
+
+ # 2. commit from parent
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+
+ # 3. "split --rejoin --squash"
+ git -C "$test_count" subtree --prefix="sub dir" split --rejoin --squash &&
+
+ # 4. "pull --squash"
+ test_create_commit "$test_count/sub proj" sub2 &&
+ git -C "$test_count" subtree -d --prefix="sub dir" pull --squash ./"sub proj" HEAD &&
+
+ test_must_fail git merge-base HEAD FETCH_HEAD
+'
+
test_expect_success 'split "sub dir"/ with --branch' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
- check_equal "$(git rev-parse subproj-br)" "$split_hash"
+ test "$(git rev-parse subproj-br)" = "$split_hash"
)
'
-next_test
test_expect_success 'check hash of split' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
- check_equal "$(git rev-parse subproj-br)" "$split_hash" &&
+ test "$(git rev-parse subproj-br)" = "$split_hash" &&
# Check hash of split
new_hash=$(git rev-parse subproj-br^2) &&
(
cd ./"sub proj" &&
subdir_hash=$(git rev-parse HEAD) &&
- check_equal ''"$new_hash"'' "$subdir_hash"
+ test "$new_hash" = "$subdir_hash"
)
)
'
-next_test
test_expect_success 'split "sub dir"/ with --branch for an existing branch' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git branch subproj-br FETCH_HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br &&
- check_equal "$(git rev-parse subproj-br)" "$split_hash"
+ test "$(git rev-parse subproj-br)" = "$split_hash"
)
'
-next_test
test_expect_success 'split "sub dir"/ with --branch for an incompatible branch' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git branch init HEAD &&
- git fetch ./"sub proj" master &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
test_must_fail git subtree split --prefix="sub dir" --branch init
)
'
+test_expect_success 'split after annotated tag was added/merged with --squash pre-v2.32.0' '
+ test_create_pre2_32_repo "$test_count" &&
+ test_must_fail git -C "$test_count-clone" subtree split --prefix="sub" HEAD &&
+ git -C "$test_count-clone" subtree split --prefix="sub" HEAD "../$test_count-sub"
+'
+
+#
+# Tests for 'git subtree pull'
+#
+
+test_expect_success 'pull requires option --prefix' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ (
+ cd "$test_count" &&
+ test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err &&
+
+ echo "fatal: you must provide the --prefix option." >expected &&
+ test_must_be_empty out &&
+ test_cmp expected err
+ )
+'
+
+test_expect_success 'pull requires path given by option --prefix must exist' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err &&
+
+ echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
+ test_must_be_empty out &&
+ test_cmp expected err
+ )
+'
+
+test_expect_success 'pull basic operation' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ (
+ cd "$test_count" &&
+ exp=$(git -C "sub proj" rev-parse --verify HEAD:) &&
+ git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
+ act=$(git rev-parse --verify HEAD:"sub dir") &&
+ test "$act" = "$exp"
+ )
+'
+
+test_expect_success 'pull rejects flags for split' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ (
+ test_must_fail git subtree pull --prefix="sub dir" --annotate=foo ./"sub proj" HEAD &&
+ test_must_fail git subtree pull --prefix="sub dir" --branch=foo ./"sub proj" HEAD &&
+ test_must_fail git subtree pull --prefix="sub dir" --ignore-joins ./"sub proj" HEAD &&
+ test_must_fail git subtree pull --prefix="sub dir" --onto=foo ./"sub proj" HEAD &&
+ test_must_fail git subtree pull --prefix="sub dir" --rejoin ./"sub proj" HEAD
+ )
+'
+
+test_expect_success 'pull with --squash after annotated tag was added/merged with --squash pre-v2.32.0 ' '
+ test_create_pre2_32_repo "$test_count" &&
+ git -C "$test_count-clone" subtree -d pull --prefix="sub" --squash "../$test_count-sub" sub2
+'
+
+#
+# Tests for 'git subtree push'
+#
+
+test_expect_success 'push requires option --prefix' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
+ echo "fatal: you must provide the --prefix option." >expected &&
+ test_must_fail git subtree push "./sub proj" from-mainline >actual 2>&1 &&
+ test_debug "printf '"expected: "'" &&
+ test_debug "cat expected" &&
+ test_debug "printf '"actual: "'" &&
+ test_debug "cat actual" &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'push requires path given by option --prefix must exist' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD &&
+ echo "fatal: '\''non-existent-directory'\'' does not exist; use '\''git subtree add'\''" >expected &&
+ test_must_fail git subtree push --prefix=non-existent-directory "./sub proj" from-mainline >actual 2>&1 &&
+ test_debug "printf '"expected: "'" &&
+ test_debug "cat expected" &&
+ test_debug "printf '"actual: "'" &&
+ test_debug "cat actual" &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'push rejects flags for add' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ test_wrong_flag git subtree split --prefix="sub dir" --squash ./"sub proj" from-mainline &&
+ test_wrong_flag git subtree split --prefix="sub dir" --message=foo ./"sub proj" from-mainline
+ )
+'
+
+test_expect_success 'push basic operation' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ before=$(git rev-parse --verify HEAD) &&
+ split_hash=$(git subtree split --prefix="sub dir") &&
+ git subtree push --prefix="sub dir" ./"sub proj" from-mainline &&
+ test "$before" = "$(git rev-parse --verify HEAD)" &&
+ test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'push sub dir/ with --rejoin' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
+ git subtree push --prefix="sub dir" --annotate="*" --rejoin ./"sub proj" from-mainline &&
+ test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" &&
+ test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'push sub dir/ with --rejoin from scratch' '
+ subtree_test_create_repo "$test_count" &&
+ test_create_commit "$test_count" main1 &&
+ (
+ cd "$test_count" &&
+ mkdir "sub dir" &&
+ echo file >"sub dir"/file &&
+ git add "sub dir/file" &&
+ git commit -m"sub dir file" &&
+ split_hash=$(git subtree split --prefix="sub dir" --rejoin) &&
+ git init --bare "sub proj.git" &&
+ git subtree push --prefix="sub dir" --rejoin ./"sub proj.git" from-mainline &&
+ test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$split_hash'\''" &&
+ test "$split_hash" = "$(git -C "sub proj.git" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'push sub dir/ with --rejoin and --message' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ git subtree push --prefix="sub dir" --message="Split & rejoin" --annotate="*" --rejoin ./"sub proj" from-mainline &&
+ test "$(last_commit_subject)" = "Split & rejoin" &&
+ split_hash="$(git rev-parse --verify HEAD^2)" &&
+ test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'push "sub dir"/ with --rejoin and --squash' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" --squash FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git subtree pull --prefix="sub dir" --squash ./"sub proj" HEAD &&
+ MAIN=$(git rev-parse --verify HEAD) &&
+ SUB=$(git -C "sub proj" rev-parse --verify HEAD) &&
+
+ SPLIT=$(git subtree split --prefix="sub dir" --annotate="*") &&
+ git subtree push --prefix="sub dir" --annotate="*" --rejoin --squash ./"sub proj" from-mainline &&
+
+ test_must_fail git merge-base --is-ancestor $SUB HEAD &&
+ test_must_fail git merge-base --is-ancestor $SPLIT HEAD &&
+ git rev-list HEAD ^$MAIN >commit-list &&
+ test_line_count = 2 commit-list &&
+ test "$(git rev-parse --verify HEAD:)" = "$(git rev-parse --verify $MAIN:)" &&
+ test "$(git rev-parse --verify HEAD:"sub dir")" = "$(git rev-parse --verify $SPLIT:)" &&
+ test "$(git rev-parse --verify HEAD^1)" = $MAIN &&
+ test "$(git rev-parse --verify HEAD^2)" != $SPLIT &&
+ test "$(git rev-parse --verify HEAD^2:)" = "$(git rev-parse --verify $SPLIT:)" &&
+ test "$(last_commit_subject)" = "Split '\''sub dir/'\'' into commit '\''$SPLIT'\''" &&
+ test "$SPLIT" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'push "sub dir"/ with --branch' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
+ git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
+ test "$(git rev-parse subproj-br)" = "$split_hash" &&
+ test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'check hash of push' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
+ git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
+ test "$(git rev-parse subproj-br)" = "$split_hash" &&
+ # Check hash of split
+ new_hash=$(git rev-parse subproj-br^2) &&
+ (
+ cd ./"sub proj" &&
+ subdir_hash=$(git rev-parse HEAD) &&
+ test "$new_hash" = "$subdir_hash"
+ ) &&
+ test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'push "sub dir"/ with --branch for an existing branch' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git branch subproj-br FETCH_HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ split_hash=$(git subtree split --prefix="sub dir" --annotate="*") &&
+ git subtree push --prefix="sub dir" --annotate="*" --branch subproj-br ./"sub proj" from-mainline &&
+ test "$(git rev-parse subproj-br)" = "$split_hash" &&
+ test "$split_hash" = "$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline)"
+ )
+'
+
+test_expect_success 'push "sub dir"/ with --branch for an incompatible branch' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git branch init HEAD &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree merge --prefix="sub dir" FETCH_HEAD &&
+ test_must_fail git subtree push --prefix="sub dir" --branch init "./sub proj" from-mainline
+ )
+'
+
+test_expect_success 'push "sub dir"/ with a local rev' '
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
+ (
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
+ git subtree add --prefix="sub dir" FETCH_HEAD
+ ) &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd "$test_count" &&
+ bad_tree=$(git rev-parse --verify HEAD:"sub dir") &&
+ good_tree=$(git rev-parse --verify HEAD^:"sub dir") &&
+ git subtree push --prefix="sub dir" --annotate="*" ./"sub proj" HEAD^:from-mainline &&
+ split_tree=$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline:) &&
+ test "$split_tree" = "$good_tree"
+ )
+'
+
+test_expect_success 'push after annotated tag was added/merged with --squash pre-v2.32.0' '
+ test_create_pre2_32_repo "$test_count" &&
+ test_create_commit "$test_count-clone" sub/main-sub1 &&
+ git -C "$test_count-clone" subtree push --prefix="sub" "../$test_count-sub" from-mainline
+'
+
#
# Validity checking
#
-next_test
test_expect_success 'make sure exactly the right set of files ends up in the subproj' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count/sub proj" sub3 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
+ test_create_commit "$test_count/sub proj" sub3 &&
+ test_create_commit "$test_count" "sub dir"/main-sub3 &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub4 &&
+ test_create_commit "$test_count/sub proj" sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
+ test_create_commit "$test_count" "sub dir"/main-sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD &&
@@ -547,46 +1094,45 @@ test_expect_success 'make sure exactly the right set of files ends up in the sub
)
'
-next_test
test_expect_success 'make sure the subproj *only* contains commits that affect the "sub dir"' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count/sub proj" sub3 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
+ test_create_commit "$test_count/sub proj" sub3 &&
+ test_create_commit "$test_count" "sub dir"/main-sub3 &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub4 &&
+ test_create_commit "$test_count/sub proj" sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
+ test_create_commit "$test_count" "sub dir"/main-sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD &&
@@ -598,52 +1144,51 @@ test_expect_success 'make sure the subproj *only* contains commits that affect t
)
'
-next_test
test_expect_success 'make sure exactly the right set of files ends up in the mainline' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count/sub proj" sub3 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
+ test_create_commit "$test_count/sub proj" sub3 &&
+ test_create_commit "$test_count" "sub dir"/main-sub3 &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub4 &&
+ test_create_commit "$test_count/sub proj" sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
+ test_create_commit "$test_count" "sub dir"/main-sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
(
- cd "$subtree_test_count" &&
- git subtree pull --prefix="sub dir" ./"sub proj" master &&
+ cd "$test_count" &&
+ git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
test_write_lines main1 main2 >chkm &&
test_write_lines main-sub1 main-sub2 main-sub3 main-sub4 >chkms &&
@@ -657,53 +1202,52 @@ test_expect_success 'make sure exactly the right set of files ends up in the mai
)
'
-next_test
test_expect_success 'make sure each filename changed exactly once in the entire history' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git config log.date relative &&
- git fetch ./"sub proj" master &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count/sub proj" sub3 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
+ test_create_commit "$test_count/sub proj" sub3 &&
+ test_create_commit "$test_count" "sub dir"/main-sub3 &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub4 &&
+ test_create_commit "$test_count/sub proj" sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
+ test_create_commit "$test_count" "sub dir"/main-sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
(
- cd "$subtree_test_count" &&
- git subtree pull --prefix="sub dir" ./"sub proj" master &&
+ cd "$test_count" &&
+ git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
test_write_lines main1 main2 >chkm &&
test_write_lines sub1 sub2 sub3 sub4 >chks &&
@@ -723,105 +1267,103 @@ test_expect_success 'make sure each filename changed exactly once in the entire
)
'
-next_test
test_expect_success 'make sure the --rejoin commits never make it into subproj' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count/sub proj" sub3 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
+ test_create_commit "$test_count/sub proj" sub3 &&
+ test_create_commit "$test_count" "sub dir"/main-sub3 &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub4 &&
+ test_create_commit "$test_count/sub proj" sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
+ test_create_commit "$test_count" "sub dir"/main-sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
(
- cd "$subtree_test_count" &&
- git subtree pull --prefix="sub dir" ./"sub proj" master &&
- check_equal "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" ""
+ cd "$test_count" &&
+ git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
+ test "$(git log --pretty=format:"%s" HEAD^2 | grep -i split)" = ""
)
'
-next_test
test_expect_success 'make sure no "git subtree" tagged commits make it into subproj' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count/sub proj" sub3 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
+ test_create_commit "$test_count/sub proj" sub3 &&
+ test_create_commit "$test_count" "sub dir"/main-sub3 &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub4 &&
+ test_create_commit "$test_count/sub proj" sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub4 &&
+ test_create_commit "$test_count" "sub dir"/main-sub4 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --annotate="*" --branch subproj-br --rejoin
) &&
(
- cd "$subtree_test_count/sub proj" &&
+ cd "$test_count/sub proj" &&
git fetch .. subproj-br &&
git merge FETCH_HEAD
) &&
(
- cd "$subtree_test_count" &&
- git subtree pull --prefix="sub dir" ./"sub proj" master &&
+ cd "$test_count" &&
+ git subtree pull --prefix="sub dir" ./"sub proj" HEAD &&
# They are meaningless to subproj since one side of the merge refers to the mainline
- check_equal "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" ""
+ test "$(git log --pretty=format:"%s%n%b" HEAD^2 | grep "git-subtree.*:")" = ""
)
'
@@ -829,145 +1371,135 @@ test_expect_success 'make sure no "git subtree" tagged commits make it into subp
# A new set of tests
#
-next_test
test_expect_success 'make sure "git subtree split" find the correct parent' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git branch subproj-ref FETCH_HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --branch subproj-br &&
# at this point, the new commit parent should be subproj-ref, if it is
- # not, something went wrong (the "newparent" of "master~" commit should
+ # not, something went wrong (the "newparent" of "HEAD~" commit should
# have been sub2, but it was not, because its cache was not set to
# itself)
- check_equal "$(git log --pretty=format:%P -1 subproj-br)" "$(git rev-parse subproj-ref)"
+ test "$(git log --pretty=format:%P -1 subproj-br)" = "$(git rev-parse subproj-ref)"
)
'
-next_test
test_expect_success 'split a new subtree without --onto option' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --branch subproj-br
) &&
- mkdir "$subtree_test_count"/"sub dir2" &&
- test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
+ mkdir "$test_count"/"sub dir2" &&
+ test_create_commit "$test_count" "sub dir2"/main-sub2 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
# also test that we still can split out an entirely new subtree
# if the parent of the first commit in the tree is not empty,
# then the new subtree has accidentally been attached to something
git subtree split --prefix="sub dir2" --branch subproj2-br &&
- check_equal "$(git log --pretty=format:%P -1 subproj2-br)" ""
+ test "$(git log --pretty=format:%P -1 subproj2-br)" = ""
)
'
-next_test
test_expect_success 'verify one file change per commit' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git branch sub1 FETCH_HEAD &&
git subtree add --prefix="sub dir" sub1
) &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir" --branch subproj-br
) &&
- mkdir "$subtree_test_count"/"sub dir2" &&
- test_create_commit "$subtree_test_count" "sub dir2"/main-sub2 &&
+ mkdir "$test_count"/"sub dir2" &&
+ test_create_commit "$test_count" "sub dir2"/main-sub2 &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git subtree split --prefix="sub dir2" --branch subproj2-br &&
- x= &&
- git log --pretty=format:"commit: %H" | join_commits |
- (
- while read commit a b; do
- test_debug "echo Verifying commit $commit"
- test_debug "echo a: $a"
- test_debug "echo b: $b"
- check_equal "$b" ""
- x=1
- done
- check_equal "$x" 1
- )
+ git log --format="%H" >commit-list &&
+ while read commit
+ do
+ git log -n1 --format="" --name-only "$commit" >file-list &&
+ test_line_count -le 1 file-list || return 1
+ done <commit-list
)
'
-next_test
test_expect_success 'push split to subproj' '
- subtree_test_create_repo "$subtree_test_count" &&
- subtree_test_create_repo "$subtree_test_count/sub proj" &&
- test_create_commit "$subtree_test_count" main1 &&
- test_create_commit "$subtree_test_count/sub proj" sub1 &&
+ subtree_test_create_repo "$test_count" &&
+ subtree_test_create_repo "$test_count/sub proj" &&
+ test_create_commit "$test_count" main1 &&
+ test_create_commit "$test_count/sub proj" sub1 &&
(
- cd "$subtree_test_count" &&
- git fetch ./"sub proj" master &&
+ cd "$test_count" &&
+ git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub1 &&
- test_create_commit "$subtree_test_count" main2 &&
- test_create_commit "$subtree_test_count/sub proj" sub2 &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub2 &&
- (
- cd $subtree_test_count/"sub proj" &&
- git branch sub-branch-1 &&
- cd .. &&
- git fetch ./"sub proj" master &&
+ test_create_commit "$test_count" "sub dir"/main-sub1 &&
+ test_create_commit "$test_count" main2 &&
+ test_create_commit "$test_count/sub proj" sub2 &&
+ test_create_commit "$test_count" "sub dir"/main-sub2 &&
+ (
+ cd $test_count/"sub proj" &&
+ git branch sub-branch-1 &&
+ cd .. &&
+ git fetch ./"sub proj" HEAD &&
git subtree merge --prefix="sub dir" FETCH_HEAD
) &&
- test_create_commit "$subtree_test_count" "sub dir"/main-sub3 &&
- (
- cd "$subtree_test_count" &&
- git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
- cd ./"sub proj" &&
- git checkout sub-branch-1 &&
- check_equal "$(last_commit_message)" "sub dir/main-sub3"
+ test_create_commit "$test_count" "sub dir"/main-sub3 &&
+ (
+ cd "$test_count" &&
+ git subtree push ./"sub proj" --prefix "sub dir" sub-branch-1 &&
+ cd ./"sub proj" &&
+ git checkout sub-branch-1 &&
+ test "$(last_commit_subject)" = "sub dir/main-sub3"
)
'
@@ -991,43 +1523,43 @@ test_expect_success 'push split to subproj' '
# set of commits.
#
-next_test
test_expect_success 'subtree descendant check' '
- subtree_test_create_repo "$subtree_test_count" &&
- test_create_commit "$subtree_test_count" folder_subtree/a &&
+ subtree_test_create_repo "$test_count" &&
+ defaultBranch=$(sed "s,ref: refs/heads/,," "$test_count/.git/HEAD") &&
+ test_create_commit "$test_count" folder_subtree/a &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git branch branch
) &&
- test_create_commit "$subtree_test_count" folder_subtree/0 &&
- test_create_commit "$subtree_test_count" folder_subtree/b &&
- cherry=$(cd "$subtree_test_count"; git rev-parse HEAD) &&
+ test_create_commit "$test_count" folder_subtree/0 &&
+ test_create_commit "$test_count" folder_subtree/b &&
+ cherry=$(cd "$test_count" && git rev-parse HEAD) &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git checkout branch
) &&
- test_create_commit "$subtree_test_count" commit_on_branch &&
+ test_create_commit "$test_count" commit_on_branch &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git cherry-pick $cherry &&
- git checkout master &&
+ git checkout $defaultBranch &&
git merge -m "merge should be kept on subtree" branch &&
git branch no_subtree_work_branch
) &&
- test_create_commit "$subtree_test_count" folder_subtree/d &&
+ test_create_commit "$test_count" folder_subtree/d &&
(
- cd "$subtree_test_count" &&
+ cd "$test_count" &&
git checkout no_subtree_work_branch
) &&
- test_create_commit "$subtree_test_count" not_a_subtree_change &&
+ test_create_commit "$test_count" not_a_subtree_change &&
(
- cd "$subtree_test_count" &&
- git checkout master &&
+ cd "$test_count" &&
+ git checkout $defaultBranch &&
git merge -m "merge should be skipped on subtree" no_subtree_work_branch &&
- git subtree split --prefix folder_subtree/ --branch subtree_tip master &&
+ git subtree split --prefix folder_subtree/ --branch subtree_tip $defaultBranch &&
git subtree split --prefix folder_subtree/ --branch subtree_branch branch &&
- check_equal $(git rev-list --count subtree_tip..subtree_branch) 0
+ test $(git rev-list --count subtree_tip..subtree_branch) = 0
)
'
diff --git a/contrib/subtree/todo b/contrib/subtree/todo
index 0d0e777..32d2ce3 100644
--- a/contrib/subtree/todo
+++ b/contrib/subtree/todo
@@ -23,9 +23,9 @@
"pull" and "merge" commands should fail if you've never merged
that --prefix before
-
+
docs should provide an example of "add"
-
+
note that the initial split doesn't *have* to have a commitid
specified... that's just an optimization
@@ -33,7 +33,7 @@
get a misleading "prefix must end with /" message from
one of the other git tools that git-subtree calls. Should
detect this situation and print the *real* problem.
-
+
"pull --squash" should do fetch-synthesize-merge, but instead just
does "pull" directly, which doesn't work at all.
diff --git a/contrib/svn-fe/.gitignore b/contrib/svn-fe/.gitignore
deleted file mode 100644
index 02a7791..0000000
--- a/contrib/svn-fe/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/*.xml
-/*.1
-/*.html
-/svn-fe
diff --git a/contrib/svn-fe/Makefile b/contrib/svn-fe/Makefile
deleted file mode 100644
index e8651aa..0000000
--- a/contrib/svn-fe/Makefile
+++ /dev/null
@@ -1,105 +0,0 @@
-all:: svn-fe$X
-
-CC = cc
-RM = rm -f
-MV = mv
-
-CFLAGS = -g -O2 -Wall
-LDFLAGS =
-EXTLIBS = -lz
-
-include ../../config.mak.uname
--include ../../config.mak.autogen
--include ../../config.mak
-
-ifeq ($(uname_S),Darwin)
- ifndef NO_FINK
- ifeq ($(shell test -d /sw/lib && echo y),y)
- CFLAGS += -I/sw/include
- LDFLAGS += -L/sw/lib
- endif
- endif
- ifndef NO_DARWIN_PORTS
- ifeq ($(shell test -d /opt/local/lib && echo y),y)
- CFLAGS += -I/opt/local/include
- LDFLAGS += -L/opt/local/lib
- endif
- endif
-endif
-
-ifndef NO_OPENSSL
- EXTLIBS += -lssl
- ifdef NEEDS_CRYPTO_WITH_SSL
- EXTLIBS += -lcrypto
- endif
-endif
-
-ifndef NO_PTHREADS
- CFLAGS += $(PTHREADS_CFLAGS)
- EXTLIBS += $(PTHREAD_LIBS)
-endif
-
-ifdef HAVE_CLOCK_GETTIME
- CFLAGS += -DHAVE_CLOCK_GETTIME
- EXTLIBS += -lrt
-endif
-
-ifdef NEEDS_LIBICONV
- EXTLIBS += -liconv
-endif
-
-GIT_LIB = ../../libgit.a
-VCSSVN_LIB = ../../vcs-svn/lib.a
-XDIFF_LIB = ../../xdiff/lib.a
-
-LIBS = $(VCSSVN_LIB) $(GIT_LIB) $(XDIFF_LIB)
-
-QUIET_SUBDIR0 = +$(MAKE) -C # space to separate -C and subdir
-QUIET_SUBDIR1 =
-
-ifneq ($(findstring $(MAKEFLAGS),w),w)
-PRINT_DIR = --no-print-directory
-else # "make -w"
-NO_SUBDIR = :
-endif
-
-ifneq ($(findstring $(MAKEFLAGS),s),s)
-ifndef V
- QUIET_CC = @echo ' ' CC $@;
- QUIET_LINK = @echo ' ' LINK $@;
- QUIET_SUBDIR0 = +@subdir=
- QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
- $(MAKE) $(PRINT_DIR) -C $$subdir
-endif
-endif
-
-svn-fe$X: svn-fe.o $(VCSSVN_LIB) $(XDIFF_LIB) $(GIT_LIB)
- $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(EXTLIBS) -o $@ svn-fe.o $(LIBS)
-
-svn-fe.o: svn-fe.c ../../vcs-svn/svndump.h
- $(QUIET_CC)$(CC) $(CFLAGS) -I../../vcs-svn -o $*.o -c $<
-
-svn-fe.html: svn-fe.txt
- $(QUIET_SUBDIR0)../../Documentation $(QUIET_SUBDIR1) \
- MAN_TXT=../contrib/svn-fe/svn-fe.txt \
- ../contrib/svn-fe/$@
-
-svn-fe.1: svn-fe.txt
- $(QUIET_SUBDIR0)../../Documentation $(QUIET_SUBDIR1) \
- MAN_TXT=../contrib/svn-fe/svn-fe.txt \
- ../contrib/svn-fe/$@
- $(MV) ../../Documentation/svn-fe.1 .
-
-../../vcs-svn/lib.a: FORCE
- $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) vcs-svn/lib.a
-
-../../xdiff/lib.a: FORCE
- $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) xdiff/lib.a
-
-../../libgit.a: FORCE
- $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) libgit.a
-
-clean:
- $(RM) svn-fe$X svn-fe.o svn-fe.html svn-fe.xml svn-fe.1
-
-.PHONY: all clean FORCE
diff --git a/contrib/svn-fe/svn-fe.c b/contrib/svn-fe/svn-fe.c
deleted file mode 100644
index f363505..0000000
--- a/contrib/svn-fe/svn-fe.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * This file is in the public domain.
- * You may freely use, modify, distribute, and relicense it.
- */
-
-#include <stdlib.h>
-#include "svndump.h"
-
-int main(int argc, char **argv)
-{
- if (svndump_init(NULL))
- return 1;
- svndump_read((argc > 1) ? argv[1] : NULL, "refs/heads/master",
- "refs/notes/svn/revs");
- svndump_deinit();
- svndump_reset();
- return 0;
-}
diff --git a/contrib/svn-fe/svn-fe.txt b/contrib/svn-fe/svn-fe.txt
deleted file mode 100644
index 19333fc..0000000
--- a/contrib/svn-fe/svn-fe.txt
+++ /dev/null
@@ -1,71 +0,0 @@
-svn-fe(1)
-=========
-
-NAME
-----
-svn-fe - convert an SVN "dumpfile" to a fast-import stream
-
-SYNOPSIS
---------
-[verse]
-mkfifo backchannel &&
-svnadmin dump --deltas REPO |
- svn-fe [url] 3<backchannel |
- git fast-import --cat-blob-fd=3 3>backchannel
-
-DESCRIPTION
------------
-
-Converts a Subversion dumpfile into input suitable for
-git-fast-import(1) and similar importers. REPO is a path to a
-Subversion repository mirrored on the local disk. Remote Subversion
-repositories can be mirrored on local disk using the `svnsync`
-command.
-
-Note: this tool is very young. The details of its commandline
-interface may change in backward incompatible ways.
-
-INPUT FORMAT
-------------
-Subversion's repository dump format is documented in full in
-`notes/dump-load-format.txt` from the Subversion source tree.
-Files in this format can be generated using the 'svnadmin dump' or
-'svk admin dump' command.
-
-OUTPUT FORMAT
--------------
-The fast-import format is documented by the git-fast-import(1)
-manual page.
-
-NOTES
------
-Subversion dumps do not record a separate author and committer for
-each revision, nor do they record a separate display name and email
-address for each author. Like git-svn(1), 'svn-fe' will use the name
-
----------
-user <user@UUID>
----------
-
-as committer, where 'user' is the value of the `svn:author` property
-and 'UUID' the repository's identifier.
-
-To support incremental imports, 'svn-fe' puts a `git-svn-id` line at
-the end of each commit log message if passed a URL on the command
-line. This line has the form `git-svn-id: URL@REVNO UUID`.
-
-The resulting repository will generally require further processing
-to put each project in its own repository and to separate the history
-of each branch. The 'git filter-repo --subdirectory-filter' command
-may be useful for this purpose.
-
-BUGS
-----
-Empty directories and unknown properties are silently discarded.
-
-The exit status does not reflect whether an error was detected.
-
-SEE ALSO
---------
-git-svn(1), svn2git(1), svk(1), git-filter-repo(1), git-fast-import(1),
-https://svn.apache.org/repos/asf/subversion/trunk/notes/dump-load-format.txt
diff --git a/contrib/svn-fe/svnrdump_sim.py b/contrib/svn-fe/svnrdump_sim.py
deleted file mode 100755
index 50c6a4f..0000000
--- a/contrib/svn-fe/svnrdump_sim.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/usr/bin/env python
-"""
-Simulates svnrdump by replaying an existing dump from a file, taking care
-of the specified revision range.
-To simulate incremental imports the environment variable SVNRMAX can be set
-to the highest revision that should be available.
-"""
-import sys
-import os
-
-if sys.hexversion < 0x02040000:
- # The limiter is the ValueError() calls. This may be too conservative
- sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n")
- sys.exit(1)
-
-
-def getrevlimit():
- var = 'SVNRMAX'
- if var in os.environ:
- return os.environ[var]
- return None
-
-
-def writedump(url, lower, upper):
- if url.startswith('sim://'):
- filename = url[6:]
- if filename[-1] == '/':
- filename = filename[:-1] # remove terminating slash
- else:
- raise ValueError('sim:// url required')
- f = open(filename, 'r')
- state = 'header'
- wroterev = False
- while(True):
- l = f.readline()
- if l == '':
- break
- if state == 'header' and l.startswith('Revision-number: '):
- state = 'prefix'
- if state == 'prefix' and l == 'Revision-number: %s\n' % lower:
- state = 'selection'
- if not upper == 'HEAD' and state == 'selection' and \
- l == 'Revision-number: %s\n' % upper:
- break
-
- if state == 'header' or state == 'selection':
- if state == 'selection':
- wroterev = True
- sys.stdout.write(l)
- return wroterev
-
-if __name__ == "__main__":
- if not (len(sys.argv) in (3, 4, 5)):
- print("usage: %s dump URL -rLOWER:UPPER")
- sys.exit(1)
- if not sys.argv[1] == 'dump':
- raise NotImplementedError('only "dump" is suppported.')
- url = sys.argv[2]
- r = ('0', 'HEAD')
- if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r':
- r = sys.argv[3][2:].lstrip().split(':')
- if not getrevlimit() is None:
- r[1] = getrevlimit()
- if writedump(url, r[0], r[1]):
- ret = 0
- else:
- ret = 1
- sys.exit(ret)
diff --git a/contrib/vscode/README.md b/contrib/vscode/README.md
index 8202d62..f383c95 100644
--- a/contrib/vscode/README.md
+++ b/contrib/vscode/README.md
@@ -6,7 +6,11 @@ code editor which runs on your desktop and is available for
[Windows](https://code.visualstudio.com/docs/setup/windows),
[macOS](https://code.visualstudio.com/docs/setup/mac) and
[Linux](https://code.visualstudio.com/docs/setup/linux). Among other languages,
-it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools).
+it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools) with
+[debugging support](https://code.visualstudio.com/docs/editor/debugging)
+
+To get help about "how to personalize your settings" read:
+[How to set up your settings](https://code.visualstudio.com/docs/getstarted/settings)
To start developing Git with VS Code, simply run the Unix shell script called
`init.sh` in this directory, which creates the configuration files in
diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh
index 27de949..f2d61bb 100755
--- a/contrib/vscode/init.sh
+++ b/contrib/vscode/init.sh
@@ -25,8 +25,12 @@ cat >.vscode/settings.json.new <<\EOF ||
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 8,
- "editor.wordWrap": "wordWrapColumn",
- "editor.wordWrapColumn": 80,
+ "files.trimTrailingWhitespace": true
+ },
+ "[txt]": {
+ "editor.detectIndentation": false,
+ "editor.insertSpaces": false,
+ "editor.tabSize": 8,
"files.trimTrailingWhitespace": true
},
"files.associations": {
@@ -88,7 +92,6 @@ cat >.vscode/settings.json.new <<\EOF ||
"isexe",
"iskeychar",
"kompare",
- "mksnpath",
"mktag",
"mktree",
"mmblob",
@@ -271,7 +274,6 @@ cat >.vscode/launch.json.new <<EOF ||
"stopAtEntry": false,
"cwd": "\${workspaceFolder}",
"environment": [],
- "externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "$GDBPATH",
"setupCommands": [
diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir
index 888c34a..989197a 100755
--- a/contrib/workdir/git-new-workdir
+++ b/contrib/workdir/git-new-workdir
@@ -79,7 +79,7 @@ trap cleanup $siglist
# create the links to the original repo. explicitly exclude index, HEAD and
# logs/HEAD from the list since they are purely related to the current working
# directory, and should not be shared.
-for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
+for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn reftable
do
# create a containing directory if needed
case $x in