Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'jk/rebase-i-comment-char'

Finishing touches to the earlier core.commentchar topic to cover
"rebase -i" as well.

* jk/rebase-i-comment-char:
  rebase -i: respect core.commentchar
  • Loading branch information...
commit 00abd715ab0a2cd69f9d27ea15c5440002f970b8 2 parents d04f998 + 180bad3
Junio C Hamano authored February 17, 2013
84  git-rebase--interactive.sh
@@ -80,6 +80,9 @@ rewritten_pending="$state_dir"/rewritten-pending
80 80
 GIT_CHERRY_PICK_HELP="$resolvemsg"
81 81
 export GIT_CHERRY_PICK_HELP
82 82
 
  83
+comment_char=$(git config --get core.commentchar 2>/dev/null | cut -c1)
  84
+: ${comment_char:=#}
  85
+
83 86
 warn () {
84 87
 	printf '%s\n' "$*" >&2
85 88
 }
@@ -105,8 +108,8 @@ mark_action_done () {
105 108
 	sed -e 1q < "$todo" >> "$done"
106 109
 	sed -e 1d < "$todo" >> "$todo".new
107 110
 	mv -f "$todo".new "$todo"
108  
-	new_count=$(sane_grep -c '^[^#]' < "$done")
109  
-	total=$(($new_count+$(sane_grep -c '^[^#]' < "$todo")))
  111
+	new_count=$(git stripspace --strip-comments <"$done" | wc -l)
  112
+	total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
110 113
 	if test "$last_count" != "$new_count"
111 114
 	then
112 115
 		last_count=$new_count
@@ -116,19 +119,19 @@ mark_action_done () {
116 119
 }
117 120
 
118 121
 append_todo_help () {
119  
-	cat >> "$todo" << EOF
120  
-#
121  
-# Commands:
122  
-#  p, pick = use commit
123  
-#  r, reword = use commit, but edit the commit message
124  
-#  e, edit = use commit, but stop for amending
125  
-#  s, squash = use commit, but meld into previous commit
126  
-#  f, fixup = like "squash", but discard this commit's log message
127  
-#  x, exec = run command (the rest of the line) using shell
128  
-#
129  
-# These lines can be re-ordered; they are executed from top to bottom.
130  
-#
131  
-# If you remove a line here THAT COMMIT WILL BE LOST.
  122
+	git stripspace --comment-lines >>"$todo" <<\EOF
  123
+
  124
+Commands:
  125
+ p, pick = use commit
  126
+ r, reword = use commit, but edit the commit message
  127
+ e, edit = use commit, but stop for amending
  128
+ s, squash = use commit, but meld into previous commit
  129
+ f, fixup = like "squash", but discard this commit's log message
  130
+ x, exec = run command (the rest of the line) using shell
  131
+
  132
+These lines can be re-ordered; they are executed from top to bottom.
  133
+
  134
+If you remove a line here THAT COMMIT WILL BE LOST.
132 135
 EOF
133 136
 }
134 137
 
@@ -179,7 +182,7 @@ die_abort () {
179 182
 }
180 183
 
181 184
 has_action () {
182  
-	sane_grep '^[^#]' "$1" >/dev/null
  185
+	test -n "$(git stripspace --strip-comments <"$1")"
183 186
 }
184 187
 
185 188
 is_empty_commit() {
@@ -363,10 +366,10 @@ update_squash_messages () {
363 366
 	if test -f "$squash_msg"; then
364 367
 		mv "$squash_msg" "$squash_msg".bak || exit
365 368
 		count=$(($(sed -n \
366  
-			-e "1s/^# This is a combination of \(.*\) commits\./\1/p" \
  369
+			-e "1s/^. This is a combination of \(.*\) commits\./\1/p" \
367 370
 			-e "q" < "$squash_msg".bak)+1))
368 371
 		{
369  
-			echo "# This is a combination of $count commits."
  372
+			printf '%s\n' "$comment_char This is a combination of $count commits."
370 373
 			sed -e 1d -e '2,/^./{
371 374
 				/^$/d
372 375
 			}' <"$squash_msg".bak
@@ -375,8 +378,8 @@ update_squash_messages () {
375 378
 		commit_message HEAD > "$fixup_msg" || die "Cannot write $fixup_msg"
376 379
 		count=2
377 380
 		{
378  
-			echo "# This is a combination of 2 commits."
379  
-			echo "# The first commit's message is:"
  381
+			printf '%s\n' "$comment_char This is a combination of 2 commits."
  382
+			printf '%s\n' "$comment_char The first commit's message is:"
380 383
 			echo
381 384
 			cat "$fixup_msg"
382 385
 		} >"$squash_msg"
@@ -385,21 +388,22 @@ update_squash_messages () {
385 388
 	squash)
386 389
 		rm -f "$fixup_msg"
387 390
 		echo
388  
-		echo "# This is the $(nth_string $count) commit message:"
  391
+		printf '%s\n' "$comment_char This is the $(nth_string $count) commit message:"
389 392
 		echo
390 393
 		commit_message $2
391 394
 		;;
392 395
 	fixup)
393 396
 		echo
394  
-		echo "# The $(nth_string $count) commit message will be skipped:"
  397
+		printf '%s\n' "$comment_char The $(nth_string $count) commit message will be skipped:"
395 398
 		echo
396  
-		commit_message $2 | sed -e 's/^/#	/'
  399
+		# Change the space after the comment character to TAB:
  400
+		commit_message $2 | git stripspace --comment-lines | sed -e 's/ /	/'
397 401
 		;;
398 402
 	esac >>"$squash_msg"
399 403
 }
400 404
 
401 405
 peek_next_command () {
402  
-	sed -n -e "/^#/d" -e '/^$/d' -e "s/ .*//p" -e "q" < "$todo"
  406
+	git stripspace --strip-comments <"$todo" | sed -n -e 's/ .*//p' -e q
403 407
 }
404 408
 
405 409
 # A squash/fixup has failed.  Prepare the long version of the squash
@@ -464,7 +468,7 @@ do_next () {
464 468
 	rm -f "$msg" "$author_script" "$amend" || exit
465 469
 	read -r command sha1 rest < "$todo"
466 470
 	case "$command" in
467  
-	'#'*|''|noop)
  471
+	"$comment_char"*|''|noop)
468 472
 		mark_action_done
469 473
 		;;
470 474
 	pick|p)
@@ -803,15 +807,15 @@ skip)
803 807
 	do_rest
804 808
 	;;
805 809
 edit-todo)
806  
-	sed -e '/^#/d' < "$todo" > "$todo".new
  810
+	git stripspace --strip-comments <"$todo" >"$todo".new
807 811
 	mv -f "$todo".new "$todo"
808 812
 	append_todo_help
809  
-	cat >> "$todo" << EOF
810  
-#
811  
-# You are editing the todo file of an ongoing interactive rebase.
812  
-# To continue rebase after editing, run:
813  
-#     git rebase --continue
814  
-#
  813
+	git stripspace --comment-lines >>"$todo" <<\EOF
  814
+
  815
+You are editing the todo file of an ongoing interactive rebase.
  816
+To continue rebase after editing, run:
  817
+    git rebase --continue
  818
+
815 819
 EOF
816 820
 
817 821
 	git_sequence_editor "$todo" ||
@@ -881,7 +885,7 @@ do
881 885
 
882 886
 	if test -z "$keep_empty" && is_empty_commit $shortsha1 && ! is_merge_commit $shortsha1
883 887
 	then
884  
-		comment_out="# "
  888
+		comment_out="$comment_char "
885 889
 	else
886 890
 		comment_out=
887 891
 	fi
@@ -942,20 +946,20 @@ test -s "$todo" || echo noop >> "$todo"
942 946
 test -n "$autosquash" && rearrange_squash "$todo"
943 947
 test -n "$cmd" && add_exec_commands "$todo"
944 948
 
945  
-cat >> "$todo" << EOF
  949
+cat >>"$todo" <<EOF
946 950
 
947  
-# Rebase $shortrevisions onto $shortonto
  951
+$comment_char Rebase $shortrevisions onto $shortonto
948 952
 EOF
949 953
 append_todo_help
950  
-cat >> "$todo" << EOF
951  
-#
952  
-# However, if you remove everything, the rebase will be aborted.
953  
-#
  954
+git stripspace --comment-lines >>"$todo" <<\EOF
  955
+
  956
+However, if you remove everything, the rebase will be aborted.
  957
+
954 958
 EOF
955 959
 
956 960
 if test -z "$keep_empty"
957 961
 then
958  
-	echo "# Note that empty commits are commented out" >>"$todo"
  962
+	printf '%s\n' "$comment_char Note that empty commits are commented out" >>"$todo"
959 963
 fi
960 964
 
961 965
 
14  t/t3404-rebase-interactive.sh
@@ -934,4 +934,18 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
934 934
 	test L = $(git cat-file commit HEAD | sed -ne \$p)
935 935
 '
936 936
 
  937
+test_expect_success 'rebase -i respects core.commentchar' '
  938
+	git reset --hard &&
  939
+	git checkout E^0 &&
  940
+	git config core.commentchar "\\" &&
  941
+	test_when_finished "git config --unset core.commentchar" &&
  942
+	write_script remove-all-but-first.sh <<-\EOF &&
  943
+	sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
  944
+	mv "$1.tmp" "$1"
  945
+	EOF
  946
+	test_set_editor "$(pwd)/remove-all-but-first.sh" &&
  947
+	git rebase -i B &&
  948
+	test B = $(git cat-file commit HEAD^ | sed -ne \$p)
  949
+'
  950
+
937 951
 test_done

0 notes on commit 00abd71

Please sign in to comment.
Something went wrong with that request. Please try again.