Skip to content

Commit e277097

Browse files
peffgitster
authored andcommitted
credentials: add "cache" helper
If you access repositories over smart-http using http authentication, then it can be annoying to have git ask you for your password repeatedly. We cache credentials in memory, of course, but git is composed of many small programs. Having to input your password for each one can be frustrating. This patch introduces a credential helper that will cache passwords in memory for a short period of time. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a6fc9fd commit e277097

12 files changed

+812
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
/git-commit-tree
3131
/git-config
3232
/git-count-objects
33+
/git-credential-cache
34+
/git-credential-cache--daemon
3335
/git-cvsexportcommit
3436
/git-cvsimport
3537
/git-cvsserver
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
git-credential-cache--daemon(1)
2+
===============================
3+
4+
NAME
5+
----
6+
git-credential-cache--daemon - temporarily store user credentials in memory
7+
8+
SYNOPSIS
9+
--------
10+
[verse]
11+
git credential-cache--daemon <socket>
12+
13+
DESCRIPTION
14+
-----------
15+
16+
NOTE: You probably don't want to invoke this command yourself; it is
17+
started automatically when you use linkgit:git-credential-cache[1].
18+
19+
This command listens on the Unix domain socket specified by `<socket>`
20+
for `git-credential-cache` clients. Clients may store and retrieve
21+
credentials. Each credential is held for a timeout specified by the
22+
client; once no credentials are held, the daemon exits.
23+
24+
GIT
25+
---
26+
Part of the linkgit:git[1] suite
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
git-credential-cache(1)
2+
=======================
3+
4+
NAME
5+
----
6+
git-credential-cache - helper to temporarily store passwords in memory
7+
8+
SYNOPSIS
9+
--------
10+
-----------------------------
11+
git config credential.helper 'cache [options]'
12+
-----------------------------
13+
14+
DESCRIPTION
15+
-----------
16+
17+
This command caches credentials in memory for use by future git
18+
programs. The stored credentials never touch the disk, and are forgotten
19+
after a configurable timeout. The cache is accessible over a Unix
20+
domain socket, restricted to the current user by filesystem permissions.
21+
22+
You probably don't want to invoke this command directly; it is meant to
23+
be used as a credential helper by other parts of git. See
24+
linkgit:gitcredentials[7] or `EXAMPLES` below.
25+
26+
OPTIONS
27+
-------
28+
29+
--timeout <seconds>::
30+
31+
Number of seconds to cache credentials (default: 900).
32+
33+
--socket <path>::
34+
35+
Use `<path>` to contact a running cache daemon (or start a new
36+
cache daemon if one is not started). Defaults to
37+
`~/.git-credential-cache/socket`. If your home directory is on a
38+
network-mounted filesystem, you may need to change this to a
39+
local filesystem.
40+
41+
CONTROLLING THE DAEMON
42+
----------------------
43+
44+
If you would like the daemon to exit early, forgetting all cached
45+
credentials before their timeout, you can issue an `exit` action:
46+
47+
--------------------------------------
48+
git credential-cache exit
49+
--------------------------------------
50+
51+
EXAMPLES
52+
--------
53+
54+
The point of this helper is to reduce the number of times you must type
55+
your username or password. For example:
56+
57+
------------------------------------
58+
$ git config credential.helper cache
59+
$ git push http://example.com/repo.git
60+
Username: <type your username>
61+
Password: <type your password>
62+
63+
[work for 5 more minutes]
64+
$ git push http://example.com/repo.git
65+
[your credentials are used automatically]
66+
------------------------------------
67+
68+
You can provide options via the credential.helper configuration
69+
variable (this example drops the cache time to 5 minutes):
70+
71+
-------------------------------------------------------
72+
$ git config credential.helper 'cache --timeout=300'
73+
-------------------------------------------------------
74+
75+
GIT
76+
---
77+
Part of the linkgit:git[1] suite

Documentation/gitcredentials.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,18 @@ Credential helpers, on the other hand, are external programs from which git can
6363
request both usernames and passwords; they typically interface with secure
6464
storage provided by the OS or other programs.
6565

66-
To use a helper, you must first select one to use. Git does not yet
67-
include any credential helpers, but you may have third-party helpers
68-
installed; search for `credential-*` in the output of `git help -a`, and
69-
consult the documentation of individual helpers. Once you have selected
70-
a helper, you can tell git to use it by putting its name into the
66+
To use a helper, you must first select one to use. Git currently
67+
includes the following helpers:
68+
69+
cache::
70+
71+
Cache credentials in memory for a short period of time. See
72+
linkgit:git-credential-cache[1] for details.
73+
74+
You may also have third-party helpers installed; search for
75+
`credential-*` in the output of `git help -a`, and consult the
76+
documentation of individual helpers. Once you have selected a helper,
77+
you can tell git to use it by putting its name into the
7178
credential.helper variable.
7279

7380
1. Find a helper.

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ PROGRAM_OBJS += show-index.o
427427
PROGRAM_OBJS += upload-pack.o
428428
PROGRAM_OBJS += http-backend.o
429429
PROGRAM_OBJS += sh-i18n--envsubst.o
430+
PROGRAM_OBJS += credential-cache.o
431+
PROGRAM_OBJS += credential-cache--daemon.o
430432

431433
PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))
432434

@@ -699,6 +701,7 @@ LIB_OBJS += transport-helper.o
699701
LIB_OBJS += tree-diff.o
700702
LIB_OBJS += tree.o
701703
LIB_OBJS += tree-walk.o
704+
LIB_OBJS += unix-socket.o
702705
LIB_OBJS += unpack-trees.o
703706
LIB_OBJS += url.o
704707
LIB_OBJS += usage.o

0 commit comments

Comments
 (0)