Apply Staged Changes to New Repo - windows

What mistake am I making in the steps I'm following?
I've edited files in repo Alpha on my local box. I then realized I wanted those changes in a different repo Bravo that is also on my local box. I tried this:
c:/repos/alpha/>git diff --cached > mypatch.txt
I then copy the patch file to the other repo location and type this:
c:/repos/bravo/>git apply mypatch.txt
If the shell I used for the diff and apply was powershell or "Git CMD", then the second command makes the error:
fatal: unrecognized input
If instead I use the "Git Bash" shell to execute the two commands, then I get a different error:
5109e.patch:19: trailing whitespace.
IL.DataUsageGB,
warning: 1 line adds whitespace errors.
I then try to apply the changes more carefully with the following command:
$ git apply --reject --whitespace=fix mypatch.txt
From this I get a dump of numerous errors. Example:
error: while searching for:
);
GO
-- Anchor table ------------------------------------------------------------
-------------------------------------------
-- IL_InvoiceLine table (with 33 attributes)
----------------------------------------------------------------------------
-------------------------------------------
IF Object_ID('dbo.IL_InvoiceLine', 'U') IS NULL
CREATE TABLE [dbo].[IL_InvoiceLine] (
error: patch failed: scripts/bi/sql/Unified_ODS_Schema.sql:302
The branch in repo Alpha and the corresponding branch in repo Bravo both come from the same origin and both have a git status that report "up to date" with the upstream. In other words, the branches are identical except for the staged changes that exist on Alpha. I am expressly avoiding a push/pull with the origin.
Suggestions?

TL;DR
There's nothing wrong, and you can completely ignore the warning. You don't need --reject or --whitespace=fix, but if you do want to use the latter, use it without the former.
Longer
If the shell I used for the diff and apply was powershell ...
This winds up writing the output as Unicode (through some mechanism I cannot describe properly since I don't "do" Windows). You'd have to filter that back to UTF-8 or ASCII to get it to apply.
If instead I use the "Git Bash" shell to execute the two commands, then I get a different error:
5109e.patch:19: trailing whitespace.
IL.DataUsageGB,
warning: 1 line adds whitespace errors.
That's not really an error, that's a warning. It means that your original patch adds a blank before an end-of-line. By default, git apply calls this an "error" but it really means "warning". It's meant to alert you to the fact that there's an invisible character on the line(s) in question, which you may not have intended. (Or maybe you did! For instance, in some Markdown formats, ending a line with two blanks inserts a paragraph break. See aslo Git ignore trailing whitespace in markdown files only.)
What constitutes a "whitespace error" (which really should be "whitespace annoyance" or "whitespace warning" or "whitespace glitch" everywhere, rather than "error") is configurable. By default git diff will highlight such whitespace glitches. While I cannot quite show it here, imagine the - line is in red and the + line is in green and that <space> represents a trailing blank:
- blah blah
+ blah foo blah<space>
This space would be highlighted in red, to make it stand out as a "whitespace error" (which I would call a whitespace glitch or annoyance or warning, but as long as we are using Git we should understand what the phrase "whitespace error" means here).
With --whitespace=fix, git apply will find the things it considers to be whitespace errors and determine whether it can fix them automatically by:
stripping trailing whitespace
removing some space-before-tab spaces
fussing with CRLF vs LF-only
If it can fix them, it will. This includes applying the patch even if the context does not quite match up but can be made to do so by this kind of fussing, so it's more than just "removing trailing whitespace in the added lines".

Related

Colorizing custom gitmessage file in vim

I have a custom .gitmessage. It is defined in the git config. I've added a ~/.vim/after/ftplugin/gitcommit.vim to redefine a couple of things in the plugin (in support of Conventional Commits), e.g., textwidth.
My .gitmessage looks something like this:
#subject-|---------|---------|---------|---------|---------|---------|---------|---------|-------->|
# Commit messages should follow the Conventional Commits Specification
# <type>(<optional scope>): <imperative subject>
# empty separator line
# <optional body>
# empty separator line
# <optional footer>
#
# API relevant changes || perf commits improve performance
# feat commits add a new feature || revert commit, well, revert a previous
# fix commits fix a bug || commit
...
...
where I provide an ASCII "ruler" for 100 chars (though the VIM filetype plugin config autowraps to the textwidth per my customization, &tc.
However, I would like to colorize the conventional commit sample and the type keywords, e.g., feat, fix, perf, &tc.
I've tried most of standard ASCII escape codes in the .gitmessage, e.g., \\e[1;30m, ^[1;30m (Ctrl-V, esc), and \033[1;30m. Alas, they all just get dumped to the vim editor—it makes sense that vim would make sure that these codes are editable—but gitcommit.vim does colorize the diff in git commit --all --verbose...
This appears to be, maybe, a function of shellescape (see :h shellescape in vim). I see this used in some of the filetype plugins, but I'm not a plugin hacker.
Any pointers?
Vim doesn't care about your escape codes.
A quick and dirty method would be to use :help :match or :help matchadd() in your custom ftplugin:
But the real solution is to create your own syntax script, following the instructions under :help usr_44. See $VIMRUNTIME/syntax/gitcommit.vim for a start.

Undoing whitespace changes in Perforce

Is there an easy way to undo whitespace changes in Perforce?
I have a .vimrc script that trims trailing whitespace on save, but in certain branches of code, the owner of said code doesn't want whitespace diffs.
I typically have to make a copy of my file, revert the original file, then manually integrate the non-whitespace changes I made.
Is there a simple command in Perforce (or other UNIX tools) that can do this automatically?
p4 resolve as a -dw option for ignoring whitespace, but I don't know how I'd make the file resolvable in the first place.
Assuming in this example your revision was #4 and your file is foo:
p4 sync file#3
p4 edit file
p4 sync file
p4 resolve -dw
You can also do this across many files at the changelist level; sync back to previous change, open for edit, sync to your change, resolve with whatever options.
I think that when you do resolve -dw it keeps the "yours" version of whitespace-only diffs, which in this case will be file#3 which is what you want.
Note that if you have individual lines with both whitespace and non-whitespace diffs you'll most likely get the whitespace diff along with the rest of the line since Perforce's merge operates per-line. If all else fails, find another merge tool that'll do the specific thing you want to do with the whitespace, set P4MERGE to that, and do p4 resolve;m.
If your changes are still pending I think you can do something like:
p4 print -o depotRev file
p4 merge3 -dw depotRev file depotRev > merged
rm depotRev
then do:
diff file merged
to make sure the diffs look right before replacing your file with merged.

Commits to GitHub repo showing large quantities of unintentional changes

I've been commiting/pushing to a public repo and finding that one commit where I may have changed less than 100 lines results in a commit with 1000 changes.
For example, I may change several lines in a method in AppDelegate.
The resulting problem is something that looks like that following:
To better showoff what whitespace issues might be occurring here is another area of unwanted commitage:
You have formatted the code and now git treats your whitecaps as changes.
Set this flag to ignore any white spaces changes
core.whitespace
Git comes preset to detect and fix some whitespace issues.
It can look for six primary whitespace issues – three are enabled by default and can be turned off, and three are disabled by default but can be activated.
git config --global core.whitespace <...>
core.whitespace
core.whitespace
A comma separated list of common whitespace problems to notice. git diff will use color.diff.whitespace to highlight them, and git apply --whitespace=error will consider them as errors.
You can prefix - to disable any of them (e.g. -trailing-space):
blank-at-eol
treats trailing whitespaces at the end of the line as an error (enabled by default).
space-before-tab
treats a space character that appears immediately before a tab character in the initial indent part of the line as an error (enabled by default).
indent-with-non-tab
treats a line that is indented with space characters instead of the equivalent tabs as an error (not enabled by default).
tab-in-indent
treats a tab character in the initial indent part of the line as an error (not enabled by default).
blank-at-eof
treats blank lines added at the end of file as an error (enabled by default).
trailing-space is a short-hand to cover both blank-at-eol and blank-at-eof.
cr-at-eol treats
a carriage-return at the end of line as part of the line terminator, i.e. with it, trailing-space does not trigger if the character before such a carriage-return is not a whitespace (not enabled by default).
tabwidth=
tells how many character positions a tab occupies; this is relevant for indent-with-non-tab and when Git fixes tab-in-indent errors. The default tab width is 8. Allowed values are 1 to 63

How can I debug .gitignore file handling?

I’m having lots of trouble convincing git to ignore files in my project.
Basically, sometimes it works, sometimes it just seems to ignore the .gitignore file for no obvious reason. (By “seems” I mean that there are patterns in it that look as if they should exclude something, but that something is not excluded.)
There’s a 'git check-ignore' command, but it only says which pattern matched a file. But I can’t find any option to make it say which patterns it’s found and where, nor why those patterns do not match a file.
Is there a way to do this kind of debugging?
P.S. There is a single issue which I did find, and I’m mentioning it here in case it helps others:
I was adding patterns using “echo pattern >> .gitignore”, which at least on my system results in spaces at the of the line (i.e., everything between “echo” and “>>” is echoed in the file, except for the first space character after “echo”).
Git does not trim those spaces when matching patterns, so for the command above it wouldn’t match a file named “pattern” but it would match “pattern{space}”.
I think most of my issues stem from this. Those extra spaces are hard to notice, so I’d still like a debug command that makes sure I notice them, if there is one.
Edit #1:
Yes, I did try -v. For example:
> mkdir test
> touch test/file.txt
> echo test >> .gitignore
> git check-ignore -v test/file.txt
(nothing is printed)
> echo test>> .gitignore
> git check-ignore -v test/cuc.txt
.gitignore:8:test test/cuc.txt
Note the extra space in the first echo line, which makes it enter “test[space]” as a pattern. As I mentioned, “check-ignore” tells you what matched, but it doesn’t tell you what didn’t nor why.

SVN Mac - commiting files with an "#" in their name

I am using the default SVN client on Mac that you use with the terminal. The problem is I want to commit three files that contains an "#" in them, and only those files. However it does not seem to work, SVN cannot read the # for some reason. I did it like this:
svn commit Assets/Monkey#Prime.pck -m "test"
What is the correct syntax?
That's the syntax for peg revisions. This is the workaround suggested in the manual:
The perceptive reader is probably wondering at this point whether the
peg revision syntax causes problems for working copy paths or URLs
that actually have at signs in them. After all, how does svn know
whether news#11 is the name of a directory in my tree or just a syntax
for “revision 11 of news”? Thankfully, while svn will always assume
the latter, there is a trivial workaround. You need only append an at
sign to the end of the path, such as news#11#. svn cares only about
the last at sign in the argument, and it is not considered illegal to
omit a literal peg revision specifier after that at sign. This
workaround even applies to paths that end in an at sign—you would use
filename## to talk about a file named filename#.
Ugly, isn't it? :)

Resources