-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* jk/git-prompt: contrib: add credential helper for OS X Keychain Makefile: OS X has /dev/tty Makefile: linux has /dev/tty credential: use git_prompt instead of git_getpass prompt: use git_terminal_prompt add generic terminal prompt function refactor git_getpass into generic prompt function move git_getpass to its own source file imap-send: don't check return value of git_getpass imap-send: avoid buffer overflow Conflicts: Makefile
- Loading branch information
Showing
12 changed files
with
374 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "git-compat-util.h" | ||
#include "compat/terminal.h" | ||
#include "sigchain.h" | ||
#include "strbuf.h" | ||
|
||
#ifdef HAVE_DEV_TTY | ||
|
||
static int term_fd = -1; | ||
static struct termios old_term; | ||
|
||
static void restore_term(void) | ||
{ | ||
if (term_fd < 0) | ||
return; | ||
|
||
tcsetattr(term_fd, TCSAFLUSH, &old_term); | ||
term_fd = -1; | ||
} | ||
|
||
static void restore_term_on_signal(int sig) | ||
{ | ||
restore_term(); | ||
sigchain_pop(sig); | ||
raise(sig); | ||
} | ||
|
||
char *git_terminal_prompt(const char *prompt, int echo) | ||
{ | ||
static struct strbuf buf = STRBUF_INIT; | ||
int r; | ||
FILE *fh; | ||
|
||
fh = fopen("/dev/tty", "w+"); | ||
if (!fh) | ||
return NULL; | ||
|
||
if (!echo) { | ||
struct termios t; | ||
|
||
if (tcgetattr(fileno(fh), &t) < 0) { | ||
fclose(fh); | ||
return NULL; | ||
} | ||
|
||
old_term = t; | ||
term_fd = fileno(fh); | ||
sigchain_push_common(restore_term_on_signal); | ||
|
||
t.c_lflag &= ~ECHO; | ||
if (tcsetattr(fileno(fh), TCSAFLUSH, &t) < 0) { | ||
term_fd = -1; | ||
fclose(fh); | ||
return NULL; | ||
} | ||
} | ||
|
||
fputs(prompt, fh); | ||
fflush(fh); | ||
|
||
r = strbuf_getline(&buf, fh, '\n'); | ||
if (!echo) { | ||
putc('\n', fh); | ||
fflush(fh); | ||
} | ||
|
||
restore_term(); | ||
fclose(fh); | ||
|
||
if (r == EOF) | ||
return NULL; | ||
return buf.buf; | ||
} | ||
|
||
#else | ||
|
||
char *git_terminal_prompt(const char *prompt, int echo) | ||
{ | ||
return getpass(prompt); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef COMPAT_TERMINAL_H | ||
#define COMPAT_TERMINAL_H | ||
|
||
char *git_terminal_prompt(const char *prompt, int echo); | ||
|
||
#endif /* COMPAT_TERMINAL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
git-credential-osxkeychain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
all:: git-credential-osxkeychain | ||
|
||
CC = gcc | ||
RM = rm -f | ||
CFLAGS = -g -Wall | ||
|
||
git-credential-osxkeychain: git-credential-osxkeychain.o | ||
$(CC) -o $@ $< -Wl,-framework -Wl,Security | ||
|
||
git-credential-osxkeychain.o: git-credential-osxkeychain.c | ||
$(CC) -c $(CFLAGS) $< | ||
|
||
clean: | ||
$(RM) git-credential-osxkeychain git-credential-osxkeychain.o |
Oops, something went wrong.