[PATCHv7 3/3] git rebase -i: add static check for commands and SHA-1

2015-06-29 Thread Galan Rémi
Check before the start of the rebasing if the commands exists, and for
the commands expecting a SHA-1, check if the SHA-1 is present and
corresponds to a commit. In case of error, print the error, stop git
rebase and prompt the user to fix with 'git rebase --edit-todo' or to
abort.

This allows to avoid doing half of a rebase before finding an error
and giving back what's left of the todo list to the user and prompt
him to fix when it might be too late for him to do so (he might have
to abort and restart the rebase).

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 git-rebase--interactive.sh| 75 +++
 t/lib-rebase.sh   |  5 +++
 t/t3404-rebase-interactive.sh | 39 ++
 3 files changed, 119 insertions(+)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 66daacf..ec4a068 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -834,6 +834,73 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Check if the SHA-1 passed as an argument is a
+# correct one, if not then print $2 in $todo.badsha
+# $1: the SHA-1 to test
+# $2: the line to display if incorrect SHA-1
+check_commit_sha () {
+   badsha=0
+   if test -z $1
+   then
+   badsha=1
+   else
+   sha1_verif=$(git rev-parse --verify --quiet $1^{commit})
+   if test -z $sha1_verif
+   then
+   badsha=1
+   fi
+   fi
+
+   if test $badsha -ne 0
+   then
+   warn Warning: the SHA-1 is missing or isn't \
+   a commit in the following line:
+   warn  - $2
+   warn
+   fi
+
+   return $badsha
+}
+
+# prints the bad commits and bad commands
+# from the todolist in stdin
+check_bad_cmd_and_sha () {
+   retval=0
+   git stripspace --strip-comments |
+   (
+   while read -r line
+   do
+   IFS=' '
+   set x $line
+   shift
+   command=$1
+   sha1=$2
+
+   case $command in
+   ''|noop|x|exec)
+   # Doesn't expect a SHA-1
+   ;;
+   pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
+   check_commit_sha $sha1 $line
+   if test $? -ne 0
+   then
+   retval=1
+   fi
+   ;;
+   *)
+   warn Warning: the command isn't recognized \
+   in the following line:
+   warn  - $line
+   warn
+   retval=1
+   ;;
+   esac
+   done
+
+   return $retval
+   )
+}
+
 # Print the list of the SHA-1 of the commits
 # from stdin to stdout
 todo_list_to_sha_list () {
@@ -868,6 +935,8 @@ checkout_onto () {
 
 # Check if the user dropped some commits by mistake
 # Behaviour determined by rebase.missingCommitsCheck.
+# Check if there is an unrecognized command or a
+# bad SHA-1 in a command.
 check_todo_list () {
raise_error=f
 
@@ -919,6 +988,12 @@ check_todo_list () {
;;
esac
 
+   check_bad_cmd_and_sha $todo
+   if test $? -ne 0
+   then
+   raise_error=t
+   fi
+
if test $raise_error = t
then
# Checkout before the first commit of the
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index fdbc900..9a96e15 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -54,6 +54,11 @@ set_fake_editor () {
echo '# comment'  $1;;
)
echo  $1;;
+   bad)
+   action=badcmd;;
+   fakesha)
+   echo $action XXX False commit  $1
+   action=pick;;
*)
sed -n ${line}s/^pick/$action/p  $1.tmp  $1
action=pick;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 904a2d0..9b2c51c 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1186,4 +1186,43 @@ test_expect_success 'rebase -i respects 
rebase.missingCommitsCheck = error' '
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+cat expect EOF
+Warning: the command isn't recognized in the following line:
+ - badcmd $(git rev-list --oneline -1 master~1)
+
+You can fix this with 'git rebase --edit-todo'.
+Or you can abort the rebase with 'git rebase --abort'.
+EOF
+
+test_expect_success 'static check of bad command

rebase -i: drop, missing commits and static checks

2015-06-29 Thread Galan Rémi
Changes between versions:

In t3404:

Changed 'test_rebase_end' to 'rebase_setup_and_clean'.
Changed the indentation in 'rebase_setup_and_clean'.
Changed the names of the branches created in my tests (avoid names
like 'tmp').
Added 'test_might_fail' in front of 'git branch -D'.
Remove 'test_config rebase.missingCommitsCheck error' in the last test
('static check of bad SHA-1') because it was useless.

In git-rebase--interactive.sh:

Errors found in commands and SHA-1 (static check) are displayed on the
spot.
I used return values to signal to the calling functions if there is an
error.
The whole while block in 'check_bad_cmd_and_sha' with the return is in a 
'(
[...]
)'
block because 'retval' would not have been correctly affected when
getting out of the loop since the while is in a pipe.

A thought occured to me:
Shouldn't all the checking also be called in a 'rebase --continue',
considering that it can be called after a 'rebase --edit-todo' ?
(Right now it is only called after closing the editor in 'rebase -i')

[PATCHv7 1/3] git-rebase -i: add command drop to remove a commit
[PATCHv7 2/3] git rebase -i: warn about removed commits
[PATCHv7 3/3] git rebase -i: add static check for commands and SHA-1

Rémi
(It seems that with 'send-email', 1 time out of 2 I get:
'5.7.8 Error: authentication failed: authentication failure')
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv7 1/3] git-rebase -i: add command drop to remove a commit

2015-06-29 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the
command drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh|  3 ++-
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 18 ++
 4 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..34bd070 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+To drop a commit, replace the command pick with drop, or just
+delete the matching line.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index dc3133f..72abf90 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -505,7 +506,7 @@ do_next () {
rm -f $msg $author_script $amend $state_dir/stopped-sha || exit
read -r command sha1 rest  $todo
case $command in
-   $comment_char*|''|noop)
+   $comment_char*|''|noop|drop|d)
mark_action_done
;;
pick|p)
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..3d059e5 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,22 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+rebase_setup_and_clean () {
+   test_when_finished 
+   git checkout master 
+   test_might_fail git branch -D $1 
+   test_might_fail git rebase --abort
+
+   git checkout -b $1 master
+}
+
+test_expect_success 'drop' '
+   rebase_setup_and_clean drop-test 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.3.532.gf6210e5.dirty

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv7 2/3] git rebase -i: warn about removed commits

2015-06-29 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) and print
warnings or stop git rebase depending on the value of the
configuration variable rebase.missingCommitsCheck.

This patch gives the user the possibility to avoid silent loss of
information (losing a commit through deleting the line in this case)
if he wants.

Add the configuration variable rebase.missingCommitsCheck.
- When unset or set to ignore, no checking is done.
- When set to warn, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to error, the commits are checked, warnings are
  displayed and the rebase is stopped.
  (The user can then use 'git rebase --edit-todo' and
  'git rebase --continue', or 'git rebase --abort')

rebase.missingCommitsCheck defaults to ignore.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/config.txt  |  11 +
 Documentation/git-rebase.txt  |   6 +++
 git-rebase--interactive.sh| 104 --
 t/t3404-rebase-interactive.sh |  66 +++
 4 files changed, 184 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 3e37b93..0360e7b 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2169,6 +2169,17 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.missingCommitsCheck::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (e.g. a line was deleted), however the
+   rebase will still proceed. If set to error, it will print
+   the previous warning and stop the rebase, 'git rebase
+   --edit-todo' can then be used to correct the error. If set to
+   ignore, no checking is done.
+   To drop a commit without warning or error, use the `drop`
+   command in the todo-list.
+   Defaults to ignore.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 34bd070..2ca3b8d 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,12 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.missingCommitsCheck::
+   If set to warn, print warnings about removed commits in
+   interactive mode. If set to error, print the warnings and
+   stop the rebase. If set to ignore, no checking is
+   done. ignore by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 72abf90..66daacf 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -834,6 +834,104 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the SHA-1 of the commits
+# from stdin to stdout
+todo_list_to_sha_list () {
+   git stripspace --strip-comments |
+   while read -r command sha1 rest
+   do
+   case $command in
+   $comment_char*|''|noop|x|exec)
+   ;;
+   *)
+   long_sha=$(git rev-list --no-walk $sha1 2/dev/null)
+   printf %s\n $long_sha
+   ;;
+   esac
+   done
+}
+
+# Use warn for each line in stdin
+warn_lines () {
+   while read -r line
+   do
+   warn  - $line
+   done
+}
+
+# Switch to the branch in $into and notify it in the reflog
+checkout_onto () {
+   GIT_REFLOG_ACTION=$GIT_REFLOG_ACTION: checkout $onto_name
+   output git checkout $onto || die_abort could not detach HEAD
+   git update-ref ORIG_HEAD $orig_head
+}
+
+# Check if the user dropped some commits by mistake
+# Behaviour determined by rebase.missingCommitsCheck.
+check_todo_list () {
+   raise_error=f
+
+   check_level=$(git config --get rebase.missingCommitsCheck)
+   check_level=${check_level:-ignore}
+   # Don't be case sensitive
+   check_level=$(printf '%s' $check_level | tr 'A-Z' 'a-z')
+
+   case $check_level in
+   warn|error)
+   # Get the SHA-1 of the commits
+   todo_list_to_sha_list $todo.backup $todo.oldsha1
+   todo_list_to_sha_list $todo $todo.newsha1
+
+   # Sort the SHA-1 and compare them
+   sort -u $todo.oldsha1 $todo.oldsha1+
+   mv $todo.oldsha1+ $todo.oldsha1
+   sort -u $todo.newsha1 $todo.newsha1+
+   mv $todo.newsha1+ $todo.newsha1
+   comm -2 -3 $todo.oldsha1 $todo.newsha1 $todo.miss
+
+   # Warn about missing commits
+   if test -s $todo.miss
+   then
+   test $check_level = error  raise_error=t

[PATCHv6 1/3] git-rebase -i: add command drop to remove a commit

2015-06-22 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the
command drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh|  3 ++-
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 16 
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..34bd070 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+To drop a commit, replace the command pick with drop, or just
+delete the matching line.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index dc3133f..72abf90 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -505,7 +506,7 @@ do_next () {
rm -f $msg $author_script $amend $state_dir/stopped-sha || exit
read -r command sha1 rest  $todo
case $command in
-   $comment_char*|''|noop)
+   $comment_char*|''|noop|drop|d)
mark_action_done
;;
pick|p)
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..ecd277c 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,20 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+test_rebase_end () {
+   test_when_finished git checkout master 
+   git branch -D $1 
+   test_might_fail git rebase --abort 
+   git checkout -b $1 master
+}
+
+test_expect_success 'drop' '
+   test_rebase_end dropTest 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.3.371.g8992f2a

--
To unsubscribe from this list: send the line unsubscribe git in


[PATCHv6 2/3] git rebase -i: warn about removed commits

2015-06-22 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) and print
warnings or stop git rebase depending on the value of the
configuration variable rebase.missingCommitsCheck.

This patch gives the user the possibility to avoid silent loss of
information (losing a commit through deleting the line in this case)
if he wants.

Add the configuration variable rebase.missingCommitsCheck.
- When unset or set to ignore, no checking is done.
- When set to warn, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to error, the commits are checked, warnings are
  displayed and the rebase is stopped.
  (The user can then use 'git rebase --edit-todo' and
  'git rebase --continue', or 'git rebase --abort')

rebase.missingCommitsCheck defaults to ignore.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 On the contrary of v5, the SHA-1 that are read are the short one.
 (the todo-list is read directly after the user closes his editor
 and not after expansion of ids)

 Documentation/config.txt  |  11 +
 Documentation/git-rebase.txt  |   6 +++
 git-rebase--interactive.sh| 104 --
 t/t3404-rebase-interactive.sh |  66 +++
 4 files changed, 184 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4d21ce1..25b2a04 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2160,6 +2160,17 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.missingCommitsCheck::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (e.g. a line was deleted), however the
+   rebase will still proceed. If set to error, it will print
+   the previous warning and stop the rebase, 'git rebase
+   --edit-todo' can then be used to correct the error. If set to
+   ignore, no checking is done.
+   To drop a commit without warning or error, use the `drop`
+   command in the todo-list.
+   Defaults to ignore.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 34bd070..2ca3b8d 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,12 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.missingCommitsCheck::
+   If set to warn, print warnings about removed commits in
+   interactive mode. If set to error, print the warnings and
+   stop the rebase. If set to ignore, no checking is
+   done. ignore by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 72abf90..66daacf 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -834,6 +834,104 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the SHA-1 of the commits
+# from stdin to stdout
+todo_list_to_sha_list () {
+   git stripspace --strip-comments |
+   while read -r command sha1 rest
+   do
+   case $command in
+   $comment_char*|''|noop|x|exec)
+   ;;
+   *)
+   long_sha=$(git rev-list --no-walk $sha1 2/dev/null)
+   printf %s\n $long_sha
+   ;;
+   esac
+   done
+}
+
+# Use warn for each line in stdin
+warn_lines () {
+   while read -r line
+   do
+   warn  - $line
+   done
+}
+
+# Switch to the branch in $into and notify it in the reflog
+checkout_onto () {
+   GIT_REFLOG_ACTION=$GIT_REFLOG_ACTION: checkout $onto_name
+   output git checkout $onto || die_abort could not detach HEAD
+   git update-ref ORIG_HEAD $orig_head
+}
+
+# Check if the user dropped some commits by mistake
+# Behaviour determined by rebase.missingCommitsCheck.
+check_todo_list () {
+   raise_error=f
+
+   check_level=$(git config --get rebase.missingCommitsCheck)
+   check_level=${check_level:-ignore}
+   # Don't be case sensitive
+   check_level=$(printf '%s' $check_level | tr 'A-Z' 'a-z')
+
+   case $check_level in
+   warn|error)
+   # Get the SHA-1 of the commits
+   todo_list_to_sha_list $todo.backup $todo.oldsha1
+   todo_list_to_sha_list $todo $todo.newsha1
+
+   # Sort the SHA-1 and compare them
+   sort -u $todo.oldsha1 $todo.oldsha1+
+   mv $todo.oldsha1+ $todo.oldsha1
+   sort -u $todo.newsha1 $todo.newsha1+
+   mv $todo.newsha1+ $todo.newsha1
+   comm -2 -3 $todo.oldsha1 $todo.newsha1 $todo.miss
+
+   # Warn about

[PATCHv6 3/3] git rebase -i: add static check for commands and SHA-1

2015-06-22 Thread Galan Rémi
Check before the start of the rebasing if the commands exists, and for
the commands expecting a SHA-1, check if the SHA-1 is present and
corresponds to a commit. In case of error, print the error, stop git
rebase and prompt the user to fix with 'git rebase --edit-todo' or to
abort.

This allows to avoid doing half of a rebase before finding an error
and giving back what's left of the todo list to the user and prompt
him to fix when it might be too late for him to do so (he might have
to abort and restart the rebase).

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 I used:
   read -r command sha1 rest EOF
   $line
   EOF
 because
   printf '%s' $line | read -r command sha1 rest
 doesn't work (the 3 variables have no value as a result).
 There might be a better way to do this, but I don't have it right now.

 git-rebase--interactive.sh| 70 +++
 t/lib-rebase.sh   |  5 
 t/t3404-rebase-interactive.sh | 40 +
 3 files changed, 115 insertions(+)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 66daacf..6381686 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -834,6 +834,52 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Check if the SHA-1 passed as an argument is a
+# correct one, if not then print $2 in $todo.badsha
+# $1: the SHA-1 to test
+# $2: the line to display if incorrect SHA-1
+check_commit_sha () {
+   badsha=f
+   if test -z $1
+   then
+   badsha=t
+   else
+   sha1_verif=$(git rev-parse --verify --quiet $1^{commit})
+   if test -z $sha1_verif
+   then
+   badsha=t
+   fi
+   fi
+
+   if test $badsha = t
+   then
+   printf '%s\n' $2 $todo.badsha
+   fi
+}
+
+# prints the bad commits and bad commands
+# from the todolist in stdin
+check_bad_cmd_and_sha () {
+   git stripspace --strip-comments |
+   while read -r line
+   do
+   read -r command sha1 rest EOF
+$line
+EOF
+   case $command in
+   ''|noop|x|exec)
+   # Doesn't expect a SHA-1
+   ;;
+   pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
+   check_commit_sha $sha1 $line
+   ;;
+   *)
+   printf '%s\n' $line $todo.badcmd
+   ;;
+   esac
+   done
+}
+
 # Print the list of the SHA-1 of the commits
 # from stdin to stdout
 todo_list_to_sha_list () {
@@ -868,6 +914,8 @@ checkout_onto () {
 
 # Check if the user dropped some commits by mistake
 # Behaviour determined by rebase.missingCommitsCheck.
+# Check if there is an unrecognized command or a
+# bad SHA-1 in a command.
 check_todo_list () {
raise_error=f
 
@@ -919,6 +967,28 @@ check_todo_list () {
;;
esac
 
+   check_bad_cmd_and_sha $todo
+
+   if test -s $todo.badsha
+   then
+   raise_error=t
+
+   warn Warning: the SHA-1 is missing or isn't \
+   a commit in the following line(s):
+   warn_lines $todo.badsha
+   warn
+   fi
+
+   if test -s $todo.badcmd
+   then
+   raise_error=t
+
+   warn Warning: the command isn't recognized \
+   in the following line(s):
+   warn_lines $todo.badcmd
+   warn
+   fi
+
if test $raise_error = t
then
# Checkout before the first commit of the
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index fdbc900..9a96e15 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -54,6 +54,11 @@ set_fake_editor () {
echo '# comment'  $1;;
)
echo  $1;;
+   bad)
+   action=badcmd;;
+   fakesha)
+   echo $action XXX False commit  $1
+   action=pick;;
*)
sed -n ${line}s/^pick/$action/p  $1.tmp  $1
action=pick;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index a92ae19..d691b1c 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1184,4 +1184,44 @@ test_expect_success 'rebase -i respects 
rebase.missingCommitsCheck = error' '
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+cat expect EOF
+Warning: the command isn't recognized in the following line(s):
+ - badcmd $(git rev-list --oneline -1 master~1)
+
+You can fix this with 'git rebase --edit-todo'.
+Or you can abort the rebase with 'git rebase --abort'.
+EOF
+
+test_expect_success 'static check of bad command' '
+   test_rebase_end tmp2 
+   set_fake_editor 
+   test_must_fail env FAKE_LINES=1 2 3 bad 4 5

[PATCH/RFCv5 1/3] git-rebase -i: add command drop to remove a commit

2015-06-10 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the
command drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 In t3404, test_rebase_end is introduced, mainly because it will be
 reused in future tests (in 2/3 and 3/3).

 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh|  3 ++-
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 16 
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..34bd070 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+To drop a commit, replace the command pick with drop, or just
+delete the matching line.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index dc3133f..72abf90 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -505,7 +506,7 @@ do_next () {
rm -f $msg $author_script $amend $state_dir/stopped-sha || exit
read -r command sha1 rest  $todo
case $command in
-   $comment_char*|''|noop)
+   $comment_char*|''|noop|drop|d)
mark_action_done
;;
pick|p)
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..ecd277c 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,20 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+test_rebase_end () {
+   test_when_finished git checkout master 
+   git branch -D $1 
+   test_might_fail git rebase --abort 
+   git checkout -b $1 master
+}
+
+test_expect_success 'drop' '
+   test_rebase_end dropTest 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.2.496.gdc9319a

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFCv5 2/3] git rebase -i: warn about removed commits

2015-06-10 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) and print
warnings or stop git rebase depending on the value of the
configuration variable rebase.missingCommitsCheck.

This patch gives the user the possibility to avoid silent loss of
information (losing a commit through deleting the line in this case)
if he wants.

Add the configuration variable rebase.missingCommitsCheck.
- When unset or set to ignore, no checking is done.
- When set to warn, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to error, the commits are checked, warnings are
  displayed and the rebase is stopped.
  (The user can then use 'git rebase --edit-todo' and
  'git rebase --continue', or 'git rebase --abort')

rebase.missingCommitsCheck defaults to ignore.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 In git-rebase--interactive, in the error case of check_todo_list, I
 added 'git checkout $onto' so that using 'die' for the error allows
 to use 'git rebase --edit-todo' (otherwise HEAD would not have been
 changed and it still would be placed after the commits of the
 rebase).
 Since now it doesn't abort the rebase, the documentation and the
 messages in the case error have changed.
 I moved the error case away from the initial test case for missing
 commits as to prepare for 3/3 part of the patch. It is something that
 was advised by Eric Sunshine when I checked both missing and
 duplicated commits, but that I removed it when removing the checking
 for duplicated commits since there was only one test. However I add
 it again since 3/3 will add more checking.
 I use the variable raiseError that I affect if the error must be
 raised instead of testing directly because I think it makes more
 sense with 3/3 and if we add other check in the future since it adds
 more possible errors (the test for the error case if not something
 like 'if (test checkLevel = error  test -s todo.miss) || test cond2
 || test cond3 || ...').
 I am wondering if a check_todo_list call should be added in the
 '--continue' part of the code: with this patch, the checking is only
 done once, if the user doesn't edit correctly with 'git rebase
 --edit-todo', it won't be picked by this.
 In the tests in t3404 I now also test that the warning/error messages
 are correct.
 I tried to not change this patch too much since it was already
 heavily reviewed, but there are some changes (mostly the ones
 mentionned above).

 Documentation/config.txt  | 11 +
 Documentation/git-rebase.txt  |  6 +++
 git-rebase--interactive.sh| 96 +++
 t/t3404-rebase-interactive.sh | 66 +
 4 files changed, 179 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4d21ce1..25b2a04 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2160,6 +2160,17 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.missingCommitsCheck::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (e.g. a line was deleted), however the
+   rebase will still proceed. If set to error, it will print
+   the previous warning and stop the rebase, 'git rebase
+   --edit-todo' can then be used to correct the error. If set to
+   ignore, no checking is done.
+   To drop a commit without warning or error, use the `drop`
+   command in the todo-list.
+   Defaults to ignore.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 34bd070..2ca3b8d 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,12 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.missingCommitsCheck::
+   If set to warn, print warnings about removed commits in
+   interactive mode. If set to error, print the warnings and
+   stop the rebase. If set to ignore, no checking is
+   done. ignore by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 72abf90..68a71d0 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -834,6 +834,100 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the SHA-1 of the commits
+# from stdin to stdout
+todo_list_to_sha_list () {
+   git stripspace --strip-comments |
+   while read -r command sha1 rest
+   do
+   case $command in
+   $comment_char*|''|noop|x|exec)
+   ;;
+   *)
+   printf %s\n $sha1
+   ;;
+   esac

[PATCH/RFCv5 3/3] git rebase -i: add static check for commands and SHA-1

2015-06-10 Thread Galan Rémi
Check before the start of the rebasing if the commands exists, and for
the commands expecting a SHA-1, check if the SHA-1 is present and
corresponds to a commit. In case of error, print the error, stop git
rebase and prompt the user to fix with 'git rebase --edit-todo' or to
abort.

This allows to avoid doing half of a rebase before finding an error
and giving back what's left of the todo list to the user and prompt
him to fix when it might be too late for him to do so (he might have
to abort and restart the rebase).

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 git-rebase--interactive.sh| 63 +++
 t/lib-rebase.sh   |  5 
 t/t3404-rebase-interactive.sh | 40 +++
 3 files changed, 108 insertions(+)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 68a71d0..226a8a8 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -834,6 +834,47 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# prints the bad commits and bad commands
+# from the todolist in stdin
+check_bad_cmd_and_sha () {
+   git stripspace --strip-comments |
+   while read -r command sha1 rest
+   do
+   case $command in
+   ''|noop|x|exec)
+   ;;
+   pick|p|drop|d|reword|r|edit|e|squash|s|fixup|f)
+   if test -z $sha1
+   then
+   echo $command $rest $todo.badsha
+   else
+   sha1_verif=$(git rev-parse --verify --quiet 
$sha1^{commit})
+   if test -z $sha1_verif
+   then
+   echo $command $sha1 $rest \
+   $todo.badsha
+   fi
+   fi
+   ;;
+   *)
+   if test -z $sha1
+   then
+   echo $command $todo.badcmd
+   else
+   commit=$(git rev-list --oneline -1 
--ignore-missing $sha1 2/dev/null)
+   if test -z $commit
+   then
+   echo $command $sha1 $rest \
+   $todo.badcmd
+   else
+   echo $command $commit $todo.badcmd
+   fi
+   fi
+   ;;
+   esac
+   done
+}
+
 # Print the list of the SHA-1 of the commits
 # from stdin to stdout
 todo_list_to_sha_list () {
@@ -913,6 +954,28 @@ check_todo_list () {
;;
esac
 
+   check_bad_cmd_and_sha $todo
+
+   if test -s $todo.badsha
+   then
+   raiseError=t
+
+   warn Warning: the SHA-1 is missing or isn't \
+   a commit in the following line(s):
+   warn_file $todo.badsha
+   warn
+   fi
+
+   if test -s $todo.badcmd
+   then
+   raiseError=t
+
+   warn Warning: the command isn't recognized \
+   in the following line(s):
+   warn_file $todo.badcmd
+   warn
+   fi
+
if test $raiseError = t
then
# Checkout before the first commit of the
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index fdbc900..9a96e15 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -54,6 +54,11 @@ set_fake_editor () {
echo '# comment'  $1;;
)
echo  $1;;
+   bad)
+   action=badcmd;;
+   fakesha)
+   echo $action XXX False commit  $1
+   action=pick;;
*)
sed -n ${line}s/^pick/$action/p  $1.tmp  $1
action=pick;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index a92ae19..d691b1c 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1184,4 +1184,44 @@ test_expect_success 'rebase -i respects 
rebase.missingCommitsCheck = error' '
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+cat expect EOF
+Warning: the command isn't recognized in the following line(s):
+ - badcmd $(git rev-list --oneline -1 master~1)
+
+You can fix this with 'git rebase --edit-todo'.
+Or you can abort the rebase with 'git rebase --abort'.
+EOF
+
+test_expect_success 'static check of bad command' '
+   test_rebase_end tmp2 
+   set_fake_editor 
+   test_must_fail env FAKE_LINES=1 2 3 bad 4 5 \
+   git rebase -i --root 2actual 
+   test_cmp expect actual 
+   FAKE_LINES=1 2 3 drop 4 5 git rebase

[PATCH/RFCv4 1/2] git-rebase -i: add command drop to remove a commit

2015-06-03 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the
command drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh| 18 ++
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 10 ++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..9cf3760 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+To drop a commit, replace the command pick with drop, or just
+delete its line.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index dc3133f..869cc60 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -508,6 +509,23 @@ do_next () {
$comment_char*|''|noop)
mark_action_done
;;
+   drop|d)
+   if test -z $sha1
+   then
+   warn Missing SHA-1 in 'drop' command.
+   die Please fix this using 'git rebase --edit-todo'.
+   fi
+
+   sha1_verif=$(git rev-parse --verify --quiet $sha1^{commit})
+   if test -z $sha1_verif
+   then
+   warn '$sha1' is not a SHA-1 or does not represent \
+   a commit in 'drop' command.
+   die Please fix this using 'git rebase --edit-todo'.
+   fi
+
+   mark_action_done
+   ;;
pick|p)
comment_for_reflog pick
 
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..8960083 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,14 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+test_expect_success 'drop' '
+   test_when_finished git checkout master 
+   git checkout -b dropBranchTest master 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.2.389.geaf7ccf

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFCv4 2/2] git rebase -i: warn about removed commits

2015-06-03 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) and print
warnings or abort git rebase depending on the value of the
configuration variable rebase.missingCommits.

This patch gives the user the possibility to avoid silent loss of
information (losing a commit through deleting the line in this case)
if he wants to.

Add the configuration variable rebase.missingCommitsCheck.
- When unset or set to ignore, no checking is done.
- When set to warn, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to error, the commits are checked, warnings are
  displayed and the rebase is aborted.

rebase.missingCommitsCheck defaults to ignore.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/config.txt  | 10 ++
 Documentation/git-rebase.txt  |  6 
 git-rebase--interactive.sh| 82 +++
 t/t3404-rebase-interactive.sh | 63 +
 4 files changed, 161 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4d21ce1..b29cd8d 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2160,6 +2160,16 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.missingCommitsCheck::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (e.g. a line was deleted), however the
+   rebase will still proceed. If set to error, it will print
+   the previous warning and abort the rebase. If set to
+   ignore, no checking is done.
+   To drop a commit without warning or error, use the `drop`
+   command in the todo-list.
+   Defaults to ignore.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 9cf3760..6d413a1 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,12 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.missingCommitsCheck::
+   If set to warn print warnings about removed commits in
+   interactive mode. If set to error print the warnings and
+   abort the rebase. If set to ignore no checking is
+   done. ignore by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 869cc60..26804dd 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -851,6 +851,86 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the SHA-1 of the commits
+# from a todo list in a file.
+# $1: todo-file, $2: outfile
+todo_list_to_sha_list () {
+   git stripspace --strip-comments $1 | while read -r command sha1 rest
+   do
+   case $command in
+   x|exec)
+   ;;
+   *)
+   printf %s\n $sha1
+   ;;
+   esac
+   done $2
+}
+
+# Use warn for each line of a file
+# $1: file
+warn_file () {
+   while read -r line
+   do
+   warn  - $line
+   done $1
+}
+
+# Check if the user dropped some commits by mistake
+# Behaviour determined by rebase.missingCommitsCheck.
+check_commits () {
+   checkLevel=$(git config --get rebase.missingCommitsCheck)
+   checkLevel=${checkLevel:-ignore}
+   # Don't be case sensitive
+   checkLevel=$(echo $checkLevel | tr 'A-Z' 'a-z')
+
+   case $checkLevel in
+   warn|error)
+   # Get the SHA-1 of the commits
+   todo_list_to_sha_list $todo.backup $todo.oldsha1
+   todo_list_to_sha_list $todo $todo.newsha1
+
+   # Sort the SHA-1 and compare them
+   sort -u $todo.oldsha1 $todo.oldsha1+
+   mv $todo.oldsha1+ $todo.oldsha1
+   sort -u $todo.newsha1 $todo.newsha1+
+   mv $todo.newsha1+ $todo.newsha1
+   comm -2 -3 $todo.oldsha1 $todo.newsha1 $todo.miss
+
+   # Make the list user-friendly
+   opt=--no-walk=sorted --format=oneline --abbrev-commit --stdin
+   git rev-list $opt $todo.miss $todo.miss+
+   mv $todo.miss+ $todo.miss
+
+   # Check missing commits
+   if test -s $todo.miss
+   then
+   warn Warning: some commits may have been dropped \
+   accidentally.
+   warn Dropped commits (newer to older):
+   warn_file $todo.miss
+   warn 
+   warn To avoid this message, use \drop\ to \
+   explicitly remove a commit.
+   warn Use git

[PATCH/RFCv3 1/2] git-rebase -i: add command drop to remove a commit

2015-06-02 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the
command drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh| 18 ++
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 10 ++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..9cf3760 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+To drop a commit, replace the command pick with drop, or just
+delete its line.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index dc3133f..869cc60 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -508,6 +509,23 @@ do_next () {
$comment_char*|''|noop)
mark_action_done
;;
+   drop|d)
+   if test -z $sha1
+   then
+   warn Missing SHA-1 in 'drop' command.
+   die Please fix this using 'git rebase --edit-todo'.
+   fi
+
+   sha1_verif=$(git rev-parse --verify --quiet $sha1^{commit})
+   if test -z $sha1_verif
+   then
+   warn '$sha1' is not a SHA-1 or does not represent \
+   a commit in 'drop' command.
+   die Please fix this using 'git rebase --edit-todo'.
+   fi
+
+   mark_action_done
+   ;;
pick|p)
comment_for_reflog pick
 
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..8960083 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,14 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+test_expect_success 'drop' '
+   test_when_finished git checkout master 
+   git checkout -b dropBranchTest master 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.1.411.g9c4ad60

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFCv3 2/2] git rebase -i: warn about removed commits

2015-06-02 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) and print
warnings or abort git rebase according to the value of the
configuration variable rebase.missingCommitsCheckLevel.

Add the configuration variable rebase.missingCommitsCheckLevel.
- When unset or set to ignore, no checking is done.
- When set to warn, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to error, the commits are checked, warnings are
  displayed and the rebase is aborted.

rebase.missingCommitsCheckLevel defaults to ignore.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/config.txt  |   7 +++
 Documentation/git-rebase.txt  |   6 +++
 git-rebase--interactive.sh| 105 ++
 t/t3404-rebase-interactive.sh |  25 ++
 4 files changed, 143 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4d21ce1..ec9011d 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2160,6 +2160,13 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.missingCommitsCheckLevel::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (i.e. a line was deleted), however the
+   rebase will still proceed. If set to error, it will print
+   the previous warning and abort the rebase. If set to
+   ignore, no checking is done.  Defaults to ignore.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 9cf3760..71029f8 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,12 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.missingCommitsCheckLevel::
+   If set to warn print warnings about removed commits in
+   interactive mode. If set to error print the warnings and
+   abort the rebase. If set to ignore no checking is
+   done. ignore by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 869cc60..6391423 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -851,6 +851,109 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the SHA-1 of the commits
+# from a todo list in a file.
+# $1: todo-file, $2: outfile
+todo_list_to_sha_list () {
+   todo_list=$(git stripspace --strip-comments $1)
+   temp_file=$(mktemp)
+   echo $todo_list $temp_file
+   while read -r command sha1 rest
+   do
+   case $command in
+   x|exec)
+   ;;
+   *)
+   printf %s\n $sha1
+   ;;
+   esac
+   done $temp_file $2
+   rm $temp_file
+}
+
+# Transforms SHA-1 list in argument
+# to a list of commits (in place)
+# Doesn't check if the SHA-1 are commits.
+# $1: file with long SHA-1 list
+long_sha_to_commit_list () {
+   short_missing=
+   git_command=git show --oneline
+   get_line_command=head -n 1
+   temp_file=$(mktemp)
+   while read -r sha
+   do
+   if test -n $sha
+   then
+   commit=$($git_command $sha | $get_line_command)
+   if test -n $commit
+   then
+   printf %s\n $commit
+   fi
+   fi
+   done $1 $temp_file
+   mv $temp_file $1
+}
+
+# Use warn for each line of a file
+# $1: file to warn
+warn_file () {
+   while read -r line
+   do
+   warn  - $line
+   done $1
+}
+
+# Check if the user dropped some commits by mistake
+# Behaviour determined by .gitconfig.
+check_commits () {
+   checkLevel=$(git config --get rebase.missingCommitsCheckLevel)
+   checkLevel=${checkLevel:-ignore}
+   # To lowercase
+   checkLevel=$(echo $checkLevel | tr 'A-Z' 'a-z')
+
+   case $checkLevel in
+   warn|error)
+   # Get the SHA-1 of the commits
+   todo_list_to_sha_list $todo.backup $todo.oldsha1
+   todo_list_to_sha_list $todo $todo.newsha1
+
+   # Sort the SHA-1 and compare them
+   echo $(sort -u $todo.oldsha1) $todo.oldsha1
+   echo $(sort -u $todo.newsha1) $todo.newsha1
+   echo $(comm -2 -3 $todo.oldsha1 $todo.newsha1) 
$todo.miss
+
+   # Make the list user-friendly
+   long_sha_to_commit_list $todo.miss
+
+   # Check missing commits
+   if test -s $todo.miss
+   then
+   warn Warning : some commits may have been dropped

[PATCH/RFCv2 2/2] git rebase -i: warn about removed commits

2015-06-01 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) and print
warnings or abort git rebase according to the value of the
configuration variable rebase.checkLevel.

Add the configuration variable rebase.checkLevel.
- When unset or set to ignore, no checking is done.
- When set to warn, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to error, the commits are checked, warnings are
  displayed and the rebase is aborted.

rebase.checkLevel defaults to ignore.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/config.txt  |   9 
 Documentation/git-rebase.txt  |   6 +++
 git-rebase--interactive.sh| 105 ++
 t/t3404-rebase-interactive.sh |  10 +++-
 4 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5f76e8c..e2e5554 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2160,6 +2160,15 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.checkLevel::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (i.e. a line was deleted) or if some
+   commits appear more than one time (e.g. the same commit is
+   picked twice), however the rebase will still proceed. If set
+   to error, it will print the previous warnings and abort the
+   rebase. If set to ignore, no checking is done.  Defaults to
+   ignore.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 9cf3760..d348ca2 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,12 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.checkLevel::
+   If set to warn print warnings about removed commits and
+   duplicated commits in interactive mode. If set to error
+   print the warnings and abort the rebase. If set to ignore no
+   checking is done. ignore by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 2882276..58da6ee 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -837,6 +837,109 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the SHA-1 of the commits
+# from a todo list in a file.
+# $1: todo-file, $2: outfile
+todo_list_to_sha_list () {
+   todo_list=$(git stripspace --strip-comments $1)
+   temp_file=$(mktemp)
+   echo $todo_list $temp_file
+   while read -r command sha1 rest
+   do
+   case $command in
+   x|exec)
+   ;;
+   *)
+   printf %s\n $sha1
+   ;;
+   esac
+   done $temp_file $2
+   rm $temp_file
+}
+
+# Transforms SHA-1 list in argument
+# to a list of commits (in place)
+# Doesn't check if the SHA-1 are commits.
+# $1: file with long SHA-1 list
+long_sha_to_commit_list () {
+   short_missing=
+   git_command=git show --oneline
+   get_line_command=head -n 1
+   temp_file=$(mktemp)
+   while read -r sha
+   do
+   if test -n $sha
+   then
+   commit=$($git_command $sha | $get_line_command)
+   if test -n $commit
+   then
+   printf %s\n $commit
+   fi
+   fi
+   done $1 $temp_file
+   mv $temp_file $1
+}
+
+# Use warn for each line of a file
+# $1: file to warn
+warn_file () {
+   while read -r line
+   do
+   warn  - $line
+   done $1
+}
+
+# Check if the user dropped some commits by mistake
+# Behaviour determined by .gitconfig.
+check_commits () {
+   checkLevel=$(git config --get rebase.checkLevel)
+   checkLevel=${checkLevel:-ignore}
+   # To lowercase
+   checkLevel=$(echo $checkLevel | tr 'A-Z' 'a-z')
+
+   case $checkLevel in
+   warn|error)
+   # Get the SHA-1 of the commits
+   todo_list_to_sha_list $todo.backup $todo.oldsha1
+   todo_list_to_sha_list $todo $todo.newsha1
+
+   # Sort the SHA-1 and compare them
+   echo $(sort -u $todo.oldsha1) $todo.oldsha1
+   echo $(sort -u $todo.newsha1) $todo.newsha1
+   echo $(comm -2 -3 $todo.oldsha1 $todo.newsha1) 
$todo.miss
+
+   # Make the list user-friendly
+   long_sha_to_commit_list $todo.miss
+
+   # Check missing commits
+   if test -s $todo.miss
+   then
+   warn Warning

[PATCH/RFCv2 1/2] git-rebase -i: add command drop to remove a commit

2015-06-01 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the
command drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh|  3 ++-
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 11 +++
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..9cf3760 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+To drop a commit, replace the command pick with drop, or just
+delete its line.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index bab0dcc..2882276 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -505,7 +506,7 @@ do_next () {
rm -f $msg $author_script $amend || exit
read -r command sha1 rest  $todo
case $command in
-   $comment_char*|''|noop)
+   $comment_char*|''|noop|drop|d)
mark_action_done
;;
pick|p)
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..1bad068 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,15 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+test_expect_success 'drop' '
+   git checkout master 
+   test_when_finished git checkout master 
+   git checkout -b dropBranchTest master 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.1.363.g9535a9c

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFCv2 0/2] rebase -i : drop command and removed commits

2015-06-01 Thread Galan Rémi
 - [PATCH 1/2] git-rebase -i: add command drop to remove a commit
The 'drop' command is added as a way to explicitely remove commits in
git rebase -i.
This patch does not prevent users from commenting the line, removing
the line or using the 'noop' command if they want to.
While the 'noop' command has the same effect, it doesn't seem to be
the right use for it since 'noop' merely ignores everything that
follows, in particular writing 'noop SHA-1 text' can be confusing.
Commenting a line also has the same effect but the 2/2 part of the
patch is not made for working correctly with comments (though it still
works with 'noop').
This command is inspired by the command 'drop' in histedit of
Mercurial (though in the idea, it is not made to make migrants from
Mercurial feel better but rather because it seems like a good idea).
For the 'drop' command, maybe instead of just doing the same thing as
noop, checking if the SHA-1 that supposedly follow does exist could be
a good idea.

 - [PATCH 2/2] git rebase -i: warn about removed commits 
Since the default behaviour is 'ignore', meaning that no checking is
done and no warning is displayed, users that are used to remove the
lines to remove a commit can still do so without changing their
configuration.
However this patch gives the user the possibility to avoid silent loss
of information if he wants.
Regarding the comments of v1 : The dupplicated commits are not checked
anymore ((about the review by Eric Sunshine) thus the error case stays
within the warning test, now that we only have one test for warnings).
The list of removed commits is now shown in the format 'short SHA-1
commit-message' instead of 'full SHA-1', this was done following
an idea given by Matthieu Moy outside of the mailing list. 
Because of this some code have been added and modified and thus need
reviewing.
A test has been added to check the correct behaviour of the error
configuration.

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFCv2 2/2] git rebase -i: warn about removed commits

2015-06-01 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) and print
warnings or abort git rebase according to the value of the
configuration variable rebase.checkLevel.

Add the configuration variable rebase.checkLevel.
- When unset or set to ignore, no checking is done.
- When set to warn, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to error, the commits are checked, warnings are
  displayed and the rebase is aborted.

rebase.checkLevel defaults to ignore.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/config.txt  |   9 
 Documentation/git-rebase.txt  |   6 +++
 git-rebase--interactive.sh| 105 ++
 t/t3404-rebase-interactive.sh |  10 +++-
 4 files changed, 129 insertions(+), 1 deletion(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5f76e8c..e2e5554 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2160,6 +2160,15 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.checkLevel::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (i.e. a line was deleted) or if some
+   commits appear more than one time (e.g. the same commit is
+   picked twice), however the rebase will still proceed. If set
+   to error, it will print the previous warnings and abort the
+   rebase. If set to ignore, no checking is done.  Defaults to
+   ignore.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 9cf3760..d348ca2 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,12 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.checkLevel::
+   If set to warn print warnings about removed commits and
+   duplicated commits in interactive mode. If set to error
+   print the warnings and abort the rebase. If set to ignore no
+   checking is done. ignore by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 2882276..58da6ee 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -837,6 +837,109 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the SHA-1 of the commits
+# from a todo list in a file.
+# $1: todo-file, $2: outfile
+todo_list_to_sha_list () {
+   todo_list=$(git stripspace --strip-comments $1)
+   temp_file=$(mktemp)
+   echo $todo_list $temp_file
+   while read -r command sha1 rest
+   do
+   case $command in
+   x|exec)
+   ;;
+   *)
+   printf %s\n $sha1
+   ;;
+   esac
+   done $temp_file $2
+   rm $temp_file
+}
+
+# Transforms SHA-1 list in argument
+# to a list of commits (in place)
+# Doesn't check if the SHA-1 are commits.
+# $1: file with long SHA-1 list
+long_sha_to_commit_list () {
+   short_missing=
+   git_command=git show --oneline
+   get_line_command=head -n 1
+   temp_file=$(mktemp)
+   while read -r sha
+   do
+   if test -n $sha
+   then
+   commit=$($git_command $sha | $get_line_command)
+   if test -n $commit
+   then
+   printf %s\n $commit
+   fi
+   fi
+   done $1 $temp_file
+   mv $temp_file $1
+}
+
+# Use warn for each line of a file
+# $1: file to warn
+warn_file () {
+   while read -r line
+   do
+   warn  - $line
+   done $1
+}
+
+# Check if the user dropped some commits by mistake
+# Behaviour determined by .gitconfig.
+check_commits () {
+   checkLevel=$(git config --get rebase.checkLevel)
+   checkLevel=${checkLevel:-ignore}
+   # To lowercase
+   checkLevel=$(echo $checkLevel | tr 'A-Z' 'a-z')
+
+   case $checkLevel in
+   warn|error)
+   # Get the SHA-1 of the commits
+   todo_list_to_sha_list $todo.backup $todo.oldsha1
+   todo_list_to_sha_list $todo $todo.newsha1
+
+   # Sort the SHA-1 and compare them
+   echo $(sort -u $todo.oldsha1) $todo.oldsha1
+   echo $(sort -u $todo.newsha1) $todo.newsha1
+   echo $(comm -2 -3 $todo.oldsha1 $todo.newsha1) 
$todo.miss
+
+   # Make the list user-friendly
+   long_sha_to_commit_list $todo.miss
+
+   # Check missing commits
+   if test -s $todo.miss
+   then
+   warn Warning

[PATCH/RFCv2 1/2] git-rebase -i: add command drop to remove a commit

2015-06-01 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the
command drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh|  3 ++-
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 11 +++
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..9cf3760 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+To drop a commit, replace the command pick with drop, or just
+delete its line.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index bab0dcc..2882276 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -505,7 +506,7 @@ do_next () {
rm -f $msg $author_script $amend || exit
read -r command sha1 rest  $todo
case $command in
-   $comment_char*|''|noop)
+   $comment_char*|''|noop|drop|d)
mark_action_done
;;
pick|p)
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..1bad068 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,15 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+test_expect_success 'drop' '
+   git checkout master 
+   test_when_finished git checkout master 
+   git checkout -b dropBranchTest master 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.1.363.g9535a9c

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH/RFC 2/2] git rebase -i: Warn removed or dupplicated commits

2015-05-26 Thread Galan Rémi
Check if commits were removed (i.e. a line was deleted) or dupplicated
(e.g. the same commit is picked twice), can print warnings or abort
git rebase according to the value of the configuration variable
rebase.checkLevel.

Add the configuration variable rebase.checkLevel.
- When unset or set to IGNORED, no checking is done.
- When set to WARN, the commits are checked, warnings are
  displayed but git rebase still proceeds.
- When set to ERROR, the commits are checked, warnings are
  displayed and the rebase is aborted.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 This part of the patch has no test yet, it is more for rfc.

 Documentation/config.txt |  8 +
 Documentation/git-rebase.txt |  5 +++
 git-rebase--interactive.sh   | 76 
 3 files changed, 89 insertions(+)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index d44bc85..2152e27 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2204,6 +2204,14 @@ rebase.autoStash::
successful rebase might result in non-trivial conflicts.
Defaults to false.
 
+rebase.checkLevel::
+   If set to warn, git rebase -i will print a warning if some
+   commits are removed (i.e. a line was deleted) or if some
+   commits appear more than one time (e.g. the same commit is
+   picked twice), however the rebase will still proceed. If set
+   to error, it will print the previous warnings and abort the
+   rebase.
+
 receive.advertiseAtomic::
By default, git-receive-pack will advertise the atomic push
capability to its clients. If you don't want to this capability
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 3cd2ef2..cb05cbb 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -213,6 +213,11 @@ rebase.autoSquash::
 rebase.autoStash::
If set to true enable '--autostash' option by default.
 
+rebase.checkLevel::
+   If set to warn print warnings about removed commits and
+   duplicated commits in interactive mode. If set to error
+   print the warnings and abort the rebase. No check by default.
+
 OPTIONS
 ---
 --onto newbase::
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index cb749e8..8a837ca 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -837,6 +837,80 @@ add_exec_commands () {
mv $1.new $1
 }
 
+# Print the list of the sha-1 of the commits
+# from a todo list in a file.
+# $1 : todo-file, $2 : outfile
+todo_list_to_sha_list () {
+   todo_list=$(git stripspace --strip-comments  $1)
+   temp_file=$(mktemp)
+   echo $todo_list  $temp_file
+   while read -r command sha1 rest  $temp_file
+   do
+   case $command in
+   x|exec)
+   ;;
+   *)
+   echo $sha1  $2
+   ;;
+   esac
+   sed -i '1d' $temp_file
+   done
+   rm $temp_file
+}
+
+# Check if the user dropped some commits by mistake
+# or if there are two identical commits.
+# Behaviour determined by .gitconfig.
+check_commits () {
+   checkLevel=$(git config --get rebase.checkLevel)
+   checkLevel=${checkLevel:-IGNORE}
+   # To uppercase
+   checkLevel=$(echo $checkLevel | tr '[:lower:]' '[:upper:]')
+
+   case $checkLevel in
+   WARN|ERROR)
+   todo_list_to_sha_list $todo.backup $todo.oldsha1
+   todo_list_to_sha_list $todo $todo.newsha1
+
+   duplicates=$(sort $todo.newsha1 | uniq -d)
+
+   echo $(sort -u $todo.oldsha1)  $todo.oldsha1
+   echo $(sort -u $todo.newsha1)  $todo.newsha1
+   missing=$(comm -2 -3 $todo.oldsha1 $todo.newsha1)
+
+   # check missing commits
+   if ! test -z $missing
+   then
+   warn Warning : some commits may have been dropped 
accidentally.
+   warn Dropped commits:
+   warn $missing
+   warn To avoid this message, use \drop\ to 
explicitely remove a commit.
+   warn Use git --config rebase.checkLevel to change
+   warn the level of warnings (ignore,warn,error).
+   warn 
+
+   if test $checkLevel = ERROR
+   then
+   die_abort Rebase aborted due to dropped 
commits.
+   fi
+   fi
+
+   # check duplicate commits
+   if ! test -z $duplicates
+   then
+   warn Warning : some commits have been used twice:
+   warn $duplicates
+   warn 
+   fi
+   ;;
+   IGNORE)
+   ;;
+   *)
+   warn Unrecognized setting

[PATCH/RFC 1/2] git-rebase -i: Add key word drop to remove a commit

2015-05-26 Thread Galan Rémi
Instead of removing a line to remove the commit, you can use the key
word drop (just like pick or edit). It has the same effect as
deleting the line (removing the commit) except that you keep a visual
trace of your actions, allowing a better control and reducing the
possibility of removing a commit by mistake.

Signed-off-by: Galan Rémi remi.galan-alfo...@ensimag.grenoble-inp.fr
---
 Documentation/git-rebase.txt  |  3 +++
 git-rebase--interactive.sh|  4 
 t/lib-rebase.sh   |  4 ++--
 t/t3404-rebase-interactive.sh | 11 +++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 1d01baa..3cd2ef2 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -514,6 +514,9 @@ rebasing.
 If you just want to edit the commit message for a commit, replace the
 command pick with the command reword.
 
+If you want to remove a commit, replace the command pick by the
+command drop.
+
 If you want to fold two or more commits into one, replace the command
 pick for the second and subsequent commits with squash or fixup.
 If the commits had different authors, the folded commit will be
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index dc3133f..cb749e8 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -152,6 +152,7 @@ Commands:
  s, squash = use commit, but meld into previous commit
  f, fixup = like squash, but discard this commit's log message
  x, exec = run command (the rest of the line) using shell
+ d, drop = remove commit
 
 These lines can be re-ordered; they are executed from top to bottom.
 
@@ -515,6 +516,9 @@ do_next () {
do_pick $sha1 $rest
record_in_rewritten $sha1
;;
+   drop|d)
+   mark_action_done
+   ;;
reword|r)
comment_for_reflog reword
 
diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh
index 6bd2522..fdbc900 100644
--- a/t/lib-rebase.sh
+++ b/t/lib-rebase.sh
@@ -14,7 +14,7 @@
 #   specified line.
 #
 #   cmd lineno -- add a line with the specified command
-#   (squash, fixup, edit, or reword) and the SHA1 taken
+#   (squash, fixup, edit, reword or drop) and the SHA1 taken
 #   from the specified line.
 #
 #   exec_cmd_with_args -- add an exec cmd with args line.
@@ -46,7 +46,7 @@ set_fake_editor () {
action=pick
for line in $FAKE_LINES; do
case $line in
-   squash|fixup|edit|reword)
+   squash|fixup|edit|reword|drop)
action=$line;;
exec*)
echo $line | sed 's/_/ /g'  $1;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index ac429a0..1bad068 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1102,4 +1102,15 @@ test_expect_success 'rebase -i commits that overwrite 
untracked files (no ff)' '
test $(git cat-file commit HEAD | sed -ne \$p) = I
 '
 
+test_expect_success 'drop' '
+   git checkout master 
+   test_when_finished git checkout master 
+   git checkout -b dropBranchTest master 
+   set_fake_editor 
+   FAKE_LINES=1 drop 2 3 drop 4 5 git rebase -i --root 
+   test E = $(git cat-file commit HEAD | sed -ne \$p) 
+   test C = $(git cat-file commit HEAD^ | sed -ne \$p) 
+   test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
+'
+
 test_done
-- 
2.4.1.174.g28bfe8e

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html