{"thread":{"id":"35360","subject":"[BUG] Rebase options '--whitespace=fix' and '--keep-empty' are incompatible","startedAt":"2013-11-20T00:05:23Z","lastAt":"2013-11-20T00:05:23Z","messageCount":1,"participants":["Nathan Collins"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"230819","messageId":"CAO8RVvc8iO-VcR+e3dvPtfV8DDZN+UVbFX5tCxyr65FbeDxDbw@mail.gmail.com","threadId":"35360","inReplyTo":null,"subject":"[BUG] Rebase options '--whitespace=fix' and '--keep-empty' are incompatible","fromName":"Nathan Collins","fromEmail":"nathan.collins@gmail.com","sentAt":"2013-11-20T00:05:23Z","receivedAt":"2013-11-20T00:05:23Z","isPatch":false,"sender":{"key":"nathan.collins@gmail.com","avatar":"https://gravatar.com/avatar/ecec917e18a103ea8fa2cddf99d766caa0f52d0aef155ba715a9ada837b5c1d2?d=mp&s=160"},"body":"Bug\n===\n\nThe command\n\n  git rebase --whitespace=fix --keep-empty <commit>\n\ndoes not fix whitespace in the rebased commits.\n\nExample\n=======\n\nSet up a repo with a whitespace error commit and an empty commit:\n\n  git init rebase-bug.git\n  cd rebase-bug.git\n  touch foo\n  git add foo\n  touch foo\n  git add foo\n  git commit -m \"Empty foo\"\n  echo \"xxx   \" > foo\n  git add foo\n  git commit -m \"Trailing whitespace foo\"\n  git commit --allow-empty -m \"Empty commit\n\nNow we have the following commits (adding '$' at EOL to make trailing\nwhitespace clear):\n\n  git log --oneline --patch | sed -re 's/$/$/'\n\n  d383707 Empty commit$\n  4b71cd0 Trailing whitespace foo$\n  diff --git foo foo$\n  index e69de29..272a831 100644$\n  --- foo$\n  +++ foo$\n  @@ -0,0 +1 @@$\n  +xxx   $\n  26d51d6 Empty foo$\n  diff --git foo foo$\n  new file mode 100644$\n  index 0000000..e69de29$\n\nMake a backup:\n\n  cp -r ../rebase-bug.git{,.backup}\n\nWe can now fix the whitespace with 'git rebase --whitespace=fix', but\nthis drops the empty commit:\n\n  git rebase --whitespace=fix HEAD~2\n\n  Current branch master is up to date, rebase forced.\n  First, rewinding head to replay your work on top of it...\n  Applying: Trailing whitespace foo\n\n  git log --oneline --patch | sed -re 's/$/$/'\n\n  2f6f66d Trailing whitespace foo$\n  diff --git foo foo$\n  index e69de29..d6459e0 100644$\n  --- foo$\n  +++ foo$\n  @@ -0,0 +1 @@$\n  +xxx$\n  26d51d6 Empty foo$\n  diff --git foo foo$\n  new file mode 100644$\n  index 0000000..e69de29$\n\nIf we add '--keep-empty', then we keep the empty commit, but the\nwhitespace is not fixed:\n\n  cd ../rebase-bug.git.backup\n  git rebase --whitespace=fix --keep-empty HEAD~2\n\n  Current branch master is up to date, rebase forced.\n  First, rewinding head to replay your work on top of it...\n  [detached HEAD a48c4c8] Trailing whitespace foo\n   1 file changed, 1 insertion(+)\n  [detached HEAD 8a15ca4] Empty commit\n\n  git log --oneline --patch | sed -re 's/$/$/'\n\n  f852c53 Empty commit$\n  f8c3626 Trailing whitespace foo$\n  diff --git foo foo$\n  index e69de29..272a831 100644$\n  --- foo$\n  +++ foo$\n  @@ -0,0 +1 @@$\n  +xxx   $\n  26d51d6 Empty foo$\n  diff --git foo foo$\n  new file mode 100644$\n  index 0000000..e69de29$\n\nGit version\n===========\n\nI'm using git version 1.8.2.3.\n\nMotivation\n==========\n\nhttp://stackoverflow.com/a/15398512/470844\n\nI wanted a Git alias to remove whitespace errors from the index and\ntree. I tried this:\n\n  fixws-global-tree-and-index = !\"\\\n    git commit --allow-empty -m FIXWS_SAVE_INDEX && \\\n    git add -u :/ && \\\n    git commit --allow-empty -m FIXWS_SAVE_TREE && \\\n    git rebase --whitespace=fix --keep-empty HEAD~2 && \\\n    git reset HEAD~ && \\\n    git reset --soft HEAD~\"\n\nBut, it does not work, because of the bug illustrated above.  So,\ninstead, I have this:\n\n  fixws-global-tree-and-index = !\"\\\n    if (! git diff-files --quiet .) && \\\n       (! git diff-index --quiet --cached HEAD) ; then \\\n      git commit -m FIXWS_SAVE_INDEX && \\\n      git add -u :/ && \\\n      git commit -m FIXWS_SAVE_TREE && \\\n      git rebase --whitespace=fix HEAD~2 && \\\n      git reset HEAD~ && \\\n      git reset --soft HEAD~ ; \\\n    elif (! git diff-files --quiet .) ; then \\\n      git add -u :/ && \\\n      git commit -m FIXWS_SAVE_TREE && \\\n      git rebase --whitespace=fix HEAD~ && \\\n      git reset HEAD~ ; \\\n    elif (! git diff-index --quiet --cached HEAD) ; then \\\n      git commit -m FIXWS_SAVE_INDEX && \\\n      git rebase --whitespace=fix HEAD~ && \\\n      git reset --soft HEAD~ ; \\\n    fi\"\n\nI.e., I calculate which commits are non-empty and only make those\ncommits.\n\nCheers,\n\n-nathan\n"}]}