* [PATCH 1/4] mergetool: add copyright
@ 2016-10-06 23:47 David Aguilar
2016-10-06 23:47 ` [PATCH 2/4] mergetool: move main program flow into a main() function David Aguilar
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: David Aguilar @ 2016-10-06 23:47 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano, Johannes Sixt, Luis Gutierrez
Signed-off-by: David Aguilar <davvid@gmail.com>
---
git-mergetool.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/git-mergetool.sh b/git-mergetool.sh
index bf86270..300ce7f 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -3,6 +3,7 @@
# This program resolves merge conflicts in git
#
# Copyright (c) 2006 Theodore Y. Ts'o
+# Copyright (c) 2009-2016 David Aguilar
#
# This file is licensed under the GPL v2, or a later version
# at the discretion of Junio C Hamano.
--
2.10.1.355.g33afd83.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] mergetool: move main program flow into a main() function
2016-10-06 23:47 [PATCH 1/4] mergetool: add copyright David Aguilar
@ 2016-10-06 23:47 ` David Aguilar
2016-10-07 5:51 ` Johannes Sixt
2016-10-06 23:47 ` [PATCH 3/4] mergetool: honor diff.orderFile David Aguilar
2016-10-06 23:47 ` [PATCH 4/4] mergetool: honor -O<order-file> David Aguilar
2 siblings, 1 reply; 7+ messages in thread
From: David Aguilar @ 2016-10-06 23:47 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano, Johannes Sixt, Luis Gutierrez
Signed-off-by: David Aguilar <davvid@gmail.com>
---
git-mergetool.sh | 180 ++++++++++++++++++++++++++++---------------------------
1 file changed, 93 insertions(+), 87 deletions(-)
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 300ce7f..b2cd0a4 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -366,51 +366,6 @@ merge_file () {
return 0
}
-prompt=$(git config --bool mergetool.prompt)
-guessed_merge_tool=false
-
-while test $# != 0
-do
- case "$1" in
- --tool-help=*)
- TOOL_MODE=${1#--tool-help=}
- show_tool_help
- ;;
- --tool-help)
- show_tool_help
- ;;
- -t|--tool*)
- case "$#,$1" in
- *,*=*)
- merge_tool=$(expr "z$1" : 'z-[^=]*=\(.*\)')
- ;;
- 1,*)
- usage ;;
- *)
- merge_tool="$2"
- shift ;;
- esac
- ;;
- -y|--no-prompt)
- prompt=false
- ;;
- --prompt)
- prompt=true
- ;;
- --)
- shift
- break
- ;;
- -*)
- usage
- ;;
- *)
- break
- ;;
- esac
- shift
-done
-
prompt_after_failed_merge () {
while true
do
@@ -427,57 +382,108 @@ prompt_after_failed_merge () {
done
}
-git_dir_init
-require_work_tree
+main () {
+ prompt=$(git config --bool mergetool.prompt)
+ guessed_merge_tool=false
+
+ while test $# != 0
+ do
+ case "$1" in
+ --tool-help=*)
+ TOOL_MODE=${1#--tool-help=}
+ show_tool_help
+ ;;
+ --tool-help)
+ show_tool_help
+ ;;
+ -t|--tool*)
+ case "$#,$1" in
+ *,*=*)
+ merge_tool=$(expr "z$1" : 'z-[^=]*=\(.*\)')
+ ;;
+ 1,*)
+ usage ;;
+ *)
+ merge_tool="$2"
+ shift ;;
+ esac
+ ;;
+ -y|--no-prompt)
+ prompt=false
+ ;;
+ --prompt)
+ prompt=true
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+ done
+
+ git_dir_init
+ require_work_tree
-if test -z "$merge_tool"
-then
- # Check if a merge tool has been configured
- merge_tool=$(get_configured_merge_tool)
- # Try to guess an appropriate merge tool if no tool has been set.
if test -z "$merge_tool"
then
- merge_tool=$(guess_merge_tool) || exit
- guessed_merge_tool=true
+ # Check if a merge tool has been configured
+ merge_tool=$(get_configured_merge_tool)
+ # Try to guess an appropriate merge tool if no tool has been set.
+ if test -z "$merge_tool"
+ then
+ merge_tool=$(guess_merge_tool) || exit
+ guessed_merge_tool=true
+ fi
fi
-fi
-merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
-merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
-
-files=
+ merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
+ merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
-if test $# -eq 0
-then
- cd_to_toplevel
+ files=
- if test -e "$GIT_DIR/MERGE_RR"
+ if test $# -eq 0
then
- files=$(git rerere remaining)
+ cd_to_toplevel
+
+ if test -e "$GIT_DIR/MERGE_RR"
+ then
+ files=$(git rerere remaining)
+ else
+ files=$(git ls-files -u |
+ sed -e 's/^[^ ]* //' | sort -u)
+ fi
else
- files=$(git ls-files -u | sed -e 's/^[^ ]* //' | sort -u)
+ files=$(git ls-files -u -- "$@" |
+ sed -e 's/^[^ ]* //' | sort -u)
fi
-else
- files=$(git ls-files -u -- "$@" | sed -e 's/^[^ ]* //' | sort -u)
-fi
-
-if test -z "$files"
-then
- echo "No files need merging"
- exit 0
-fi
-
-printf "Merging:\n"
-printf "%s\n" "$files"
-
-rc=0
-for i in $files
-do
- printf "\n"
- if ! merge_file "$i"
+
+ if test -z "$files"
then
- rc=1
- prompt_after_failed_merge || exit 1
+ echo "No files need merging"
+ exit 0
fi
-done
-exit $rc
+ printf "Merging:\n"
+ printf "%s\n" "$files"
+
+ rc=0
+ for i in $files
+ do
+ printf "\n"
+ if ! merge_file "$i"
+ then
+ rc=1
+ prompt_after_failed_merge || exit 1
+ fi
+ done
+
+ exit $rc
+}
+
+main "$@"
--
2.10.1.355.g33afd83.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] mergetool: honor diff.orderFile
2016-10-06 23:47 [PATCH 1/4] mergetool: add copyright David Aguilar
2016-10-06 23:47 ` [PATCH 2/4] mergetool: move main program flow into a main() function David Aguilar
@ 2016-10-06 23:47 ` David Aguilar
2016-10-07 17:08 ` Johannes Sixt
2016-10-06 23:47 ` [PATCH 4/4] mergetool: honor -O<order-file> David Aguilar
2 siblings, 1 reply; 7+ messages in thread
From: David Aguilar @ 2016-10-06 23:47 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano, Johannes Sixt, Luis Gutierrez
Teach mergetool to get the list of files to edit via `diff` so that we
gain support for diff.orderFile.
Suggested-by: Luis Gutierrez <luisgutz@gmail.com>
Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Documentation/git-mergetool.txt | 5 +++++
git-mergetool.sh | 30 +++++++++++++++---------------
t/t7610-mergetool.sh | 33 +++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 15 deletions(-)
diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
index e846c2e..c4c1a9b 100644
--- a/Documentation/git-mergetool.txt
+++ b/Documentation/git-mergetool.txt
@@ -79,6 +79,11 @@ success of the resolution after the custom tool has exited.
Prompt before each invocation of the merge resolution program
to give the user a chance to skip the path.
+DIFF ORDER FILES
+----------------
+`git mergetool` honors the `diff.orderFile` configuration variable
+used by `git diff`. See linkgit:git-config[1] for more details.
+
TEMPORARY FILES
---------------
`git mergetool` creates `*.orig` backup files while resolving merges.
diff --git a/git-mergetool.sh b/git-mergetool.sh
index b2cd0a4..65696d8 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -382,6 +382,11 @@ prompt_after_failed_merge () {
done
}
+print_noop_and_exit () {
+ echo "No files need merging"
+ exit 0
+}
+
main () {
prompt=$(git config --bool mergetool.prompt)
guessed_merge_tool=false
@@ -445,28 +450,23 @@ main () {
merge_keep_backup="$(git config --bool mergetool.keepBackup || echo true)"
merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)"
- files=
-
- if test $# -eq 0
+ if test $# -eq 0 && test -e "$GIT_DIR/MERGE_RR"
then
- cd_to_toplevel
-
- if test -e "$GIT_DIR/MERGE_RR"
+ set -- $(git rerere remaining)
+ if test $# -eq 0
then
- files=$(git rerere remaining)
- else
- files=$(git ls-files -u |
- sed -e 's/^[^ ]* //' | sort -u)
+ print_noop_and_exit
fi
- else
- files=$(git ls-files -u -- "$@" |
- sed -e 's/^[^ ]* //' | sort -u)
fi
+ files=$(git -c core.quotePath=false \
+ diff --name-only --diff-filter=U -- "$@")
+
+ cd_to_toplevel
+
if test -z "$files"
then
- echo "No files need merging"
- exit 0
+ print_noop_and_exit
fi
printf "Merging:\n"
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 7217f39..fb2aeef 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -606,4 +606,37 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
git reset --hard master >/dev/null 2>&1
'
+test_expect_success 'diff.orderFile configuration is honored' '
+ test_config diff.orderFile order-file &&
+ test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
+ test_config mergetool.myecho.trustExitCode true &&
+ echo b >order-file &&
+ echo a >>order-file &&
+ git checkout -b order-file-start master &&
+ echo start >a &&
+ echo start >b &&
+ git add a b &&
+ git commit -m start &&
+ git checkout -b order-file-side1 order-file-start &&
+ echo side1 >a &&
+ echo side1 >b &&
+ git add a b &&
+ git commit -m side1 &&
+ git checkout -b order-file-side2 order-file-start &&
+ echo side2 >a &&
+ echo side2 >b &&
+ git add a b &&
+ git commit -m side2 &&
+ test_must_fail git merge order-file-side1 &&
+ cat >expect <<-\EOF &&
+ Merging:
+ b
+ a
+ EOF
+ git mergetool --no-prompt --tool myecho | grep -A 2 Merging: >actual &&
+ test_cmp expect actual &&
+ git reset --hard >/dev/null
+'
+'
+
test_done
--
2.10.1.355.g33afd83.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] mergetool: honor -O<order-file>
2016-10-06 23:47 [PATCH 1/4] mergetool: add copyright David Aguilar
2016-10-06 23:47 ` [PATCH 2/4] mergetool: move main program flow into a main() function David Aguilar
2016-10-06 23:47 ` [PATCH 3/4] mergetool: honor diff.orderFile David Aguilar
@ 2016-10-06 23:47 ` David Aguilar
2016-10-07 17:16 ` Johannes Sixt
2 siblings, 1 reply; 7+ messages in thread
From: David Aguilar @ 2016-10-06 23:47 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano, Johannes Sixt, Luis Gutierrez
Teach mergetool to pass "-O<order-file>" down to `git diff` when
specified on the command-line.
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Documentation/git-mergetool.txt | 10 ++++++----
git-mergetool.sh | 14 ++++++++++++--
t/t7610-mergetool.sh | 27 +++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
index c4c1a9b..3622d66 100644
--- a/Documentation/git-mergetool.txt
+++ b/Documentation/git-mergetool.txt
@@ -79,10 +79,12 @@ success of the resolution after the custom tool has exited.
Prompt before each invocation of the merge resolution program
to give the user a chance to skip the path.
-DIFF ORDER FILES
-----------------
-`git mergetool` honors the `diff.orderFile` configuration variable
-used by `git diff`. See linkgit:git-config[1] for more details.
+-O<orderfile>::
+ Process files in the order specified in the
+ <orderfile>, which has one shell glob pattern per line.
+ This overrides the `diff.orderFile` configuration variable
+ (see linkgit:git-config[1]). To cancel `diff.orderFile`,
+ use `-O/dev/null`.
TEMPORARY FILES
---------------
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 65696d8..9dca58b 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -9,7 +9,7 @@
# at the discretion of Junio C Hamano.
#
-USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
+USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-O<order-file>] [file to merge] ...'
SUBDIRECTORY_OK=Yes
NONGIT_OK=Yes
OPTIONS_SPEC=
@@ -390,6 +390,7 @@ print_noop_and_exit () {
main () {
prompt=$(git config --bool mergetool.prompt)
guessed_merge_tool=false
+ order_file=
while test $# != 0
do
@@ -419,6 +420,9 @@ main () {
--prompt)
prompt=true
;;
+ -O*)
+ order_file="$1"
+ ;;
--)
shift
break
@@ -459,8 +463,14 @@ main () {
fi
fi
+ if test -n "$order_file"
+ then
+ set -- "$order_file" -- "$@"
+ else
+ set -- -- "$@"
+ fi
files=$(git -c core.quotePath=false \
- diff --name-only --diff-filter=U -- "$@")
+ diff --name-only --diff-filter=U "$@")
cd_to_toplevel
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index fb2aeef..0f9869a 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -637,6 +637,33 @@ test_expect_success 'diff.orderFile configuration is honored' '
test_cmp expect actual &&
git reset --hard >/dev/null
'
+
+test_expect_success 'mergetool -Oorder-file is honored' '
+ test_config diff.orderFile order-file &&
+ test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
+ test_config mergetool.myecho.trustExitCode true &&
+ test_must_fail git merge order-file-side1 &&
+ cat >expect <<-\EOF &&
+ Merging:
+ a
+ b
+ EOF
+ git mergetool -O/dev/null --no-prompt --tool myecho |
+ grep -A 2 Merging: >actual &&
+ test_cmp expect actual &&
+ git reset --hard >/dev/null 2>&1 &&
+
+ git config --unset diff.orderFile &&
+ test_must_fail git merge order-file-side1 &&
+ cat >expect <<-\EOF &&
+ Merging:
+ b
+ a
+ EOF
+ git mergetool -Oorder-file --no-prompt --tool myecho |
+ grep -A 2 Merging: >actual &&
+ test_cmp expect actual &&
+ git reset --hard >/dev/null 2>&1
'
test_done
--
2.10.1.355.g33afd83.dirty
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 2/4] mergetool: move main program flow into a main() function
2016-10-06 23:47 ` [PATCH 2/4] mergetool: move main program flow into a main() function David Aguilar
@ 2016-10-07 5:51 ` Johannes Sixt
0 siblings, 0 replies; 7+ messages in thread
From: Johannes Sixt @ 2016-10-07 5:51 UTC (permalink / raw)
To: David Aguilar; +Cc: Git Mailing List, Junio C Hamano, Luis Gutierrez
Am 07.10.2016 um 01:47 schrieb David Aguilar:
> Signed-off-by: David Aguilar <davvid@gmail.com>
> ---
An answer to "why?" is missing here. I guess it is just so that
everything happens in functions, and that there is only the invocation
of main at the top-level of the script. I am unsure whether this is
sufficient justification; you are adding a level of indentation after all.
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/4] mergetool: honor diff.orderFile
2016-10-06 23:47 ` [PATCH 3/4] mergetool: honor diff.orderFile David Aguilar
@ 2016-10-07 17:08 ` Johannes Sixt
0 siblings, 0 replies; 7+ messages in thread
From: Johannes Sixt @ 2016-10-07 17:08 UTC (permalink / raw)
To: David Aguilar; +Cc: Git Mailing List, Junio C Hamano, Luis Gutierrez
Am 07.10.2016 um 01:47 schrieb David Aguilar:
> @@ -606,4 +606,37 @@ test_expect_success MKTEMP 'temporary filenames are used with mergetool.writeToT
> git reset --hard master >/dev/null 2>&1
> '
>
> +test_expect_success 'diff.orderFile configuration is honored' '
> + test_config diff.orderFile order-file &&
> + test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
> + test_config mergetool.myecho.trustExitCode true &&
> + echo b >order-file &&
> + echo a >>order-file &&
> + git checkout -b order-file-start master &&
> + echo start >a &&
> + echo start >b &&
> + git add a b &&
> + git commit -m start &&
> + git checkout -b order-file-side1 order-file-start &&
> + echo side1 >a &&
> + echo side1 >b &&
> + git add a b &&
> + git commit -m side1 &&
> + git checkout -b order-file-side2 order-file-start &&
> + echo side2 >a &&
> + echo side2 >b &&
> + git add a b &&
> + git commit -m side2 &&
> + test_must_fail git merge order-file-side1 &&
> + cat >expect <<-\EOF &&
> + Merging:
> + b
> + a
> + EOF
> + git mergetool --no-prompt --tool myecho | grep -A 2 Merging: >actual &&
Is grep -A universally available?
> + test_cmp expect actual &&
> + git reset --hard >/dev/null
> +'
> +'
Two single-quotes?
> +
> test_done
>
Otherwise the patch looks good.
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/4] mergetool: honor -O<order-file>
2016-10-06 23:47 ` [PATCH 4/4] mergetool: honor -O<order-file> David Aguilar
@ 2016-10-07 17:16 ` Johannes Sixt
0 siblings, 0 replies; 7+ messages in thread
From: Johannes Sixt @ 2016-10-07 17:16 UTC (permalink / raw)
To: David Aguilar; +Cc: Git Mailing List, Junio C Hamano, Luis Gutierrez
Am 07.10.2016 um 01:47 schrieb David Aguilar:
> diff --git a/git-mergetool.sh b/git-mergetool.sh
> index 65696d8..9dca58b 100755
> --- a/git-mergetool.sh
> +++ b/git-mergetool.sh
> @@ -9,7 +9,7 @@
> # at the discretion of Junio C Hamano.
> #
>
> -USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
> +USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-O<order-file>] [file to merge] ...'
> SUBDIRECTORY_OK=Yes
> NONGIT_OK=Yes
> OPTIONS_SPEC=
> @@ -390,6 +390,7 @@ print_noop_and_exit () {
> main () {
> prompt=$(git config --bool mergetool.prompt)
> guessed_merge_tool=false
> + order_file=
>
> while test $# != 0
> do
> @@ -419,6 +420,9 @@ main () {
> --prompt)
> prompt=true
> ;;
> + -O*)
> + order_file="$1"
> + ;;
> --)
> shift
> break
> @@ -459,8 +463,14 @@ main () {
> fi
> fi
>
> + if test -n "$order_file"
> + then
> + set -- "$order_file" -- "$@"
> + else
> + set -- -- "$@"
> + fi
> files=$(git -c core.quotePath=false \
> - diff --name-only --diff-filter=U -- "$@")
> + diff --name-only --diff-filter=U "$@")
You can write this as
files=$(git -c core.quotePath=false \
diff --name-only --diff-filter=U \
${order_file:+"$order_file"} -- "$@")
without the case distinction earlier. This construct is usually used to
attach the option (-O) in front of the argument, but it is already
included in the value; so, we use the construct only to avoid an empty
argument when the option is unset and to get a quoted string when it is set.
>
> cd_to_toplevel
>
> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
> index fb2aeef..0f9869a 100755
> --- a/t/t7610-mergetool.sh
> +++ b/t/t7610-mergetool.sh
> @@ -637,6 +637,33 @@ test_expect_success 'diff.orderFile configuration is honored' '
> test_cmp expect actual &&
> git reset --hard >/dev/null
> '
> +
> +test_expect_success 'mergetool -Oorder-file is honored' '
> + test_config diff.orderFile order-file &&
> + test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
> + test_config mergetool.myecho.trustExitCode true &&
> + test_must_fail git merge order-file-side1 &&
> + cat >expect <<-\EOF &&
> + Merging:
> + a
> + b
> + EOF
> + git mergetool -O/dev/null --no-prompt --tool myecho |
> + grep -A 2 Merging: >actual &&
> + test_cmp expect actual &&
> + git reset --hard >/dev/null 2>&1 &&
> +
> + git config --unset diff.orderFile &&
> + test_must_fail git merge order-file-side1 &&
> + cat >expect <<-\EOF &&
> + Merging:
> + b
> + a
> + EOF
> + git mergetool -Oorder-file --no-prompt --tool myecho |
> + grep -A 2 Merging: >actual &&
grep -A again. Furthermore, you call git mergetool in the upstream of a
pipe. This will ignore the exit status.
> + test_cmp expect actual &&
> + git reset --hard >/dev/null 2>&1
> '
Ah, the earlier lone quote should have been added in this patch.
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-07 17:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-06 23:47 [PATCH 1/4] mergetool: add copyright David Aguilar
2016-10-06 23:47 ` [PATCH 2/4] mergetool: move main program flow into a main() function David Aguilar
2016-10-07 5:51 ` Johannes Sixt
2016-10-06 23:47 ` [PATCH 3/4] mergetool: honor diff.orderFile David Aguilar
2016-10-07 17:08 ` Johannes Sixt
2016-10-06 23:47 ` [PATCH 4/4] mergetool: honor -O<order-file> David Aguilar
2016-10-07 17:16 ` Johannes Sixt
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).