From b462c024022e3a41821f24bca9e43f16973693db Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Sun, 22 May 2016 16:33:51 +0700 Subject: completion: support git-worktree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds bare-bone completion support for git-worktree. More advanced completion (e.g. ref completion in git-worktree-add) can be added later. --force completion in "worktree add" is left out because that option should be handled with care. Signed-off-by: Nguyễn Thái Ngọc Duy Reviewed-by: Eric Sunshine Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'contrib/completion/git-completion.bash') diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 34024754d9..951a186df0 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2595,6 +2595,29 @@ _git_whatchanged () _git_log } +_git_worktree () +{ + local subcommands="add list prune" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + else + case "$subcommand,$cur" in + add,--*) + __gitcomp "--detach" + ;; + list,--*) + __gitcomp "--porcelain" + ;; + prune,--*) + __gitcomp "--dry-run --expire --verbose" + ;; + *) + ;; + esac + fi +} + __git_main () { local i c=1 command __git_dir -- cgit v1.3 From 21d2a9e3cce6167a3cf69303ad5b35ec819a763b Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Fri, 10 Jun 2016 12:12:04 +0200 Subject: completion: factor out untracked file modes into a variable Signed-off-by: Thomas Braun Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'contrib/completion/git-completion.bash') diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index e3918c87e3..a44e00b45e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1098,6 +1098,8 @@ _git_clone () esac } +__git_untracked_file_modes="all no normal" + _git_commit () { case "$prev" in @@ -1119,7 +1121,7 @@ _git_commit () return ;; --untracked-files=*) - __gitcomp "all no normal" "" "${cur##--untracked-files=}" + __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" return ;; --*) -- cgit v1.3 From 7c599e92aaba4a2ef07784858def25ced8512276 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Fri, 10 Jun 2016 12:12:05 +0200 Subject: completion: add __git_get_option_value helper This function allows to search the commmand line and config files for an option, long and short, with mandatory value. The function would return e.g. for the command line "git status -uno --untracked-files=all" the result "all" regardless of the config option. Signed-off-by: Thomas Braun Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'contrib/completion/git-completion.bash') diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index a44e00b45e..14a8d0fe6e 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -803,6 +803,50 @@ __git_find_on_cmdline () done } +# Echo the value of an option set on the command line or config +# +# $1: short option name +# $2: long option name including = +# $3: list of possible values +# $4: config string (optional) +# +# example: +# result="$(__git_get_option_value "-d" "--do-something=" \ +# "yes no" "core.doSomething")" +# +# result is then either empty (no option set) or "yes" or "no" +# +# __git_get_option_value requires 3 arguments +__git_get_option_value () +{ + local c short_opt long_opt val + local result= values config_key word + + short_opt="$1" + long_opt="$2" + values="$3" + config_key="$4" + + ((c = $cword - 1)) + while [ $c -ge 0 ]; do + word="${words[c]}" + for val in $values; do + if [ "$short_opt$val" = "$word" ] || + [ "$long_opt$val" = "$word" ]; then + result="$val" + break 2 + fi + done + ((c--)) + done + + if [ -n "$config_key" ] && [ -z "$result" ]; then + result="$(git --git-dir="$(__gitdir)" config "$config_key")" + fi + + echo "$result" +} + __git_has_doubledash () { local c=1 -- cgit v1.3 From 634d2344e608c218e8163fe0b14e50ec1a62066a Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Fri, 10 Jun 2016 12:12:06 +0200 Subject: completion: add git status Signed-off-by: Thomas Braun Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'contrib/completion/git-completion.bash') diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 14a8d0fe6e..bb3acac1ec 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1825,6 +1825,56 @@ _git_stage () _git_add } +_git_status () +{ + local complete_opt + local untracked_state + + case "$cur" in + --ignore-submodules=*) + __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}" + return + ;; + --untracked-files=*) + __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" + return + ;; + --column=*) + __gitcomp " + always never auto column row plain dense nodense + " "" "${cur##--column=}" + return + ;; + --*) + __gitcomp " + --short --branch --porcelain --long --verbose + --untracked-files= --ignore-submodules= --ignored + --column= --no-column + " + return + ;; + esac + + untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \ + "$__git_untracked_file_modes" "status.showUntrackedFiles")" + + case "$untracked_state" in + no) + # --ignored option does not matter + complete_opt= + ;; + all|normal|*) + complete_opt="--cached --directory --no-empty-directory --others" + + if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then + complete_opt="$complete_opt --ignored --exclude=*" + fi + ;; + esac + + __git_complete_index_file "$complete_opt" +} + __git_config_get_set_variables () { local prevword word config_file= c=$cword -- cgit v1.3 From 58142c09a4fe825912e5a2ebfa1ba5f7f6d8beb5 Mon Sep 17 00:00:00 2001 From: Nguyễn Thái Ngọc Duy Date: Mon, 13 Jun 2016 19:18:24 +0700 Subject: worktree: add "lock" command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Helped-by: Eric Sunshine Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- Documentation/git-worktree.txt | 26 +++++++++++++----- builtin/worktree.c | 38 +++++++++++++++++++++++++++ contrib/completion/git-completion.bash | 5 +++- t/t2028-worktree-move.sh | 48 ++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 7 deletions(-) create mode 100755 t/t2028-worktree-move.sh (limited to 'contrib/completion/git-completion.bash') diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt index 27feff6dba..b49b25bf52 100644 --- a/Documentation/git-worktree.txt +++ b/Documentation/git-worktree.txt @@ -11,6 +11,7 @@ SYNOPSIS [verse] 'git worktree add' [-f] [--detach] [--checkout] [-b ] [] 'git worktree list' [--porcelain] +'git worktree lock' [--reason ] 'git worktree prune' [-n] [-v] [--expire ] DESCRIPTION @@ -38,9 +39,8 @@ section "DETAILS" for more information. If a linked working tree is stored on a portable device or network share which is not always mounted, you can prevent its administrative files from -being pruned by creating a file named 'locked' alongside the other -administrative files, optionally containing a plain text reason that -pruning should be suppressed. See section "DETAILS" for more information. +being pruned by issuing the `git worktree lock` command, optionally +specifying `--reason` to explain why the working tree is locked. COMMANDS -------- @@ -61,6 +61,14 @@ each of the linked worktrees. The output details include if the worktree is bare, the revision currently checked out, and the branch currently checked out (or 'detached HEAD' if none). +lock:: + +If a working tree is on a portable device or network share which +is not always mounted, lock it to prevent its administrative +files from being pruned automatically. This also prevents it from +being moved or deleted. Optionally, specify a reason for the lock +with `--reason`. + prune:: Prune working tree information in $GIT_DIR/worktrees. @@ -110,6 +118,13 @@ OPTIONS --expire