summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/buildsystems/CMakeLists.txt33
-rw-r--r--contrib/coccinelle/.gitignore2
-rw-r--r--contrib/coccinelle/README49
-rw-r--r--contrib/coccinelle/hashmap.cocci2
-rw-r--r--contrib/coccinelle/index-compatibility.cocci139
-rw-r--r--contrib/coccinelle/index-compatibility.pending.cocci24
-rw-r--r--contrib/coccinelle/preincr.cocci2
-rwxr-xr-xcontrib/coccinelle/spatchcache304
-rw-r--r--contrib/coccinelle/strbuf.cocci2
-rw-r--r--contrib/coccinelle/swap.cocci2
-rw-r--r--contrib/coccinelle/the_repository.pending.cocci1
-rw-r--r--contrib/completion/git-prompt.sh12
-rwxr-xr-xcontrib/credential/netrc/git-credential-netrc.perl5
-rwxr-xr-xcontrib/credential/netrc/t-git-credential-netrc.sh18
-rw-r--r--contrib/credential/osxkeychain/git-credential-osxkeychain.c5
-rw-r--r--contrib/credential/wincred/git-credential-wincred.c7
-rw-r--r--contrib/scalar/.gitignore2
-rw-r--r--contrib/scalar/Makefile35
-rw-r--r--contrib/scalar/scalar.c1132
-rw-r--r--contrib/scalar/scalar.txt166
-rw-r--r--contrib/scalar/t/Makefile81
-rwxr-xr-xcontrib/scalar/t/t9099-scalar.sh123
-rwxr-xr-xcontrib/subtree/git-subtree.sh177
-rw-r--r--contrib/subtree/git-subtree.txt16
-rw-r--r--contrib/subtree/t/Makefile3
-rwxr-xr-xcontrib/subtree/t/t7900-subtree.sh60
26 files changed, 755 insertions, 1647 deletions
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index 2237109..2f6e019 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -308,6 +308,8 @@ if(SUPPORTS_SIMPLE_IPC)
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)
@@ -315,6 +317,8 @@ if(SUPPORTS_SIMPLE_IPC)
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)
@@ -610,7 +614,7 @@ unset(CMAKE_REQUIRED_INCLUDES)
#programs
set(PROGRAMS_BUILT
git git-daemon git-http-backend git-sh-i18n--envsubst
- git-shell)
+ git-shell scalar)
if(NOT CURL_FOUND)
list(APPEND excluded_progs git-http-fetch git-http-push)
@@ -757,6 +761,9 @@ 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)
@@ -903,7 +910,7 @@ list(TRANSFORM git_perl_scripts PREPEND "${CMAKE_BINARY_DIR}/")
#install
foreach(program ${PROGRAMS_BUILT})
-if(program STREQUAL "git" OR program STREQUAL "git-shell")
+if(program MATCHES "^(git|git-shell|scalar)$")
install(TARGETS ${program}
RUNTIME DESTINATION bin)
else()
@@ -977,7 +984,7 @@ endif()
#wrapper scripts
set(wrapper_scripts
- git git-upload-pack git-receive-pack git-upload-archive git-shell git-remote-ext)
+ 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)
@@ -1018,7 +1025,6 @@ set(NO_PERL )
set(NO_PTHREADS )
set(NO_PYTHON )
set(PAGER_ENV "LESS=FRX LV=-c")
-set(DC_SHA1 YesPlease)
set(RUNTIME_PREFIX true)
set(NO_GETTEXT )
@@ -1054,7 +1060,6 @@ 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 "DC_SHA1='${DC_SHA1}'\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")
@@ -1067,18 +1072,14 @@ 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})
- file(RELATIVE_PATH BUILD_DIR_RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/CMakeCache.txt)
- string(REPLACE "/CMakeCache.txt" "" BUILD_DIR_RELATIVE ${BUILD_DIR_RELATIVE})
#Setting the build directory in test-lib.sh before running tests
file(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
- "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh GIT_BUILD_DIR_REPL REGEX \"GIT_BUILD_DIR=(.*)\")\n"
- "file(STRINGS ${CMAKE_SOURCE_DIR}/t/test-lib.sh content NEWLINE_CONSUME)\n"
- "string(REPLACE \"\${GIT_BUILD_DIR_REPL}\" \"GIT_BUILD_DIR=\\\"$TEST_DIRECTORY/../${BUILD_DIR_RELATIVE}\\\"\" content \"\${content}\")\n"
- "file(WRITE ${CMAKE_SOURCE_DIR}/t/test-lib.sh \${content})")
+ "file(WRITE ${CMAKE_SOURCE_DIR}/GIT-BUILD-DIR \"${CMAKE_BINARY_DIR}\")")
#misc copies
- file(COPY ${CMAKE_SOURCE_DIR}/t/chainlint.sed DESTINATION ${CMAKE_BINARY_DIR}/t/)
+ 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(COPY ${CMAKE_SOURCE_DIR}/mergetools/tkdiff DESTINATION ${CMAKE_BINARY_DIR}/mergetools/)
+ 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()
@@ -1088,8 +1089,12 @@ file(GLOB test_scipts "${CMAKE_SOURCE_DIR}/t/t[0-9]*.sh")
#test
foreach(tsh ${test_scipts})
add_test(NAME ${tsh}
- COMMAND ${SH_EXE} ${tsh}
+ 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("${CMAKE_SOURCE_DIR}/t/t7112-reset-submodule.sh" PROPERTIES TIMEOUT 4000)
+
endif()#BUILD_TESTING
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..d1daa1f 100644
--- a/contrib/coccinelle/README
+++ b/contrib/coccinelle/README
@@ -41,3 +41,52 @@ 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.
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..8520f03
--- /dev/null
+++ b/contrib/coccinelle/index-compatibility.cocci
@@ -0,0 +1,139 @@
+// the_index.* variables
+@@
+identifier AC = active_cache;
+identifier ACC = active_cache_changed;
+identifier ACT = active_cache_tree;
+@@
+(
+- AC
++ the_index.cache
+|
+- ACC
++ the_index.cache_changed
+|
+- ACT
++ the_index.cache_tree
+)
+
+@@
+identifier AN = active_nr;
+identifier f != prepare_to_commit;
+@@
+ f(...) {<...
+- AN
++ the_index.cache_nr
+ ...>}
+
+// "the_repository" simple cases
+@@
+@@
+(
+- 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
+)
+ (
++ &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
+ )
diff --git a/contrib/coccinelle/index-compatibility.pending.cocci b/contrib/coccinelle/index-compatibility.pending.cocci
new file mode 100644
index 0000000..01f875d
--- /dev/null
+++ b/contrib/coccinelle/index-compatibility.pending.cocci
@@ -0,0 +1,24 @@
+// "the_repository" simple cases
+@@
+@@
+(
+- read_cache
++ repo_read_index
+)
+ (
++ the_repository,
+ ...)
+
+// "the_index" simple cases
+@@
+@@
+(
+- discard_cache
++ discard_index
+|
+- cache_name_pos
++ index_name_pos
+)
+ (
++ &the_index,
+ ...)
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 0970d98..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 !~ "%";
@@
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/the_repository.pending.cocci b/contrib/coccinelle/the_repository.pending.cocci
index 072ea0d..747d382 100644
--- a/contrib/coccinelle/the_repository.pending.cocci
+++ b/contrib/coccinelle/the_repository.pending.cocci
@@ -20,7 +20,6 @@ expression E;
@@
expression E;
-expression F;
@@
- has_object_file_with_flags(
+ repo_has_object_file_with_flags(the_repository,
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 1435548..57972c2 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -84,6 +84,10 @@
# 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:
@@ -508,6 +512,12 @@ __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=""
@@ -572,7 +582,7 @@ __git_ps1 ()
fi
local f="$h$w$i$s$u$p"
- local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}"
+ 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/credential/netrc/git-credential-netrc.perl b/contrib/credential/netrc/git-credential-netrc.perl
index bc57cc6..9fb998a 100755
--- a/contrib/credential/netrc/git-credential-netrc.perl
+++ 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");
}
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/git-credential-osxkeychain.c b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
index bf77748..e29cc28 100644
--- a/contrib/credential/osxkeychain/git-credential-osxkeychain.c
+++ b/contrib/credential/osxkeychain/git-credential-osxkeychain.c
@@ -159,6 +159,11 @@ static void read_credential(void)
username = xstrdup(v);
else if (!strcmp(buf, "password"))
password = xstrdup(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.
+ */
}
}
diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c
index 5091048..ead6e26 100644
--- a/contrib/credential/wincred/git-credential-wincred.c
+++ b/contrib/credential/wincred/git-credential-wincred.c
@@ -278,8 +278,11 @@ 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");
+ /*
+ * 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.
+ */
}
}
diff --git a/contrib/scalar/.gitignore b/contrib/scalar/.gitignore
deleted file mode 100644
index ff3d47e..0000000
--- a/contrib/scalar/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/*.exe
-/scalar
diff --git a/contrib/scalar/Makefile b/contrib/scalar/Makefile
deleted file mode 100644
index 37f283f..0000000
--- a/contrib/scalar/Makefile
+++ /dev/null
@@ -1,35 +0,0 @@
-# The default target of this Makefile is...
-all::
-
-# Import tree-wide shared Makefile behavior and libraries
-include ../../shared.mak
-
-include ../../config.mak.uname
--include ../../config.mak.autogen
--include ../../config.mak
-
-TARGETS = scalar$(X) scalar.o
-GITLIBS = ../../common-main.o ../../libgit.a ../../xdiff/lib.a
-
-all:: scalar$(X) ../../bin-wrappers/scalar
-
-$(GITLIBS):
- $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(subst ../../,,$@)
-
-$(TARGETS): $(GITLIBS) scalar.c
- $(QUIET_SUBDIR0)../.. $(QUIET_SUBDIR1) $(patsubst %,contrib/scalar/%,$@)
-
-clean:
- $(RM) $(TARGETS) ../../bin-wrappers/scalar
-
-../../bin-wrappers/scalar: ../../wrap-for-bin.sh Makefile
- @mkdir -p ../../bin-wrappers
- $(QUIET_GEN)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
- -e 's|@@BUILD_DIR@@|$(shell cd ../.. && pwd)|' \
- -e 's|@@PROG@@|contrib/scalar/scalar$(X)|' < $< > $@ && \
- chmod +x $@
-
-test: all
- $(MAKE) -C t
-
-.PHONY: $(GITLIBS) all clean test FORCE
diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c
deleted file mode 100644
index 97e71fe..0000000
--- a/contrib/scalar/scalar.c
+++ /dev/null
@@ -1,1132 +0,0 @@
-/*
- * The Scalar command-line interface.
- */
-
-#include "cache.h"
-#include "gettext.h"
-#include "parse-options.h"
-#include "config.h"
-#include "run-command.h"
-#include "refs.h"
-#include "dir.h"
-#include "packfile.h"
-#include "help.h"
-#include "archive.h"
-#include "object-store.h"
-
-/*
- * Remove the deepest subdirectory in the provided path string. Path must not
- * include a trailing path separator. Returns 1 if parent directory found,
- * otherwise 0.
- */
-static int strbuf_parent_directory(struct strbuf *buf)
-{
- size_t len = buf->len;
- size_t offset = offset_1st_component(buf->buf);
- char *path_sep = find_last_dir_sep(buf->buf + offset);
- strbuf_setlen(buf, path_sep ? path_sep - buf->buf : offset);
-
- return buf->len < len;
-}
-
-static void setup_enlistment_directory(int argc, const char **argv,
- const char * const *usagestr,
- const struct option *options,
- struct strbuf *enlistment_root)
-{
- struct strbuf path = STRBUF_INIT;
- char *root;
- int enlistment_found = 0;
-
- if (startup_info->have_repository)
- BUG("gitdir already set up?!?");
-
- if (argc > 1)
- usage_with_options(usagestr, options);
-
- /* find the worktree, determine its corresponding root */
- if (argc == 1) {
- strbuf_add_absolute_path(&path, argv[0]);
- if (!is_directory(path.buf))
- die(_("'%s' does not exist"), path.buf);
- } else if (strbuf_getcwd(&path) < 0)
- die(_("need a working directory"));
-
- strbuf_trim_trailing_dir_sep(&path);
- do {
- const size_t len = path.len;
-
- /* check if currently in enlistment root with src/ workdir */
- strbuf_addstr(&path, "/src");
- if (is_nonbare_repository_dir(&path)) {
- if (enlistment_root)
- strbuf_add(enlistment_root, path.buf, len);
-
- enlistment_found = 1;
- break;
- }
-
- /* reset to original path */
- strbuf_setlen(&path, len);
-
- /* check if currently in workdir */
- if (is_nonbare_repository_dir(&path)) {
- if (enlistment_root) {
- /*
- * If the worktree's directory's name is `src`, the enlistment is the
- * parent directory, otherwise it is identical to the worktree.
- */
- root = strip_path_suffix(path.buf, "src");
- strbuf_addstr(enlistment_root, root ? root : path.buf);
- free(root);
- }
-
- enlistment_found = 1;
- break;
- }
- } while (strbuf_parent_directory(&path));
-
- if (!enlistment_found)
- die(_("could not find enlistment root"));
-
- if (chdir(path.buf) < 0)
- die_errno(_("could not switch to '%s'"), path.buf);
-
- strbuf_release(&path);
- setup_git_directory();
-}
-
-static int run_git(const char *arg, ...)
-{
- struct strvec argv = STRVEC_INIT;
- va_list args;
- const char *p;
- int res;
-
- va_start(args, arg);
- strvec_push(&argv, arg);
- while ((p = va_arg(args, const char *)))
- strvec_push(&argv, p);
- va_end(args);
-
- res = run_command_v_opt(argv.v, RUN_GIT_CMD);
-
- strvec_clear(&argv);
- return res;
-}
-
-static int set_recommended_config(int reconfigure)
-{
- struct {
- const char *key;
- const char *value;
- int overwrite_on_reconfigure;
- } config[] = {
- /* Required */
- { "am.keepCR", "true", 1 },
- { "core.FSCache", "true", 1 },
- { "core.multiPackIndex", "true", 1 },
- { "core.preloadIndex", "true", 1 },
-#ifndef WIN32
- { "core.untrackedCache", "true", 1 },
-#else
- /*
- * Unfortunately, Scalar's Functional Tests demonstrated
- * that the untracked cache feature is unreliable on Windows
- * (which is a bummer because that platform would benefit the
- * most from it). For some reason, freshly created files seem
- * not to update the directory's `lastModified` time
- * immediately, but the untracked cache would need to rely on
- * that.
- *
- * Therefore, with a sad heart, we disable this very useful
- * feature on Windows.
- */
- { "core.untrackedCache", "false", 1 },
-#endif
- { "core.logAllRefUpdates", "true", 1 },
- { "credential.https://dev.azure.com.useHttpPath", "true", 1 },
- { "credential.validate", "false", 1 }, /* GCM4W-only */
- { "gc.auto", "0", 1 },
- { "gui.GCWarning", "false", 1 },
- { "index.threads", "true", 1 },
- { "index.version", "4", 1 },
- { "merge.stat", "false", 1 },
- { "merge.renames", "true", 1 },
- { "pack.useBitmaps", "false", 1 },
- { "pack.useSparse", "true", 1 },
- { "receive.autoGC", "false", 1 },
- { "feature.manyFiles", "false", 1 },
- { "feature.experimental", "false", 1 },
- { "fetch.unpackLimit", "1", 1 },
- { "fetch.writeCommitGraph", "false", 1 },
-#ifdef WIN32
- { "http.sslBackend", "schannel", 1 },
-#endif
- /* Optional */
- { "status.aheadBehind", "false" },
- { "commitGraph.generationVersion", "1" },
- { "core.autoCRLF", "false" },
- { "core.safeCRLF", "false" },
- { "fetch.showForcedUpdates", "false" },
- { NULL, NULL },
- };
- int i;
- char *value;
-
- for (i = 0; config[i].key; i++) {
- if ((reconfigure && config[i].overwrite_on_reconfigure) ||
- git_config_get_string(config[i].key, &value)) {
- trace2_data_string("scalar", the_repository, config[i].key, "created");
- if (git_config_set_gently(config[i].key,
- config[i].value) < 0)
- return error(_("could not configure %s=%s"),
- config[i].key, config[i].value);
- } else {
- trace2_data_string("scalar", the_repository, config[i].key, "exists");
- free(value);
- }
- }
-
- /*
- * The `log.excludeDecoration` setting is special because it allows
- * for multiple values.
- */
- if (git_config_get_string("log.excludeDecoration", &value)) {
- trace2_data_string("scalar", the_repository,
- "log.excludeDecoration", "created");
- if (git_config_set_multivar_gently("log.excludeDecoration",
- "refs/prefetch/*",
- CONFIG_REGEX_NONE, 0))
- return error(_("could not configure "
- "log.excludeDecoration"));
- } else {
- trace2_data_string("scalar", the_repository,
- "log.excludeDecoration", "exists");
- free(value);
- }
-
- return 0;
-}
-
-static int toggle_maintenance(int enable)
-{
- return run_git("maintenance", enable ? "start" : "unregister", NULL);
-}
-
-static int add_or_remove_enlistment(int add)
-{
- int res;
-
- if (!the_repository->worktree)
- die(_("Scalar enlistments require a worktree"));
-
- res = run_git("config", "--global", "--get", "--fixed-value",
- "scalar.repo", the_repository->worktree, NULL);
-
- /*
- * If we want to add and the setting is already there, then do nothing.
- * If we want to remove and the setting is not there, then do nothing.
- */
- if ((add && !res) || (!add && res))
- return 0;
-
- return run_git("config", "--global", add ? "--add" : "--unset",
- add ? "--no-fixed-value" : "--fixed-value",
- "scalar.repo", the_repository->worktree, NULL);
-}
-
-static int register_dir(void)
-{
- int res = add_or_remove_enlistment(1);
-
- if (!res)
- res = set_recommended_config(0);
-
- if (!res)
- res = toggle_maintenance(1);
-
- return res;
-}
-
-static int unregister_dir(void)
-{
- int res = 0;
-
- if (toggle_maintenance(0) < 0)
- res = -1;
-
- if (add_or_remove_enlistment(0) < 0)
- res = -1;
-
- return res;
-}
-
-static int add_directory_to_archiver(struct strvec *archiver_args,
- const char *path, int recurse)
-{
- int at_root = !*path;
- DIR *dir = opendir(at_root ? "." : path);
- struct dirent *e;
- struct strbuf buf = STRBUF_INIT;
- size_t len;
- int res = 0;
-
- if (!dir)
- return error_errno(_("could not open directory '%s'"), path);
-
- if (!at_root)
- strbuf_addf(&buf, "%s/", path);
- len = buf.len;
- strvec_pushf(archiver_args, "--prefix=%s", buf.buf);
-
- while (!res && (e = readdir(dir))) {
- if (!strcmp(".", e->d_name) || !strcmp("..", e->d_name))
- continue;
-
- strbuf_setlen(&buf, len);
- strbuf_addstr(&buf, e->d_name);
-
- if (e->d_type == DT_REG)
- strvec_pushf(archiver_args, "--add-file=%s", buf.buf);
- else if (e->d_type != DT_DIR)
- warning(_("skipping '%s', which is neither file nor "
- "directory"), buf.buf);
- else if (recurse &&
- add_directory_to_archiver(archiver_args,
- buf.buf, recurse) < 0)
- res = -1;
- }
-
- closedir(dir);
- strbuf_release(&buf);
- return res;
-}
-
-#ifndef WIN32
-#include <sys/statvfs.h>
-#endif
-
-static int get_disk_info(struct strbuf *out)
-{
-#ifdef WIN32
- struct strbuf buf = STRBUF_INIT;
- char volume_name[MAX_PATH], fs_name[MAX_PATH];
- DWORD serial_number, component_length, flags;
- ULARGE_INTEGER avail2caller, total, avail;
-
- strbuf_realpath(&buf, ".", 1);
- if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) {
- error(_("could not determine free disk size for '%s'"),
- buf.buf);
- strbuf_release(&buf);
- return -1;
- }
-
- strbuf_setlen(&buf, offset_1st_component(buf.buf));
- if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name),
- &serial_number, &component_length, &flags,
- fs_name, sizeof(fs_name))) {
- error(_("could not get info for '%s'"), buf.buf);
- strbuf_release(&buf);
- return -1;
- }
- strbuf_addf(out, "Available space on '%s': ", buf.buf);
- strbuf_humanise_bytes(out, avail2caller.QuadPart);
- strbuf_addch(out, '\n');
- strbuf_release(&buf);
-#else
- struct strbuf buf = STRBUF_INIT;
- struct statvfs stat;
-
- strbuf_realpath(&buf, ".", 1);
- if (statvfs(buf.buf, &stat) < 0) {
- error_errno(_("could not determine free disk size for '%s'"),
- buf.buf);
- strbuf_release(&buf);
- return -1;
- }
-
- strbuf_addf(out, "Available space on '%s': ", buf.buf);
- strbuf_humanise_bytes(out, st_mult(stat.f_bsize, stat.f_bavail));
- strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag);
- strbuf_release(&buf);
-#endif
- return 0;
-}
-
-/* printf-style interface, expects `<key>=<value>` argument */
-static int set_config(const char *fmt, ...)
-{
- struct strbuf buf = STRBUF_INIT;
- char *value;
- int res;
- va_list args;
-
- va_start(args, fmt);
- strbuf_vaddf(&buf, fmt, args);
- va_end(args);
-
- value = strchr(buf.buf, '=');
- if (value)
- *(value++) = '\0';
- res = git_config_set_gently(buf.buf, value);
- strbuf_release(&buf);
-
- return res;
-}
-
-static char *remote_default_branch(const char *url)
-{
- struct child_process cp = CHILD_PROCESS_INIT;
- struct strbuf out = STRBUF_INIT;
-
- cp.git_cmd = 1;
- strvec_pushl(&cp.args, "ls-remote", "--symref", url, "HEAD", NULL);
- if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) {
- const char *line = out.buf;
-
- while (*line) {
- const char *eol = strchrnul(line, '\n'), *p;
- size_t len = eol - line;
- char *branch;
-
- if (!skip_prefix(line, "ref: ", &p) ||
- !strip_suffix_mem(line, &len, "\tHEAD")) {
- line = eol + (*eol == '\n');
- continue;
- }
-
- eol = line + len;
- if (skip_prefix(p, "refs/heads/", &p)) {
- branch = xstrndup(p, eol - p);
- strbuf_release(&out);
- return branch;
- }
-
- error(_("remote HEAD is not a branch: '%.*s'"),
- (int)(eol - p), p);
- strbuf_release(&out);
- return NULL;
- }
- }
- warning(_("failed to get default branch name from remote; "
- "using local default"));
- strbuf_reset(&out);
-
- child_process_init(&cp);
- cp.git_cmd = 1;
- strvec_pushl(&cp.args, "symbolic-ref", "--short", "HEAD", NULL);
- if (!pipe_command(&cp, NULL, 0, &out, 0, NULL, 0)) {
- strbuf_trim(&out);
- return strbuf_detach(&out, NULL);
- }
-
- strbuf_release(&out);
- error(_("failed to get default branch name"));
- return NULL;
-}
-
-static int delete_enlistment(struct strbuf *enlistment)
-{
-#ifdef WIN32
- struct strbuf parent = STRBUF_INIT;
-#endif
-
- if (unregister_dir())
- die(_("failed to unregister repository"));
-
-#ifdef WIN32
- /*
- * Change the current directory to one outside of the enlistment so
- * that we may delete everything underneath it.
- */
- strbuf_addbuf(&parent, enlistment);
- strbuf_parent_directory(&parent);
- if (chdir(parent.buf) < 0)
- die_errno(_("could not switch to '%s'"), parent.buf);
- strbuf_release(&parent);
-#endif
-
- if (remove_dir_recursively(enlistment, 0))
- die(_("failed to delete enlistment directory"));
-
- return 0;
-}
-
-/*
- * Dummy implementation; Using `get_version_info()` would cause a link error
- * without this.
- */
-void load_builtin_commands(const char *prefix, struct cmdnames *cmds)
-{
- die("not implemented");
-}
-
-static int cmd_clone(int argc, const char **argv)
-{
- const char *branch = NULL;
- int full_clone = 0, single_branch = 0;
- struct option clone_options[] = {
- OPT_STRING('b', "branch", &branch, N_("<branch>"),
- N_("branch to checkout after clone")),
- OPT_BOOL(0, "full-clone", &full_clone,
- N_("when cloning, create full working directory")),
- OPT_BOOL(0, "single-branch", &single_branch,
- N_("only download metadata for the branch that will "
- "be checked out")),
- OPT_END(),
- };
- const char * const clone_usage[] = {
- N_("scalar clone [<options>] [--] <repo> [<dir>]"),
- NULL
- };
- const char *url;
- char *enlistment = NULL, *dir = NULL;
- struct strbuf buf = STRBUF_INIT;
- int res;
-
- argc = parse_options(argc, argv, NULL, clone_options, clone_usage, 0);
-
- if (argc == 2) {
- url = argv[0];
- enlistment = xstrdup(argv[1]);
- } else if (argc == 1) {
- url = argv[0];
-
- strbuf_addstr(&buf, url);
- /* Strip trailing slashes, if any */
- while (buf.len > 0 && is_dir_sep(buf.buf[buf.len - 1]))
- strbuf_setlen(&buf, buf.len - 1);
- /* Strip suffix `.git`, if any */
- strbuf_strip_suffix(&buf, ".git");
-
- enlistment = find_last_dir_sep(buf.buf);
- if (!enlistment) {
- die(_("cannot deduce worktree name from '%s'"), url);
- }
- enlistment = xstrdup(enlistment + 1);
- } else {
- usage_msg_opt(_("You must specify a repository to clone."),
- clone_usage, clone_options);
- }
-
- if (is_directory(enlistment))
- die(_("directory '%s' exists already"), enlistment);
-
- dir = xstrfmt("%s/src", enlistment);
-
- strbuf_reset(&buf);
- if (branch)
- strbuf_addf(&buf, "init.defaultBranch=%s", branch);
- else {
- char *b = repo_default_branch_name(the_repository, 1);
- strbuf_addf(&buf, "init.defaultBranch=%s", b);
- free(b);
- }
-
- if ((res = run_git("-c", buf.buf, "init", "--", dir, NULL)))
- goto cleanup;
-
- if (chdir(dir) < 0) {
- res = error_errno(_("could not switch to '%s'"), dir);
- goto cleanup;
- }
-
- setup_git_directory();
-
- /* common-main already logs `argv` */
- trace2_def_repo(the_repository);
-
- if (!branch && !(branch = remote_default_branch(url))) {
- res = error(_("failed to get default branch for '%s'"), url);
- goto cleanup;
- }
-
- if (set_config("remote.origin.url=%s", url) ||
- set_config("remote.origin.fetch="
- "+refs/heads/%s:refs/remotes/origin/%s",
- single_branch ? branch : "*",
- single_branch ? branch : "*") ||
- set_config("remote.origin.promisor=true") ||
- set_config("remote.origin.partialCloneFilter=blob:none")) {
- res = error(_("could not configure remote in '%s'"), dir);
- goto cleanup;
- }
-
- if (!full_clone &&
- (res = run_git("sparse-checkout", "init", "--cone", NULL)))
- goto cleanup;
-
- if (set_recommended_config(0))
- return error(_("could not configure '%s'"), dir);
-
- if ((res = run_git("fetch", "--quiet", "origin", NULL))) {
- warning(_("partial clone failed; attempting full clone"));
-
- if (set_config("remote.origin.promisor") ||
- set_config("remote.origin.partialCloneFilter")) {
- res = error(_("could not configure for full clone"));
- goto cleanup;
- }
-
- if ((res = run_git("fetch", "--quiet", "origin", NULL)))
- goto cleanup;
- }
-
- if ((res = set_config("branch.%s.remote=origin", branch)))
- goto cleanup;
- if ((res = set_config("branch.%s.merge=refs/heads/%s",
- branch, branch)))
- goto cleanup;
-
- strbuf_reset(&buf);
- strbuf_addf(&buf, "origin/%s", branch);
- res = run_git("checkout", "-f", "-t", buf.buf, NULL);
- if (res)
- goto cleanup;
-
- res = register_dir();
-
-cleanup:
- free(enlistment);
- free(dir);
- strbuf_release(&buf);
- return res;
-}
-
-static void dir_file_stats_objects(const char *full_path, size_t full_path_len,
- const char *file_name, void *data)
-{
- struct strbuf *buf = data;
- struct stat st;
-
- if (!stat(full_path, &st))
- strbuf_addf(buf, "%-70s %16" PRIuMAX "\n", file_name,
- (uintmax_t)st.st_size);
-}
-
-static int dir_file_stats(struct object_directory *object_dir, void *data)
-{
- struct strbuf *buf = data;
-
- strbuf_addf(buf, "Contents of %s:\n", object_dir->path);
-
- for_each_file_in_pack_dir(object_dir->path, dir_file_stats_objects,
- data);
-
- return 0;
-}
-
-static int count_files(char *path)
-{
- DIR *dir = opendir(path);
- struct dirent *e;
- int count = 0;
-
- if (!dir)
- return 0;
-
- while ((e = readdir(dir)) != NULL)
- if (!is_dot_or_dotdot(e->d_name) && e->d_type == DT_REG)
- count++;
-
- closedir(dir);
- return count;
-}
-
-static void loose_objs_stats(struct strbuf *buf, const char *path)
-{
- DIR *dir = opendir(path);
- struct dirent *e;
- int count;
- int total = 0;
- unsigned char c;
- struct strbuf count_path = STRBUF_INIT;
- size_t base_path_len;
-
- if (!dir)
- return;
-
- strbuf_addstr(buf, "Object directory stats for ");
- strbuf_add_absolute_path(buf, path);
- strbuf_addstr(buf, ":\n");
-
- strbuf_add_absolute_path(&count_path, path);
- strbuf_addch(&count_path, '/');
- base_path_len = count_path.len;
-
- while ((e = readdir(dir)) != NULL)
- if (!is_dot_or_dotdot(e->d_name) &&
- e->d_type == DT_DIR && strlen(e->d_name) == 2 &&
- !hex_to_bytes(&c, e->d_name, 1)) {
- strbuf_setlen(&count_path, base_path_len);
- strbuf_addstr(&count_path, e->d_name);
- total += (count = count_files(count_path.buf));
- strbuf_addf(buf, "%s : %7d files\n", e->d_name, count);
- }
-
- strbuf_addf(buf, "Total: %d loose objects", total);
-
- strbuf_release(&count_path);
- closedir(dir);
-}
-
-static int cmd_diagnose(int argc, const char **argv)
-{
- struct option options[] = {
- OPT_END(),
- };
- const char * const usage[] = {
- N_("scalar diagnose [<enlistment>]"),
- NULL
- };
- struct strbuf zip_path = STRBUF_INIT;
- struct strvec archiver_args = STRVEC_INIT;
- char **argv_copy = NULL;
- int stdout_fd = -1, archiver_fd = -1;
- time_t now = time(NULL);
- struct tm tm;
- struct strbuf buf = STRBUF_INIT;
- int res = 0;
-
- argc = parse_options(argc, argv, NULL, options,
- usage, 0);
-
- setup_enlistment_directory(argc, argv, usage, options, &zip_path);
-
- strbuf_addstr(&zip_path, "/.scalarDiagnostics/scalar_");
- strbuf_addftime(&zip_path,
- "%Y%m%d_%H%M%S", localtime_r(&now, &tm), 0, 0);
- strbuf_addstr(&zip_path, ".zip");
- switch (safe_create_leading_directories(zip_path.buf)) {
- case SCLD_EXISTS:
- case SCLD_OK:
- break;
- default:
- error_errno(_("could not create directory for '%s'"),
- zip_path.buf);
- goto diagnose_cleanup;
- }
- stdout_fd = dup(1);
- if (stdout_fd < 0) {
- res = error_errno(_("could not duplicate stdout"));
- goto diagnose_cleanup;
- }
-
- archiver_fd = xopen(zip_path.buf, O_CREAT | O_WRONLY | O_TRUNC, 0666);
- if (archiver_fd < 0 || dup2(archiver_fd, 1) < 0) {
- res = error_errno(_("could not redirect output"));
- goto diagnose_cleanup;
- }
-
- init_zip_archiver();
- strvec_pushl(&archiver_args, "scalar-diagnose", "--format=zip", NULL);
-
- strbuf_reset(&buf);
- strbuf_addstr(&buf, "Collecting diagnostic info\n\n");
- get_version_info(&buf, 1);
-
- strbuf_addf(&buf, "Enlistment root: %s\n", the_repository->worktree);
- get_disk_info(&buf);
- write_or_die(stdout_fd, buf.buf, buf.len);
- strvec_pushf(&archiver_args,
- "--add-virtual-file=diagnostics.log:%.*s",
- (int)buf.len, buf.buf);
-
- strbuf_reset(&buf);
- strbuf_addstr(&buf, "--add-virtual-file=packs-local.txt:");
- dir_file_stats(the_repository->objects->odb, &buf);
- foreach_alt_odb(dir_file_stats, &buf);
- strvec_push(&archiver_args, buf.buf);
-
- strbuf_reset(&buf);
- strbuf_addstr(&buf, "--add-virtual-file=objects-local.txt:");
- loose_objs_stats(&buf, ".git/objects");
- strvec_push(&archiver_args, buf.buf);
-
- if ((res = add_directory_to_archiver(&archiver_args, ".git", 0)) ||
- (res = add_directory_to_archiver(&archiver_args, ".git/hooks", 0)) ||
- (res = add_directory_to_archiver(&archiver_args, ".git/info", 0)) ||
- (res = add_directory_to_archiver(&archiver_args, ".git/logs", 1)) ||
- (res = add_directory_to_archiver(&archiver_args, ".git/objects/info", 0)))
- goto diagnose_cleanup;
-
- strvec_pushl(&archiver_args, "--prefix=",
- oid_to_hex(the_hash_algo->empty_tree), "--", NULL);
-
- /* `write_archive()` modifies the `argv` passed to it. Let it. */
- argv_copy = xmemdupz(archiver_args.v,
- sizeof(char *) * archiver_args.nr);
- res = write_archive(archiver_args.nr, (const char **)argv_copy, NULL,
- the_repository, NULL, 0);
- if (res) {
- error(_("failed to write archive"));
- goto diagnose_cleanup;
- }
-
- if (!res)
- fprintf(stderr, "\n"
- "Diagnostics complete.\n"
- "All of the gathered info is captured in '%s'\n",
- zip_path.buf);
-
-diagnose_cleanup:
- if (archiver_fd >= 0) {
- close(1);
- dup2(stdout_fd, 1);
- }
- free(argv_copy);
- strvec_clear(&archiver_args);
- strbuf_release(&zip_path);
- strbuf_release(&buf);
-
- return res;
-}
-
-static int cmd_list(int argc, const char **argv)
-{
- if (argc != 1)
- die(_("`scalar list` does not take arguments"));
-
- if (run_git("config", "--global", "--get-all", "scalar.repo", NULL) < 0)
- return -1;
- return 0;
-}
-
-static int cmd_register(int argc, const char **argv)
-{
- struct option options[] = {
- OPT_END(),
- };
- const char * const usage[] = {
- N_("scalar register [<enlistment>]"),
- NULL
- };
-
- argc = parse_options(argc, argv, NULL, options,
- usage, 0);
-
- setup_enlistment_directory(argc, argv, usage, options, NULL);
-
- return register_dir();
-}
-
-static int get_scalar_repos(const char *key, const char *value, void *data)
-{
- struct string_list *list = data;
-
- if (!strcmp(key, "scalar.repo"))
- string_list_append(list, value);
-
- return 0;
-}
-
-static int cmd_reconfigure(int argc, const char **argv)
-{
- int all = 0;
- struct option options[] = {
- OPT_BOOL('a', "all", &all,
- N_("reconfigure all registered enlistments")),
- OPT_END(),
- };
- const char * const usage[] = {
- N_("scalar reconfigure [--all | <enlistment>]"),
- NULL
- };
- struct string_list scalar_repos = STRING_LIST_INIT_DUP;
- int i, res = 0;
- struct repository r = { NULL };
- struct strbuf commondir = STRBUF_INIT, gitdir = STRBUF_INIT;
-
- argc = parse_options(argc, argv, NULL, options,
- usage, 0);
-
- if (!all) {
- setup_enlistment_directory(argc, argv, usage, options, NULL);
-
- return set_recommended_config(1);
- }
-
- if (argc > 0)
- usage_msg_opt(_("--all or <enlistment>, but not both"),
- usage, options);
-
- git_config(get_scalar_repos, &scalar_repos);
-
- for (i = 0; i < scalar_repos.nr; i++) {
- const char *dir = scalar_repos.items[i].string;
-
- strbuf_reset(&commondir);
- strbuf_reset(&gitdir);
-
- if (chdir(dir) < 0) {
- warning_errno(_("could not switch to '%s'"), dir);
- res = -1;
- } else if (discover_git_directory(&commondir, &gitdir) < 0) {
- warning_errno(_("git repository gone in '%s'"), dir);
- res = -1;
- } else {
- git_config_clear();
-
- the_repository = &r;
- r.commondir = commondir.buf;
- r.gitdir = gitdir.buf;
-
- if (set_recommended_config(1) < 0)
- res = -1;
- }
- }
-
- string_list_clear(&scalar_repos, 1);
- strbuf_release(&commondir);
- strbuf_release(&gitdir);
-
- return res;
-}
-
-static int cmd_run(int argc, const char **argv)
-{
- struct option options[] = {
- OPT_END(),
- };
- struct {
- const char *arg, *task;
- } tasks[] = {
- { "config", NULL },
- { "commit-graph", "commit-graph" },
- { "fetch", "prefetch" },
- { "loose-objects", "loose-objects" },
- { "pack-files", "incremental-repack" },
- { NULL, NULL }
- };
- struct strbuf buf = STRBUF_INIT;
- const char *usagestr[] = { NULL, NULL };
- int i;
-
- strbuf_addstr(&buf, N_("scalar run <task> [<enlistment>]\nTasks:\n"));
- for (i = 0; tasks[i].arg; i++)
- strbuf_addf(&buf, "\t%s\n", tasks[i].arg);
- usagestr[0] = buf.buf;
-
- argc = parse_options(argc, argv, NULL, options,
- usagestr, 0);
-
- if (!argc)
- usage_with_options(usagestr, options);
-
- if (!strcmp("all", argv[0])) {
- i = -1;
- } else {
- for (i = 0; tasks[i].arg && strcmp(tasks[i].arg, argv[0]); i++)
- ; /* keep looking for the task */
-
- if (i > 0 && !tasks[i].arg) {
- error(_("no such task: '%s'"), argv[0]);
- usage_with_options(usagestr, options);
- }
- }
-
- argc--;
- argv++;
- setup_enlistment_directory(argc, argv, usagestr, options, NULL);
- strbuf_release(&buf);
-
- if (i == 0)
- return register_dir();
-
- if (i > 0)
- return run_git("maintenance", "run",
- "--task", tasks[i].task, NULL);
-
- if (register_dir())
- return -1;
- for (i = 1; tasks[i].arg; i++)
- if (run_git("maintenance", "run",
- "--task", tasks[i].task, NULL))
- return -1;
- return 0;
-}
-
-static int remove_deleted_enlistment(struct strbuf *path)
-{
- int res = 0;
- strbuf_realpath_forgiving(path, path->buf, 1);
-
- if (run_git("config", "--global",
- "--unset", "--fixed-value",
- "scalar.repo", path->buf, NULL) < 0)
- res = -1;
-
- if (run_git("config", "--global",
- "--unset", "--fixed-value",
- "maintenance.repo", path->buf, NULL) < 0)
- res = -1;
-
- return res;
-}
-
-static int cmd_unregister(int argc, const char **argv)
-{
- struct option options[] = {
- OPT_END(),
- };
- const char * const usage[] = {
- N_("scalar unregister [<enlistment>]"),
- NULL
- };
-
- argc = parse_options(argc, argv, NULL, options,
- usage, 0);
-
- /*
- * Be forgiving when the enlistment or worktree does not even exist any
- * longer; This can be the case if a user deleted the worktree by
- * mistake and _still_ wants to unregister the thing.
- */
- if (argc == 1) {
- struct strbuf src_path = STRBUF_INIT, workdir_path = STRBUF_INIT;
-
- strbuf_addf(&src_path, "%s/src/.git", argv[0]);
- strbuf_addf(&workdir_path, "%s/.git", argv[0]);
- if (!is_directory(src_path.buf) && !is_directory(workdir_path.buf)) {
- /* remove possible matching registrations */
- int res = -1;
-
- strbuf_strip_suffix(&src_path, "/.git");
- res = remove_deleted_enlistment(&src_path) && res;
-
- strbuf_strip_suffix(&workdir_path, "/.git");
- res = remove_deleted_enlistment(&workdir_path) && res;
-
- strbuf_release(&src_path);
- strbuf_release(&workdir_path);
- return res;
- }
- strbuf_release(&src_path);
- strbuf_release(&workdir_path);
- }
-
- setup_enlistment_directory(argc, argv, usage, options, NULL);
-
- return unregister_dir();
-}
-
-static int cmd_delete(int argc, const char **argv)
-{
- char *cwd = xgetcwd();
- struct option options[] = {
- OPT_END(),
- };
- const char * const usage[] = {
- N_("scalar delete <enlistment>"),
- NULL
- };
- struct strbuf enlistment = STRBUF_INIT;
- int res = 0;
-
- argc = parse_options(argc, argv, NULL, options,
- usage, 0);
-
- if (argc != 1)
- usage_with_options(usage, options);
-
- setup_enlistment_directory(argc, argv, usage, options, &enlistment);
-
- if (dir_inside_of(cwd, enlistment.buf) >= 0)
- res = error(_("refusing to delete current working directory"));
- else {
- close_object_store(the_repository->objects);
- res = delete_enlistment(&enlistment);
- }
- strbuf_release(&enlistment);
- free(cwd);
-
- return res;
-}
-
-static int cmd_version(int argc, const char **argv)
-{
- int verbose = 0, build_options = 0;
- struct option options[] = {
- OPT__VERBOSE(&verbose, N_("include Git version")),
- OPT_BOOL(0, "build-options", &build_options,
- N_("include Git's build options")),
- OPT_END(),
- };
- const char * const usage[] = {
- N_("scalar verbose [-v | --verbose] [--build-options]"),
- NULL
- };
- struct strbuf buf = STRBUF_INIT;
-
- argc = parse_options(argc, argv, NULL, options,
- usage, 0);
-
- if (argc != 0)
- usage_with_options(usage, options);
-
- get_version_info(&buf, build_options);
- fprintf(stderr, "%s\n", buf.buf);
- strbuf_release(&buf);
-
- return 0;
-}
-
-static struct {
- const char *name;
- int (*fn)(int, const char **);
-} builtins[] = {
- { "clone", cmd_clone },
- { "list", cmd_list },
- { "register", cmd_register },
- { "unregister", cmd_unregister },
- { "run", cmd_run },
- { "reconfigure", cmd_reconfigure },
- { "delete", cmd_delete },
- { "version", cmd_version },
- { "diagnose", cmd_diagnose },
- { NULL, NULL},
-};
-
-int cmd_main(int argc, const char **argv)
-{
- struct strbuf scalar_usage = STRBUF_INIT;
- int i;
-
- while (argc > 1 && *argv[1] == '-') {
- if (!strcmp(argv[1], "-C")) {
- if (argc < 3)
- die(_("-C requires a <directory>"));
- if (chdir(argv[2]) < 0)
- die_errno(_("could not change to '%s'"),
- argv[2]);
- argc -= 2;
- argv += 2;
- } else if (!strcmp(argv[1], "-c")) {
- if (argc < 3)
- die(_("-c requires a <key>=<value> argument"));
- git_config_push_parameter(argv[2]);
- argc -= 2;
- argv += 2;
- } else
- break;
- }
-
- if (argc > 1) {
- argv++;
- argc--;
-
- for (i = 0; builtins[i].name; i++)
- if (!strcmp(builtins[i].name, argv[0]))
- return !!builtins[i].fn(argc, argv);
- }
-
- strbuf_addstr(&scalar_usage,
- N_("scalar [-C <directory>] [-c <key>=<value>] "
- "<command> [<options>]\n\nCommands:\n"));
- for (i = 0; builtins[i].name; i++)
- strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name);
-
- usage(scalar_usage.buf);
-}
diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt
deleted file mode 100644
index 1a12dc4..0000000
--- a/contrib/scalar/scalar.txt
+++ /dev/null
@@ -1,166 +0,0 @@
-scalar(1)
-=========
-
-NAME
-----
-scalar - A tool for managing large Git repositories
-
-SYNOPSIS
---------
-[verse]
-scalar clone [--single-branch] [--branch <main-branch>] [--full-clone] <url> [<enlistment>]
-scalar list
-scalar register [<enlistment>]
-scalar unregister [<enlistment>]
-scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]
-scalar reconfigure [ --all | <enlistment> ]
-scalar diagnose [<enlistment>]
-scalar delete <enlistment>
-
-DESCRIPTION
------------
-
-Scalar is a repository management tool that optimizes Git for use in large
-repositories. Scalar improves performance by configuring advanced Git settings,
-maintaining repositories in the background, and helping to reduce data sent
-across the network.
-
-An important Scalar concept is the enlistment: this is the top-level directory
-of the project. It usually contains the subdirectory `src/` which is a Git
-worktree. This encourages the separation between tracked files (inside `src/`)
-and untracked files, such as build artifacts (outside `src/`). When registering
-an existing Git worktree with Scalar whose name is not `src`, the enlistment
-will be identical to the worktree.
-
-The `scalar` command implements various subcommands, and different options
-depending on the subcommand. With the exception of `clone`, `list` and
-`reconfigure --all`, all subcommands expect to be run in an enlistment.
-
-The following options can be specified _before_ the subcommand:
-
--C <directory>::
- Before running the subcommand, change the working directory. This
- option imitates the same option of linkgit:git[1].
-
--c <key>=<value>::
- For the duration of running the specified subcommand, configure this
- setting. This option imitates the same option of linkgit:git[1].
-
-COMMANDS
---------
-
-Clone
-~~~~~
-
-clone [<options>] <url> [<enlistment>]::
- Clones the specified repository, similar to linkgit:git-clone[1]. By
- default, only commit and tree objects are cloned. Once finished, the
- worktree is located at `<enlistment>/src`.
-+
-The sparse-checkout feature is enabled (except when run with `--full-clone`)
-and the only files present are those in the top-level directory. Use
-`git sparse-checkout set` to expand the set of directories you want to see,
-or `git sparse-checkout disable` to expand to all files (see
-linkgit:git-sparse-checkout[1] for more details). You can explore the
-subdirectories outside your sparse-checkout by using `git ls-tree
-HEAD[:<directory>]`.
-
--b <name>::
---branch <name>::
- Instead of checking out the branch pointed to by the cloned
- repository's HEAD, check out the `<name>` branch instead.
-
---[no-]single-branch::
- Clone only the history leading to the tip of a single branch, either
- specified by the `--branch` option or the primary branch remote's
- `HEAD` points at.
-+
-Further fetches into the resulting repository will only update the
-remote-tracking branch for the branch this option was used for the initial
-cloning. If the HEAD at the remote did not point at any branch when
-`--single-branch` clone was made, no remote-tracking branch is created.
-
---[no-]full-clone::
- A sparse-checkout is initialized by default. This behavior can be
- turned off via `--full-clone`.
-
-List
-~~~~
-
-list::
- List enlistments that are currently registered by Scalar. This
- subcommand does not need to be run inside an enlistment.
-
-Register
-~~~~~~~~
-
-register [<enlistment>]::
- Adds the enlistment's repository to the list of registered repositories
- and starts background maintenance. If `<enlistment>` is not provided,
- then the enlistment associated with the current working directory is
- registered.
-+
-Note: when this subcommand is called in a worktree that is called `src/`, its
-parent directory is considered to be the Scalar enlistment. If the worktree is
-_not_ called `src/`, it itself will be considered to be the Scalar enlistment.
-
-Unregister
-~~~~~~~~~~
-
-unregister [<enlistment>]::
- Remove the specified repository from the list of repositories
- registered with Scalar and stop the scheduled background maintenance.
-
-Run
-~~~
-
-scalar run ( all | config | commit-graph | fetch | loose-objects | pack-files ) [<enlistment>]::
- Run the given maintenance task (or all tasks, if `all` was specified).
- Except for `all` and `config`, this subcommand simply hands off to
- linkgit:git-maintenance[1] (mapping `fetch` to `prefetch` and
- `pack-files` to `incremental-repack`).
-+
-These tasks are run automatically as part of the scheduled maintenance,
-as soon as the repository is registered with Scalar. It should therefore
-not be necessary to run this subcommand manually.
-+
-The `config` task is specific to Scalar and configures all those
-opinionated default settings that make Git work more efficiently with
-large repositories. As this task is run as part of `scalar clone`
-automatically, explicit invocations of this task are rarely needed.
-
-Reconfigure
-~~~~~~~~~~~
-
-After a Scalar upgrade, or when the configuration of a Scalar enlistment
-was somehow corrupted or changed by mistake, this subcommand allows to
-reconfigure the enlistment.
-
-With the `--all` option, all enlistments currently registered with Scalar
-will be reconfigured. Use this option after each Scalar upgrade.
-
-Diagnose
-~~~~~~~~
-
-diagnose [<enlistment>]::
- When reporting issues with Scalar, it is often helpful to provide the
- information gathered by this command, including logs and certain
- statistics describing the data shape of the current enlistment.
-+
-The output of this command is a `.zip` file that is written into
-a directory adjacent to the worktree in the `src` directory.
-
-Delete
-~~~~~~
-
-delete <enlistment>::
- This subcommand lets you delete an existing Scalar enlistment from your
- local file system, unregistering the repository.
-
-SEE ALSO
---------
-linkgit:git-clone[1], linkgit:git-maintenance[1].
-
-Scalar
----
-Associated with the linkgit:git[1] suite
diff --git a/contrib/scalar/t/Makefile b/contrib/scalar/t/Makefile
deleted file mode 100644
index 01e82e5..0000000
--- a/contrib/scalar/t/Makefile
+++ /dev/null
@@ -1,81 +0,0 @@
-# Import tree-wide shared Makefile behavior and libraries
-include ../../../shared.mak
-
-# Run scalar tests
-#
-# Copyright (c) 2005,2021 Junio C Hamano, Johannes Schindelin
-#
-
--include ../../../config.mak.autogen
--include ../../../config.mak
-
-SHELL_PATH ?= $(SHELL)
-PERL_PATH ?= /usr/bin/perl
-RM ?= rm -f
-PROVE ?= prove
-DEFAULT_TEST_TARGET ?= test
-TEST_LINT ?= test-lint
-
-ifdef TEST_OUTPUT_DIRECTORY
-TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results
-else
-TEST_RESULTS_DIRECTORY = ../../../t/test-results
-endif
-
-# Shell quote;
-SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
-PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
-TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY))
-
-T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
-
-all: $(DEFAULT_TEST_TARGET)
-
-test: $(TEST_LINT)
- $(MAKE) aggregate-results-and-cleanup
-
-prove: $(TEST_LINT)
- @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS)
- $(MAKE) clean-except-prove-cache
-
-$(T):
- @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
-
-clean-except-prove-cache:
- $(RM) -r 'trash directory'.* '$(TEST_RESULTS_DIRECTORY_SQ)'
- $(RM) -r valgrind/bin
-
-clean: clean-except-prove-cache
- $(RM) .prove
-
-test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax
-
-test-lint-duplicates:
- @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
- test -z "$$dups" || { \
- echo >&2 "duplicate test numbers:" $$dups; exit 1; }
-
-test-lint-executable:
- @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \
- test -z "$$bad" || { \
- echo >&2 "non-executable tests:" $$bad; exit 1; }
-
-test-lint-shell-syntax:
- @'$(PERL_PATH_SQ)' ../../../t/check-non-portable-shell.pl $(T)
-
-aggregate-results-and-cleanup: $(T)
- $(MAKE) aggregate-results
- $(MAKE) clean
-
-aggregate-results:
- for f in '$(TEST_RESULTS_DIRECTORY_SQ)'/t*-*.counts; do \
- echo "$$f"; \
- done | '$(SHELL_PATH_SQ)' ../../../t/aggregate-results.sh
-
-valgrind:
- $(MAKE) GIT_TEST_OPTS="$(GIT_TEST_OPTS) --valgrind"
-
-test-results:
- mkdir -p test-results
-
-.PHONY: $(T) aggregate-results clean valgrind
diff --git a/contrib/scalar/t/t9099-scalar.sh b/contrib/scalar/t/t9099-scalar.sh
deleted file mode 100755
index 10b1172..0000000
--- a/contrib/scalar/t/t9099-scalar.sh
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/sh
-
-test_description='test the `scalar` command'
-
-TEST_DIRECTORY=$PWD/../../../t
-export TEST_DIRECTORY
-
-# Make it work with --no-bin-wrappers
-PATH=$PWD/..:$PATH
-
-. ../../../t/test-lib.sh
-
-GIT_TEST_MAINT_SCHEDULER="crontab:test-tool crontab ../cron.txt,launchctl:true,schtasks:true"
-export GIT_TEST_MAINT_SCHEDULER
-
-test_expect_success 'scalar shows a usage' '
- test_expect_code 129 scalar -h
-'
-
-test_expect_success 'scalar unregister' '
- git init vanish/src &&
- scalar register vanish/src &&
- git config --get --global --fixed-value \
- maintenance.repo "$(pwd)/vanish/src" &&
- scalar list >scalar.repos &&
- grep -F "$(pwd)/vanish/src" scalar.repos &&
- rm -rf vanish/src/.git &&
- scalar unregister vanish &&
- test_must_fail git config --get --global --fixed-value \
- maintenance.repo "$(pwd)/vanish/src" &&
- scalar list >scalar.repos &&
- ! grep -F "$(pwd)/vanish/src" scalar.repos
-'
-
-test_expect_success 'set up repository to clone' '
- test_commit first &&
- test_commit second &&
- test_commit third &&
- git switch -c parallel first &&
- mkdir -p 1/2 &&
- test_commit 1/2/3 &&
- git config uploadPack.allowFilter true &&
- git config uploadPack.allowAnySHA1InWant true
-'
-
-test_expect_success 'scalar clone' '
- second=$(git rev-parse --verify second:second.t) &&
- scalar clone "file://$(pwd)" cloned --single-branch &&
- (
- cd cloned/src &&
-
- git config --get --global --fixed-value maintenance.repo \
- "$(pwd)" &&
-
- git for-each-ref --format="%(refname)" refs/remotes/origin/ >actual &&
- echo "refs/remotes/origin/parallel" >expect &&
- test_cmp expect actual &&
-
- test_path_is_missing 1/2 &&
- test_must_fail git rev-list --missing=print $second &&
- git rev-list $second &&
- git cat-file blob $second >actual &&
- echo "second" >expect &&
- test_cmp expect actual
- )
-'
-
-test_expect_success 'scalar reconfigure' '
- git init one/src &&
- scalar register one &&
- git -C one/src config core.preloadIndex false &&
- scalar reconfigure one &&
- test true = "$(git -C one/src config core.preloadIndex)" &&
- git -C one/src config core.preloadIndex false &&
- scalar reconfigure -a &&
- test true = "$(git -C one/src config core.preloadIndex)"
-'
-
-test_expect_success 'scalar delete without enlistment shows a usage' '
- test_expect_code 129 scalar delete
-'
-
-test_expect_success 'scalar delete with enlistment' '
- scalar delete cloned &&
- test_path_is_missing cloned
-'
-
-test_expect_success 'scalar supports -c/-C' '
- test_when_finished "scalar delete sub" &&
- git init sub &&
- scalar -C sub -c status.aheadBehind=bogus register &&
- test -z "$(git -C sub config --local status.aheadBehind)" &&
- test true = "$(git -C sub config core.preloadIndex)"
-'
-
-test_expect_success '`scalar [...] <dir>` errors out when dir is missing' '
- ! scalar run config cloned 2>err &&
- grep "cloned. does not exist" err
-'
-
-SQ="'"
-test_expect_success UNZIP 'scalar diagnose' '
- scalar clone "file://$(pwd)" cloned --single-branch &&
- git repack &&
- echo "$(pwd)/.git/objects/" >>cloned/src/.git/objects/info/alternates &&
- test_commit -C cloned/src loose &&
- scalar diagnose cloned >out 2>err &&
- grep "Available space" out &&
- sed -n "s/.*$SQ\\(.*\\.zip\\)$SQ.*/\\1/p" <err >zip_path &&
- zip_path=$(cat zip_path) &&
- test -n "$zip_path" &&
- unzip -v "$zip_path" &&
- folder=${zip_path%.zip} &&
- test_path_is_missing "$folder" &&
- unzip -p "$zip_path" diagnostics.log >out &&
- test_file_not_empty out &&
- unzip -p "$zip_path" packs-local.txt >out &&
- grep "$(pwd)/.git/objects" out &&
- unzip -p "$zip_path" objects-local.txt >out &&
- grep "^Total: [1-9]" out
-'
-
-test_done
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 7562a39..10c9c87 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -98,10 +98,18 @@ progress () {
assert () {
if ! "$@"
then
- die "assertion failed: $*"
+ die "fatal: assertion failed: $*"
fi
}
+# Usage: die_incompatible_opt OPTION COMMAND
+die_incompatible_opt () {
+ assert test "$#" = 2
+ opt="$1"
+ arg_command="$2"
+ die "fatal: the '$opt' flag does not make sense with 'git subtree $arg_command'."
+}
+
main () {
if test $# -eq 0
then
@@ -147,7 +155,7 @@ main () {
allow_addmerge=$arg_split_rejoin
;;
*)
- die "Unknown command '$arg_command'"
+ die "fatal: unknown command '$arg_command'"
;;
esac
# Reset the arguments array for "real" flag parsing.
@@ -176,16 +184,16 @@ main () {
arg_debug=1
;;
--annotate)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
arg_split_annotate="$1"
shift
;;
--no-annotate)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
arg_split_annotate=
;;
-b)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
arg_split_branch="$1"
shift
;;
@@ -194,7 +202,7 @@ main () {
shift
;;
-m)
- test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
arg_addmerge_message="$1"
shift
;;
@@ -202,41 +210,41 @@ main () {
arg_prefix=
;;
--onto)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
arg_split_onto="$1"
shift
;;
--no-onto)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
arg_split_onto=
;;
--rejoin)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
;;
--no-rejoin)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
;;
--ignore-joins)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
arg_split_ignore_joins=1
;;
--no-ignore-joins)
- test -n "$allow_split" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_split" || die_incompatible_opt "$opt" "$arg_command"
arg_split_ignore_joins=
;;
--squash)
- test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
arg_addmerge_squash=1
;;
--no-squash)
- test -n "$allow_addmerge" || die "The '$opt' flag does not make sense with 'git subtree $arg_command'."
+ test -n "$allow_addmerge" || die_incompatible_opt "$opt" "$arg_command"
arg_addmerge_squash=
;;
--)
break
;;
*)
- die "Unexpected option: $opt"
+ die "fatal: unexpected option: $opt"
;;
esac
done
@@ -244,17 +252,17 @@ main () {
if test -z "$arg_prefix"
then
- die "You must provide the --prefix option."
+ die "fatal: you must provide the --prefix option."
fi
case "$arg_command" in
add)
test -e "$arg_prefix" &&
- die "prefix '$arg_prefix' already exists."
+ die "fatal: prefix '$arg_prefix' already exists."
;;
*)
test -e "$arg_prefix" ||
- die "'$arg_prefix' does not exist; use 'git subtree add'"
+ die "fatal: '$arg_prefix' does not exist; use 'git subtree add'"
;;
esac
@@ -274,11 +282,11 @@ 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
}
@@ -334,7 +342,7 @@ cache_set () {
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"
}
@@ -363,13 +371,47 @@ try_remove_previous () {
fi
}
-# Usage: find_latest_squash DIR
+# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY]
+process_subtree_split_trailer () {
+ assert test $# = 2 -o $# = 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 () {
- assert test $# = 1
- debug "Looking for latest squash ($dir)..."
+ assert test $# = 1 -o $# = 2
+ dir="$1"
+ repository=""
+ if test "$#" = 2
+ then
+ repository="$2"
+ fi
+ debug "Looking for latest squash (dir=$dir, repository=$repository)..."
local indent=$(($indent + 1))
- dir="$1"
sq=
main=
sub=
@@ -387,8 +429,7 @@ find_latest_squash () {
main="$b"
;;
git-subtree-split:)
- sub="$(git rev-parse "$b^{commit}")" ||
- die "could not rev-parse split hash $b from commit $sq"
+ process_subtree_split_trailer "$b" "$sq" "$repository"
;;
END)
if test -n "$sub"
@@ -412,14 +453,19 @@ find_latest_squash () {
done || exit $?
}
-# Usage: find_existing_splits DIR REV
+# Usage: find_existing_splits DIR REV [REPOSITORY]
find_existing_splits () {
- assert test $# = 2
+ assert test $# = 2 -o $# = 3
debug "Looking for prior splits..."
local indent=$(($indent + 1))
dir="$1"
rev="$2"
+ repository=""
+ if test "$#" = 3
+ then
+ repository="$3"
+ fi
main=
sub=
local grep_format="^git-subtree-dir: $dir/*\$"
@@ -439,8 +485,7 @@ find_existing_splits () {
main="$b"
;;
git-subtree-split:)
- sub="$(git rev-parse "$b^{commit}")" ||
- die "could not rev-parse split hash $b from commit $sq"
+ process_subtree_split_trailer "$b" "$sq" "$repository"
;;
END)
debug "Main is: '$main'"
@@ -490,7 +535,7 @@ copy_commit () {
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
@@ -718,11 +763,11 @@ 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
}
@@ -730,7 +775,7 @@ ensure_clean () {
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: process_split_commit REV PARENTS
@@ -796,7 +841,7 @@ cmd_add () {
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 "$@"
@@ -811,7 +856,7 @@ cmd_add () {
cmd_add_repository "$@"
else
- say >&2 "error: parameters were '$*'"
+ say >&2 "fatal: parameters were '$*'"
die "Provide either a commit or a repository and commit."
fi
}
@@ -843,7 +888,7 @@ cmd_add_commit () {
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"
@@ -866,17 +911,22 @@ cmd_add_commit () {
say >&2 "Added dir '$dir'"
}
-# Usage: cmd_split [REV]
+# Usage: cmd_split [REV] [REPOSITORY]
cmd_split () {
if test $# -eq 0
then
rev=$(git rev-parse HEAD)
- elif test $# -eq 1
+ elif test $# -eq 1 -o $# -eq 2
then
rev=$(git rev-parse -q --verify "$1^{commit}") ||
- die "'$1' does not refer to a commit"
+ die "fatal: '$1' does not refer to a commit"
else
- die "You must provide exactly one revision. Got: '$*'"
+ 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"
@@ -900,7 +950,7 @@ cmd_split () {
done || exit $?
fi
- unrevs="$(find_existing_splits "$dir" "$rev")" || exit $?
+ 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.
@@ -919,7 +969,7 @@ cmd_split () {
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 "$arg_split_rejoin"
@@ -940,7 +990,7 @@ cmd_split () {
then
if ! git merge-base --is-ancestor "$arg_split_branch" "$latest_new"
then
- die "Branch '$arg_split_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
@@ -954,20 +1004,25 @@ cmd_split () {
exit 0
}
-# Usage: cmd_merge REV
+# Usage: cmd_merge REV [REPOSITORY]
cmd_merge () {
- test $# -eq 1 ||
- die "You must provide exactly one revision. Got: '$*'"
+ test $# -eq 1 -o $# -eq 2 ||
+ die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
rev=$(git rev-parse -q --verify "$1^{commit}") ||
- die "'$1' does not refer to a commit"
+ die "fatal: '$1' does not refer to a commit"
+ repository=""
+ if test "$#" = 2
+ then
+ repository="$2"
+ fi
ensure_clean
if test -n "$arg_addmerge_squash"
then
- first_split="$(find_latest_squash "$dir")" || exit $?
+ 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
@@ -995,19 +1050,21 @@ cmd_merge () {
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 $?
- cmd_merge FETCH_HEAD
+ 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> <refspec>"
+ die "fatal: you must provide <repository> <refspec>"
fi
if test -e "$dir"
then
@@ -1022,13 +1079,13 @@ cmd_push () {
fi
ensure_valid_ref_format "$remoteref"
localrev_presplit=$(git rev-parse -q --verify "$localrevname_presplit^{commit}") ||
- die "'$localrevname_presplit' does not refer to a commit"
+ die "fatal: '$localrevname_presplit' does not refer to a commit"
echo "git push using: " "$repository" "$refspec"
- localrev=$(cmd_split "$localrev_presplit") || die
+ 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
}
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 9cddfa2..004abf4 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -11,7 +11,7 @@ SYNOPSIS
[verse]
'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>
+'git subtree' [<options>] -P <prefix> merge <local-commit> [<repository>]
'git subtree' [<options>] -P <prefix> split [<local-commit>]
[verse]
@@ -76,7 +76,7 @@ add <repository> <remote-ref>::
only a single commit from the subproject, rather than its
entire history.
-merge <local-commit>::
+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
@@ -88,8 +88,13 @@ 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.
++
+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>]::
+split [<local-commit>] [<repository>]::
Extract a new, synthetic project history from the
history of the <prefix> subtree of <local-commit>, or of
HEAD if no <local-commit> is given. The new history
@@ -109,6 +114,11 @@ 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.
++
+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
diff --git a/contrib/subtree/t/Makefile b/contrib/subtree/t/Makefile
index 276898e..4655e09 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
diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 1c1f76f..341c169 100755
--- a/contrib/subtree/t/t7900-subtree.sh
+++ b/contrib/subtree/t/t7900-subtree.sh
@@ -43,6 +43,30 @@ last_commit_subject () {
git log --pretty=format:%s -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=$(cat msg | sed -e "s/$commit/$tag/" | 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 &&
@@ -264,6 +288,13 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende
)
'
+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'
#
@@ -277,7 +308,7 @@ test_expect_success 'split requires option --prefix' '
cd "$test_count" &&
git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD &&
- echo "You must provide the --prefix option." >expected &&
+ 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" &&
@@ -296,7 +327,7 @@ test_expect_success 'split requires path given by option --prefix must exist' '
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 &&
+ 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" &&
@@ -551,6 +582,12 @@ test_expect_success 'split "sub dir"/ with --branch for an incompatible branch'
)
'
+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'
#
@@ -570,7 +607,7 @@ test_expect_success 'pull requires option --prefix' '
cd "$test_count" &&
test_must_fail git subtree pull ./"sub proj" HEAD >out 2>err &&
- echo "You must provide the --prefix option." >expected &&
+ echo "fatal: you must provide the --prefix option." >expected &&
test_must_be_empty out &&
test_cmp expected err
)
@@ -584,7 +621,7 @@ test_expect_success 'pull requires path given by option --prefix must exist' '
(
test_must_fail git subtree pull --prefix="sub dir" ./"sub proj" HEAD >out 2>err &&
- echo "'\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
+ echo "fatal: '\''sub dir'\'' does not exist; use '\''git subtree add'\''" >expected &&
test_must_be_empty out &&
test_cmp expected err
)
@@ -630,6 +667,11 @@ test_expect_success 'pull rejects flags for split' '
)
'
+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'
#
@@ -643,7 +685,7 @@ test_expect_success 'push requires option --prefix' '
cd "$test_count" &&
git fetch ./"sub proj" HEAD &&
git subtree add --prefix="sub dir" FETCH_HEAD &&
- echo "You must provide the --prefix option." >expected &&
+ 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" &&
@@ -662,7 +704,7 @@ test_expect_success 'push requires path given by option --prefix must exist' '
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 &&
+ 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" &&
@@ -953,6 +995,12 @@ test_expect_success 'push "sub dir"/ with a local rev' '
)
'
+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
#