Skip to contentSkip to conversation

interactive: add interactive command helper

PATCH In review shrimech 3 participants 4 messages Aug 2 – Aug 4 1 message not in the archive Kbuild

lore
Share & tools
lore

shrimech

author
#0 lore raw

PATCH 1/1 interactive: add interactive command helper

Git does not provide a simple interactive entry point for common working-tree and history operations.

Add a new git interactive command that presents a terminal menu for common operations, including status, adding changed files, log, graph output, branch listing, and help.

The add operation provides a submenu that lists changed files and allows the user to stage an individual file or all changed files.

Register the new builtin command and add tests covering menu selection and file staging.

---
 Makefile               |   3 +
 builtin.h              |   1 +
 builtin/interactive.c  | 250 +++++++++++++++++++++++++++++++++++++++++
 command-list.txt       |   1 +
 git-interactive        | Bin 0 -> 20828840 bytes
 git.c                  |   1 +
 t/t0013-interactive.sh |  37 ++++++
 7 files changed, 293 insertions(+)
 create mode 100644 builtin/interactive.c
 create mode 100755 git-interactive
 create mode 100644 t/t0013-interactive.sh
Makefile +3 -0
index fac3e8879c..e6b32766e8 100644
@@ -1444,6 +1444,7 @@ BUILTIN_OBJS += builtin/history.o
 BUILTIN_OBJS += builtin/hook.o
 BUILTIN_OBJS += builtin/index-pack.o
 BUILTIN_OBJS += builtin/init-db.o
+BUILTIN_OBJS += builtin/interactive.o
 BUILTIN_OBJS += builtin/interpret-trailers.o
 BUILTIN_OBJS += builtin/last-modified.o
 BUILTIN_OBJS += builtin/log.o
@@ -3951,6 +3952,8 @@ ifdef MSVC
 	$(RM) compat/vcbuild/MSVC-DEFS-GEN
 endif
 
+re: clean all
+
 .PHONY: all install profile-clean cocciclean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
 .PHONY: FORCE
builtin.h +1 -0
index 4e47a4ebd3..1a26093389 100644
@@ -201,6 +201,7 @@ int cmd_history(int argc, const char **argv, const char *prefix, struct reposito
 int cmd_hook(int argc, const char **argv, const char *prefix, struct repository *repo);
 int cmd_index_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
 int cmd_init_db(int argc, const char **argv, const char *prefix, struct repository *repo);
+int cmd_interactive(int argc, const char **argv, const char *prefix, struct repository *repo);
 int cmd_interpret_trailers(int argc, const char **argv, const char *prefix, struct repository *repo);
 int cmd_last_modified(int argc, const char **argv, const char *prefix, struct repository *repo);
 int cmd_log_reflog(int argc, const char **argv, const char *prefix, struct repository *repo);
builtin/interactive.c new file +250 -0

250 lines not on this page · raw message

command-list.txt +1 -0
index 21b802c420..0cd0e8957a 100644
@@ -125,6 +125,7 @@ git-imap-send                           foreignscminterface
 git-index-pack                          plumbingmanipulators
 git-init                                mainporcelain           init
 git-instaweb                            ancillaryinterrogators          complete
+git-interactive                         ancillaryinterrogators
 git-interpret-trailers                  purehelpers
 git-last-modified                       plumbinginterrogators
 git-log                                 mainporcelain           info
git-interactive new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..980a21c967d02ab121a54ee586cc9de4a98aa725
GIT binary patch
git.c +1 -0
index e5f1811b6b..482099f9eb 100644
@@ -592,6 +592,7 @@ static struct cmd_struct commands[] = {
 	{ "index-pack", cmd_index_pack, RUN_SETUP_GENTLY | NO_PARSEOPT },
 	{ "init", cmd_init_db },
 	{ "init-db", cmd_init_db },
+	{ "interactive", cmd_interactive },
 	{ "interpret-trailers", cmd_interpret_trailers, RUN_SETUP_GENTLY },
 	{ "last-modified", cmd_last_modified, RUN_SETUP },
 	{ "log", cmd_log, RUN_SETUP },
t/t0013-interactive.sh new file +37 -0
new file mode 100644
index 0000000000..4d82efbf95
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+test_description='git interactive command selection'
+
+. ./test-lib.sh
+
+test_expect_success 'interactive menu can dispatch a numbered selection' '
+	git_bin="$TEST_DIRECTORY/../git" &&
+	printf "1\n" | "$git_bin" interactive >output 2>err &&
+	test_grep "Launching: git status" output
+'
+
+test_expect_success 'add submenu can stage a selected changed file' '
+	tmpdir=$(mktemp -d) &&
+	outdir=$(mktemp -d) &&
+	git_bin="$TEST_DIRECTORY/../git" &&
+	test_when_finished "rm -rf \"$tmpdir\" \"$outdir\"" &&
+	(
+		cd "$tmpdir" &&
+		git init -q &&
+		git config user.name tester &&
+		git config user.email [email protected] &&
+		printf "hello\n" >tracked.txt &&
+		git add tracked.txt &&
+		git commit -qm init &&
+		printf "more\n" >>tracked.txt &&
+		printf "5\n1\nq\n" | "$git_bin" interactive >"$outdir/output" 2>"$outdir/err"
+	) &&
+	test_grep "Add changed files" "$outdir/output" &&
+	(
+		cd "$tmpdir" &&
+		git diff --cached --name-only >staged &&
+		test_grep "tracked.txt" staged
+	)
+'
+
+test_done
Signature · 1 line
2.53.0
#1 lore raw
Quoted 4 lines · shrimech

Git does not provide a simple interactive entry point for common working-tree and history operations.

Add a new git interactive command that presents a terminal menu for common operations, including status, adding changed files, log, graph output, branch listing, and help.

Git comes with built-in GUI tools in git-gui and gitk. Also there are several third-party frontends[1] available for Git. Why add another built-in interactive interface instead of modify or adding to what already exists?

[1] https://git-scm.com/tools/guis

git-interactive

Quoted 5 lines
git-interactive new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..980a21c967d02ab121a54ee586cc9de4a98aa725
GIT binary patch

I think including this binary patch was a mistake?

A message that is not in the archive (sent off-list or not yet received): CAHiURhuC-dnUJ80T7f3ZynV_qj-b9_9Rs0YxyibCNDeNnuKEJA@mail.gmail.com

#3 lore raw

Cc'ing so reply is in thread. Generally, you should reply all so [email protected] is included
(coming from someone who is also acclimating to the list's email workflow :).

Quoted 3 lines · Salah Eddine HRIMECHE

i see the command "git add -i" that come with an interactive mode ,then i say with my self that you want to implement an interactive space for terminal i say with myself that going with a new command interactive is better than use it just like an option of add

I don't follow the reasoning here.

#4 lore raw
In reply to Michael Montalbo
Quoted 8 lines · Michael Montalbo

[snip]

git-interactive

Quoted 5 lines
git-interactive new file binary +0 -0
new file mode 100755
index 0000000000000000000000000000000000000000..980a21c967d02ab121a54ee586cc9de4a98aa725
GIT binary patch

I think including this binary patch was a mistake?

@shrimech your two next versions of this patch have also included this binary patch. git-interactive is a compiled artifact and should not be version controlled.

I am replying to this email because replying to the latest patch in my email webapp was too difficult.