Adding uncommitted flag to support post staged but not commit changes
Review Request #6879 — Created Feb. 1, 2015 and discarded
Problem:
While the common workflow is to post committed changes, some people have workflows where they want to post changes that are uncommitted, and have to resort to generating a diff manually and posting it usingrbt post --diff-filename=
.This work would add an
--uncommitted
flag torbt post
that would generate diffs for uncommitted changes instead.Approach:
Adding can_diff_committed capability to all clients, and let git set that to True to support it.
This revision simulate the behavior of svn, where we specify the tip to be --rbtools-working-copy so that git client know to remove the revision range out of the git commands.
In addition, to support this flag, --update, --diff-filename, and --guess-fields can't coexists, so the error is thrown when the user specifies those commands along with --uncommitted.
In order to view staged but uncommitted files, we need to add --cached to the git diff command.
Write an extra unit test to check that the git post --uncommitted works.
Verify that it throws error when --uncommitted and other options like --diff-filename,
Description | From | Last Updated |
---|---|---|
Col: 28 E222 multiple spaces after operator |
reviewbot | |
Col: 80 E501 line too long (90 > 79 characters) |
reviewbot | |
Col: 43 E203 whitespace before ':' |
reviewbot | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Col: 37 E203 whitespace before ':' |
reviewbot | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (90 > 79 characters) |
reviewbot | |
Col: 80 E501 line too long (96 > 79 characters) |
reviewbot | |
Col: 77 E225 missing whitespace around operator |
reviewbot | |
Col: 80 E501 line too long (93 > 79 characters) |
reviewbot | |
Col: 60 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 62 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 80 E501 line too long (94 > 79 characters) |
reviewbot | |
Col: 46 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 48 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 46 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Col: 48 E251 unexpected spaces around keyword / parameter equals |
reviewbot | |
Comments should be full sentences with proper capitalization and punctuation. |
david | |
Given that we now do this in both the n_revs == 0 and n_revs >= 1 cases, perhaps we should … |
david | |
We should probably not show this warning if using this flag. |
david | |
Hmm. So I can see people wanting both the diff in the working copy (unstaged) and the diff in the … |
david | |
Please add this line back in. |
david | |
Please fix this comment. |
david | |
Add a blank line between these two. |
david | |
Leftover debugging print? |
david | |
"GitClient". Also this test name is pretty hard to read (perhaps "Testing GitClient uncommitted diff with staged files"?) Because nose … |
david | |
This error message is kind of hard to read. Maybe we can have separate errors for each of the conflicting … |
david | |
Col: 22 W601 .has_key() is deprecated, use 'in' |
reviewbot | |
We should default this to None rather than the empty string. |
david | |
Reading this through, I think we should keep the handling of the uncommitted flag in this conditional: if uncommitted is … |
david | |
We're still duplicating this code. If you make the above change, you can just have these lines run all the … |
david | |
Typo: "Otherise". Also, add a period at the end. |
david | |
Add a blank line between these two. |
david | |
Add a period at the end. |
david | |
Can we test the parse_revision_spec logic here? |
david | |
Can we test the parse_revision_spec logic here? |
david | |
Remove this line. |
david | |
Can we specify choices in here? |
david | |
Typo: an -> and. You also have an extra ) in the string. |
david | |
Typo: an -> and. You also have an extra ) in the string. |
david | |
Typo: an -> and. You also have an extra ) in the string. |
david | |
This should probably default to None. |
david | |
Col: 55 E231 missing whitespace after ',' |
reviewbot | |
Col: 80 E501 line too long (81 > 79 characters) |
reviewbot | |
Col: 55 E231 missing whitespace after ',' |
reviewbot | |
Do you mind sorting these in alphabetical order? |
david | |
Can you add blank lines around the blocks? We should also use del rather than .pop(). Please also use exact … |
david | |
This change shouldn't be necessary anymore because the uncommitted handling is a separate case. |
david | |
Remove this blank line? |
david | |
Col: 48 E127 continuation line over-indented for visual indent |
reviewbot | |
For the help, how about "Uploads a diff of the changes in either the working copy or index (Git only)." |
david | |
Why are these not allowed? |
david | |
Single quotes are preferred. |
chipx86 | |
Minor nit: This wraps kind of early. |
chipx86 | |
Can you flip this? Should be uncommitted == 'workingcopy' |
chipx86 | |
Same here. |
chipx86 | |
This should probably be given an error message indicating that uncommitted has an incorrect value? |
chipx86 | |
There's some important stuff in git_cmd we don't want to lose, like turning off quoted paths nad colors. |
chipx86 | |
Best to use tuples here, to avoid the overhead of a list. |
chipx86 | |
Best to use .append() here. |
chipx86 | |
That line shouldn't be indented. |
chipx86 | |
Missing period. |
chipx86 | |
Missing period. |
chipx86 | |
Summaries are limited to one line. No wrapping. |
chipx86 | |
No need for this line. It's implied. |
chipx86 | |
Text must be aligned. |
chipx86 | |
Maybe just check for uncommitted once, and then do the rest of the conditionals inside that if block. |
chipx86 | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
'UncommittedIncorrectValueError' imported but unused |
reviewbot | |
undefined name 'OptionsCheckError' |
reviewbot | |
Col: 80 E501 line too long (84 > 79 characters) |
reviewbot | |
Col: 32 E128 continuation line under-indented for visual indent |
reviewbot | |
Col: 13 E303 too many blank lines (2) |
reviewbot | |
Col: 80 E501 line too long (83 > 79 characters) |
reviewbot | |
This is short enough that you should be able to put the """s on the same line as the docstring … |
david | |
This comment isn't really useful (the entire function is figuring out tip/base/parent_base), and kind of confusing. I'd just get rid … |
david | |
Add a blank line between here. |
david | |
This comment isn't 100% accurate. Maybe say something about how we add the revision range to the diff command when … |
david | |
The second sentence here isn't good grammar. How about "This is because the update mechanism uses the commit message to … |
david | |
Please figure out why it's not supported and explain that here. You also have a typo ("exlude") |
david | |
This comment is very self-referential to the code, and doesn't really add a lot. How about: If the user passed … |
david | |
Similar to the comment above, this is kind of confusing. How about: If the user asked for a diff of … |
david | |
You should probably just use CommandError instead of this. |
brennie | |
Since this doesn't actually interface with Git, I would suggest renaming this to _create_file or _write_file. |
brennie | |
Maybe instead of the --uncommitted-type flag you could have a --staged flag that would work as follows: If --uncommitted flag … |
brennie | |
Why this change? |
brennie | |
Blank line between these. |
brennie | |
Blank line between these. |
brennie | |
Col: 80 E501 line too long (80 > 79 characters) |
reviewbot | |
I'm not sure we want to pass a string for this value. It's too easy to typo, and isn't very … |
chipx86 | |
I don't see anywhere where this particular exception is caught. The name is a bit awkward. How about InvalidUncommittedModeError, to … |
chipx86 | |
This should be: if tip not in (self.REVISION_WORKING_COPY, self.REVISION_STAGED): No need to store as a list and then convert to … |
chipx86 | |
this seems redundant self.assertEqual(result['parent_diff'], None) implies self.assertTrue('parent_diff' in result) same for the base_commit_id one |
TI tienv | |
"... in the index. Use ..." Note the period and "the". |
chipx86 | |
Comma should go immediately after the word it follows, within the same string. Also, should be "--staged to upload the … |
chipx86 | |
"... to the working copy." |
chipx86 | |
"and this option is specified, a diff of the staged changes will be uploaded. Otherwise, the changed in the working … |
chipx86 | |
This comment just reflects the code exactly, so it doesn't need to be here. |
chipx86 | |
No \n. |
chipx86 | |
Some grammatical fixes: "If the user has explicitly specified the --uncommitted option, then the --update option cannot be used." |
chipx86 | |
No \n. |
chipx86 | |
Some grammatical fixes: "If the user has explicitly specified the --uncommitted option, then the --exclude-patterns option cannot be used." The … |
chipx86 | |
"exclude-patterns", not "exclude_patterns". |
chipx86 | |
No \n. |
chipx86 | |
Col: 1 E302 expected 2 blank lines, found 1 |
reviewbot | |
Col: 54 E231 missing whitespace after ',' |
reviewbot | |
This comment needs to be updated to reflect the new flags. |
brennie | |
Can we rename file to filename in all these instances? file is overriding a Python builtin. |
brennie | |
Should --staged be shorthand for --staged --uncommitted ? |
brennie | |
Add another blank line here. |
david | |
This is useless (we just set result to be an empty dict above -- so there will never be a … |
david |
- Groups:
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
This looks like a pretty good start!
-
-
Given that we now do this in both the
n_revs == 0
andn_revs >= 1
cases, perhaps we should move it out to happen just before wereturn result
? -
-
Hmm. So I can see people wanting both the diff in the working copy (unstaged) and the diff in the index (staged). Perhaps we should make --uncommitted be able to take an optional argument?
Please also make sure that this comment is a full sentence with proper capitalization and punctuation.
-
-
-
-
-
"GitClient". Also this test name is pretty hard to read (perhaps "Testing GitClient uncommitted diff with staged files"?) Because nose will append an ellipsis, we don't put periods at the end of test case docstrings.
-
This error message is kind of hard to read. Maybe we can have separate errors for each of the conflicting options?
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
-
-
Reading this through, I think we should keep the handling of the
uncommitted
flag in this conditional:if uncommitted is not None: del result['commit_id'] result['base'] = self._rev_parse(self.get_head_ref())[0] if uncommitted == 'workingcopy': result['tip'] = self.REVISION_WORKING_COPY elif uncommitted == 'staged': result['tip'] = self.REVISION_STAGED else: assertion? elif n_revs == 0: ...
-
We're still duplicating this code. If you make the above change, you can just have these lines run all the time before
return result
-
-
-
-
-
-
-
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
-
-
- Groups:
-
-
-
Can you add blank lines around the blocks? We should also use
del
rather than.pop()
.Please also use exact comparisons rather than 'in' (which does a substring match, which is slower and imprecise).
if 'commit_id' in result: del result['commit_id'] result['base'] = self._rev_parse(self.get_head_red())[0] if uncommitted == 'workingcopy': ...
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/clients/__init__.py rbtools/utils/review_request.py rbtools/clients/git.py
-
So my main concern is that passing
--uncommitted=staged
or--uncommitted=workingcopy
is a lot to type every time, and perhaps is confusing to people without reading docs. How about instead having--uncommitted
as a boolean flag, and then--uncommitted-type=[staged|workingcopy]
, with the default of "staged"?The pro being that, in the common case of posting changes scheduled for commit but not yet committed, it's quicker to type and post. Also,
--uncommitted-type
could be a configurable option, so that the user can specify which mode they prefer to work with in.reviewboardrc
without triggering uncommitted reviews for every change.Downside being that, in the uncommon case, it's more to type, but I think most people just want to post changes scheduled for commit without actually committing. However, with the option, that shouldn't be as big a deal.
-
-
-
-
-
-
There's some important stuff in
git_cmd
we don't want to lose, like turning off quoted paths nad colors. -
-
-
-
-
-
-
-
-
Maybe just check for
uncommitted
once, and then do the rest of the conditionals inside thatif
block.
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
-
-
-
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
-
This is short enough that you should be able to put the """s on the same line as the docstring itself. There should also be a period at the end.
-
This comment isn't really useful (the entire function is figuring out tip/base/parent_base), and kind of confusing. I'd just get rid of it.
-
-
This comment isn't 100% accurate. Maybe say something about how we add the revision range to the diff command when posting committed changes?
-
The second sentence here isn't good grammar. How about "This is because the update mechanism uses the commit message to find the review request, and uncommitted changes don't have a commit message yet."
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
Your description should be updated to talk about --uncommitted-type. You also have a typo ("Mercurila").
-
This comment is very self-referential to the code, and doesn't really add a lot. How about:
If the user passed --uncommitted-type=staged, add --cached to the 'git diff' command.
-
Similar to the comment above, this is kind of confusing. How about:
If the user asked for a diff of the working copy, we do not pass any revisions to the 'git diff' command. Otherwise, add the revision range.
-
Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
-
-
Since this doesn't actually interface with Git, I would suggest renaming this to
_create_file
or_write_file
. -
Maybe instead of the
--uncommitted-type
flag you could have a--staged
flag that would work as follows:If
--uncommitted
flag is specified and--staged
isn't specified it will use the working copy changes; otherwise if--staged
is specified, it will use the staged changes.This seems like a clearer way to go about it (and will be easier to describe).
-
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
- Description:
-
Problem:
While the common workflow is to post committed changes, some people have workflows where they want to post changes that are uncommitted, and have to resort to generating a diff manually and posting it using rbt post --diff-filename=
.This work would add an
--uncommitted
flag torbt post
that would generate diffs for uncommitted changes instead.Approach:
Adding can_diff_committed capability to all clients, and let git set that to True to support it. This revision simulate the behavior of svn, where we specify the tip to be --rbtools-working-copy so that git client know to remove the revision range out of the git commands. In addition, to support this flag, --update, --diff-filename, and --guess-fields can't coexists, so the error is thrown when the user specifies those commands along with --uncommitted. In order to view staged but uncommitted files, we need to add --cached to the git diff command. - - To Do:
- - Support Merculia - - Support exclude pattern in which the user can exclude the staged files to be posted. Currently, it will throw un error if --excluded-pattern is specified along with --uncommitted.
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
-
I'm not sure we want to pass a string for this value. It's too easy to typo, and isn't very obvious to the caller.
What I'd suggest instead is a class that works as an enum for storing the possible values. For instance:
class UncommittedMode(object): WORKING_COPY = 1 STAGED = 2
Then it's easy to check.
-
I don't see anywhere where this particular exception is caught.
The name is a bit awkward. How about
InvalidUncommittedModeError
, to match the suggested class name? -
This should be:
if tip not in (self.REVISION_WORKING_COPY, self.REVISION_STAGED):
No need to store as a list and then convert to a tuple.
-
-
Comma should go immediately after the word it follows, within the same string.
Also, should be "--staged to upload the staged changes."
-
-
"and this option is specified, a diff of the staged changes will be uploaded. Otherwise, the changed in the working copy are uploaded."
-
-
-
Some grammatical fixes:
"If the user has explicitly specified the --uncommitted option, then the --update option cannot be used."
-
-
Some grammatical fixes:
"If the user has explicitly specified the --uncommitted option, then the --exclude-patterns option cannot be used."
The note about diff-tree is a Git-specific implementation detail, so we shouldn't mention it here.
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
-
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py
-
Tool: Pyflakes Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py Tool: PEP8 Style Checker Processed Files: rbtools/clients/tests.py rbtools/commands/post.py rbtools/utils/review_request.py rbtools/clients/errors.py rbtools/clients/git.py