-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
worktree: teach add
to accept --reason <string> with --lock
#992
Conversation
Welcome to GitGitGadgetHi @SRManz, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that your Pull Request has a good description, as it will be used as cover letter. Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel
Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):
To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
There is an issue in commit 6c08695: |
@forivall Could you /allow me, please? Thanks. |
/preview |
Error: User SRManz is not permitted to use GitGitGadget |
/allow |
User SRManz is now allowed to use GitGitGadget. WARNING: SRManz has no public email address set on GitHub |
/preview |
Error: Could not determine full name of SRManz |
/preview |
Error: Could not determine public email of SRManz |
/submit |
Submitted as pull.992.git.1625550451038.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, Eric Sunshine wrote (reply to this):
|
User |
On the Git mailing list, Junio C Hamano wrote (reply to this):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):
Eric Sunshine <sunshine@sunshineco.com> writes: >> --reason <string>:: >> + With `lock` or with `add --lock`, an explanation why the working tree is locked. > > I realize that you're mimicking the interface of `git worktree lock` > which accepts an optional `--reason`, but I'm wondering if the > user-experience might be improved by instead allowing `--lock` to > accept the reason as an optional argument. For instance: > > git worktree add --lock='just because' ... Thanks for thinking aloud, but I'd prefer the interface as posted, simply because there is one less thing for users to remember. The justification to lock is given with the --reason=<why> argument no matter how you acquire the lock on a worktree.
I had considered something like what Eric suggested, but opted to keep --reason "why"
for the reason Junio gave.
diff --git a/builtin/worktree.c b/builtin/worktree.c
@@ -31,6 +31,7 @@ struct add_opts {
int checkout;
int keep_locked;
const char *lock_reason;
};
Whether or not we do go with the approach of allowing
--lock
to take
the reason as an optional argument, we don't really need two structure
members here. Instead, we can repurposekeep_locked
as aconst char *
which is NULL if--lock
was not specified, otherwise non-NULL.Makes sense.
To me, that would create ambiguity. --lock
with no --reason
would have a NULL string, which would be the same as if --lock
weren't given at all. Am I missing something?
However, in this case, it should probably just be a simple
else if
:if (!opts->keep_locked) write_file(sb.buf, "initializing"); else if (opts->lock_reason) write_file(sb.buf, "%s", opts->lock_reason); else write_file(sb.buf, _("added with --lock"));
Excellent.
Wow! What was I thinking! Note the review item I created regarding my placing _()
around "added with --lock". Should I do a separate commit?
Thanks.
My apologies if I'm not following the conventions for comments on pull requests. Lots to learn...
Accidentally clicked Close with comment button. |
This branch is now known as |
This patch series was integrated into seen via git@5eb1070. |
There was a status update in the "New Topics" section about the branch "git worktree add --lock" learned to record why the worktree is locked with a custom message. Expecting a reroll. |
This patch series was integrated into seen via git@069e085. |
This patch series was integrated into seen via git@731f3c7. |
@SRManz if you want to send a v2, please |
/submit |
Submitted as pull.992.v3.git.1625963240.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
This patch series was integrated into seen via git@dcb1c1e. |
@@ -9,7 +9,7 @@ git-worktree - Manage multiple working trees | |||
SYNOPSIS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Eric Sunshine wrote (reply to this):
On Sat, Jul 10, 2021 at 8:27 PM Stephen Manz via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> The default reason stored in the lock file, "added with --lock",
> is unlikely to be what the user would have given in a separate
> `git worktree lock` command. Allowing `--reason` to be specified
> along with `--lock` when adding a working tree gives the user control
> over the reason for locking without needing a second command.
>
> Signed-off-by: Stephen Manz <smanz@alum.mit.edu>
> ---
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> @@ -302,10 +302,10 @@ static int add_worktree(const char *path, const char *refname,
> strbuf_addf(&sb, "%s/locked", sb_repo.buf);
> - if (!opts->keep_locked)
> - write_file(sb.buf, _("initializing"));
> + if (opts->keep_locked)
> + write_file(sb.buf, "%s", opts->keep_locked);
> else
> - write_file(sb.buf, _("added with --lock"));
> + write_file(sb.buf, _("initializing"));
Changing the condition around to handle the positive case first makes
the diff noisier, but the resulting code is a bit easier to reason
about. Okay.
> @@ -500,6 +504,13 @@ static int add(int ac, const char **av, const char *prefix)
> + if (lock_reason && !keep_locked)
> + die(_("--reason requires --lock"));
> + if (lock_reason)
> + opts.keep_locked = lock_reason;
> + else if (keep_locked)
> + opts.keep_locked = _("added with --lock");
The benefit of relocating the "added with --lock" literal from
add_worktree() to add() wasn't immediately obvious, aside from making
the `if` statement in add_worktree() a bit less complex. But I managed
to convince myself that the relocation makes sense since add() knows
about the `--lock` option, whereas add_worktree() is merely a consumer
of `add_opts` without specific knowledge of how the fields in that
structure get set. Okay.
> diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
> @@ -72,6 +72,19 @@ test_expect_success '"add" worktree with lock' '
> +test_expect_success '"add" worktree with lock and reason' '
> + git worktree add --detach --lock --reason "why not" here-with-lock-reason main &&
> + test_when_finished "git worktree unlock here-with-lock-reason || :" &&
> + test -f .git/worktrees/here-with-lock-reason/locked &&
> + echo why not >expect &&
> + test_cmp expect .git/worktrees/here-with-lock-reason/locked
> +'
Two very minor comments:
First, considering that test_cmp() will fail anyhow if the `locked`
file is missing, the `test -f` is redundant.
Second, the lack of quotes around "why not" in the `echo ... >expect`
statement gives me a moment's pause since it relies upon the fact that
`echo` will insert exactly one space between the "why" and "not"
arguments (which happens to match the single space in the
double-quoted argument to `--reason`). For clarity and that extra bit
of robustness, I'd probably have used a single double-quoted string
argument with `echo`.
Anyhow, those are extremely minor comments, probably not worth a
re-roll but perhaps something to keep in mind if you do re-roll for
some other more important reason.
On the Git mailing list, Eric Sunshine wrote (reply to this):
|
This patch series was integrated into seen via git@2d4dbbc. |
There was a status update in the "Cooking" section about the branch "git worktree add --lock" learned to record why the worktree is locked with a custom message. Ready? |
This patch series was integrated into seen via git@a74a0c7. |
The default reason stored in the lock file, "added with --lock", is unlikely to be what the user would have given in a separate `git worktree lock` command. Allowing `--reason` to be specified along with `--lock` when adding a working tree gives the user control over the reason for locking without needing a second command. Signed-off-by: Stephen Manz <smanz@alum.mit.edu>
/submit |
Submitted as pull.992.v4.git.1626316350.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, Eric Sunshine wrote (reply to this):
|
This patch series was integrated into seen via git@a288ac1. |
On the Git mailing list, Eric Sunshine wrote (reply to this):
|
This patch series was integrated into seen via git@77e72f7. |
This patch series was integrated into next via git@609c0a4. |
There was a status update in the "Cooking" section about the branch "git worktree add --lock" learned to record why the worktree is locked with a custom message. Will merge to 'master'. |
This patch series was integrated into seen via git@7dcd64c. |
There was a status update in the "Cooking" section about the branch "git worktree add --lock" learned to record why the worktree is locked with a custom message. Will merge to 'master'. |
This patch series was integrated into seen via git@70f0cf7. |
This patch series was integrated into seen via git@33911ed. |
There was a status update in the "Cooking" section about the branch "git worktree add --lock" learned to record why the worktree is locked with a custom message. Will merge to 'master'. |
This patch series was integrated into seen via git@01369fd. |
This patch series was integrated into next via git@01369fd. |
This patch series was integrated into master via git@01369fd. |
Closed via 01369fd. |
The default reason stored in the lock file, "added with --lock",
is unlikely to be what the user would have given in a separate
git worktree lock
command. Allowing--reason
to be specifiedalong with
--lock
when adding a working tree gives the user controlover the reason for locking without needing a second command.
Changes since v3:
--reason
and toecho
to file, expected. This avoids the spacing comment made by Eric Sunshine.Changes since v2:
--lock
is not given, filelocked
gets removed after the working tree is populated. Thus, it's not really user-facing. Modified the commit message accordingly.lock_reason
member ofstruct add_opts
and changed type of memberkeep_locked
fromint
toconst char *
, as suggested.The file, .git/worktrees/name-of-worktree/locked, is created even if
--lock
isn't given, although only temporarily. In this instance, "initializing" is written to the file, but the file is removed at the end of theadd-worktree
operation. My goal was to maintain this behavior and is the reason my post-parsing code doesn't quite match the suggested patch.Changes since v1:
git rev-parse
in the test above the ones I'm adding. The second is wrapping the "added with --lock" string with_()
to mark it for translation. The third commit is the main change.test_when_finished ...
command to unlock the working treetest_expect_failure
totest_expect_success
and embeddedtest_must_fail
andtest_path_is_missing
commandsNote: I don't see how to disambiguate
--lock
with no--reason
from no--lock
at all. I still think that the originalkeep_locked
boolean is needed along with the newlock_reason
char array. If I don't addlock_reason
and changekeep_locked
to a char array, it will start as NULL. But it will remain NULL if--lock
alone is given or if--lock
isn't given at all.Thanks for taking the time to contribute to Git! Please be advised that the
Git community does not use github.com for their contributions. Instead, we use
a mailing list (git@vger.kernel.org) for code submissions, code reviews, and
bug reports. Nevertheless, you can use GitGitGadget (https://gitgitgadget.github.io/)
to conveniently send your Pull Requests commits to our mailing list.
Please read the "guidelines for contributing" linked above!
cc: Eric Sunshine sunshine@sunshineco.com
cc: Eric Sunshine sunshine@sunshineco.com