Svn get current user

倖福魔咒の 提交于 2020-01-12 04:00:11

问题


How to get current user that is using svn on particular workstation?

can I use svn.exe executable with some switch to get that info.

Thanks.


回答1:


In Linux, you will find the following file in your home directory:

~/.subversion/auth/svn.simple

In this file, you can see the "currently logged in user".




回答2:


There's no such thing as the "current user that is using svn." Every time an SVN command is submitted, credentials are supplied either explicitly at the command prompt or implicitly through saved credentials, which could include multiple users.




回答3:


In Windows it is located in

%APPDATA%\Subversion\auth\

To find this directory, just go to run (win-key+r), paste the above command and hit enter or click on Run button.

For me, there was a file in folder svn.simple. It is a text file and it has info with saved authentication data. I have something like this:

...
K 8
username
V 6
kosta
END



回答4:


grep username ~/.subversion/auth/svn.simple/* --after-context=2 | tail -1

Explanation:

  1. Grep the file in grep username ~/.subversion/auth/svn.simple/* will look for username

  2. --after-context=2 will print +2 line after it encounters username

Output:

username
V 6
Bhavik
  1. To print only the username
    use | tail -1 will give me my username i.e Bhavik.

Hope this explains the code.




回答5:


There are several ways to find out stored logon credentials:

  • Run svn auth to view credentials and certificates cached in SVN credential store (%APPDATA%\Subversion\auth).
  • Run cmdkey to view the credentials stored in Windows Credential Manager.
  • If your SVN server is integrated with Active Directory and supports Integrated Windows Authentication, your Windows logon credentials are used for authentication, but they are not cached. You can run whoami to find out your user account name .

BTW, don't miss Michael Hackner's answer:

There's no such thing as the "current user that is using svn." Every time an SVN command is submitted, credentials are supplied either explicitly at the command prompt or implicitly through saved credentials, which could include multiple users.




回答6:


If you are using SVN+SSH, then, the username of the user for a given workstation is in the config file for SVN. Assuming Windows workstation, this file will be in C:\Documents and Settings\\Application Data\Subversion folder. You can then write a script to get this name, and do what ever you need it for.

I think this is only for SVN+SSH setup. It cant work in other connectivity setups for SVN.




回答7:


If you are talking about the saved credentials: either you infer it from the log or you commit something (from the mentioned workstation/server) so you can see what the log says.




回答8:


Edit: Note this answer only applies to SVN versions before 1.9. If you using SVN version >1.9, then try the svn auth approach described in @bahrep's answer

This is a bash script that I use, which I put in my ~/bin/ folder and called svn_whoami.sh:

#!/bin/bash

debug=false

for ((i=1;i<=$#;i++)) do
    case ${!i} in

        -h|--help)
            programName=$( basename ${0} )
            echo "Usage:"
            echo "    ${programName} [-h|--help] [-d|--debug]"
            echo
            echo "Example:"
            echo "    ${programName} --debug"
            exit 0;
            ;;
        -d|--debug)
            debug=true;
            ;;

    esac;
done;

if [ "${debug}" == "true" ]; then
    echo "cat ~/.subversion/auth/svn.simple/* | grep -A6 username --color";
fi;

cat ~/.subversion/auth/svn.simple/* | grep -A6 svn:realmstring

Output:

$ svn_whoami.sh -d
cat ~/.subversion/auth/svn.simple/* | grep -A6 username --color
svn:realmstring
V 53
<http://your.1st.url.name.here:80> Authorization Realm
K 8
username
V 5
yourUserName
--
svn:realmstring
V 45
<http://your.2nd.url.name.here:80> Authorization Realm
K 8
username
V 5
yourUserName


来源:https://stackoverflow.com/questions/2022919/svn-get-current-user

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!