[Sublime Text] 在 Sublime Text 裡使用 Perforce plugin

[Sublime Text] 在 Sublime Text 裡使用 Perforce plugin

公司的 CVS 系統是使用 Perforce,之前就知道 Sublime Text 有支援 Perforce 的 plugin,

不過一直沒有使用成功,最近決定再來試用一次,

終於可以成功地 check out 檔案啦~立刻來記錄一下~

 

參考資料:

P4 Command Reference – P4PASSWD

 

1. 安裝 Perforce plugin

到 Sublime Text > Tools > Command Palette > Package Control: Install Package,

搜尋 Perforce,就可以直接安裝了:

Screen Shot 2016-01-24 at 11.03.22 PM  

 

2. 設定 Perforce plugin

Perforce plugin 的設定預設值如下,我是覺得沒有需要修改:

{
"perforce_auto_checkout": true, // when true, checkout will occur depending on the modify/save settings
"perforce_auto_checkout_on_save": true,
"perforce_auto_checkout_on_modified": false,
"perforce_auto_add": true, // when true, any file within the client spec that doesn't exist during the presave will be added
"perforce_warnings_enabled": true, // will output messages when warnings happen
"perforce_end_line_separator": "n", // used to reconstruct the depot file after breaking it up to remove the first line
"perforce_log_warnings_to_status": true, // used to redirect logs to the status bar instead. The standard output is too big for the line (can be multi-line with the raw output of p4)
"perforce_default_graphical_diff_command": "p4diff "%depotfile_path""%file_path" -l "%file_name in depot" -e -1 4", // used only if Select Graphical Diff Application is not called
// "perforce_p4env": "~/.p4env", // optional environent file to source rather than ~/.bash_profile
//"perforce_p4path": "/usr/local/bin/"		// optional path for p4 if symlink not available (e.g. OSX El Capitan cannot write to /usr/bin/).
}

 

要修改的話,就到 Sublime Text > Preferences > Package Settings

> Perforce > Settings – Default 複製一份到 Settings – User,再修改就行了~

 

3. 使用 Perforce plugin 自動 check out 檔案

當編輯並儲存檔案時,Perforce plugin 就會自動幫我們 check out 檔案,

用 P4V 就可以看到它幫我們 check out 到 default 的 changelist:

Screen Shot 2016-01-24 at 11.56.24 PM  

 

如果有開 Sublime Text 的 Console View 視窗的話,可以看到相關的訊息:

Perforce: //Core/src/test_all.sh#1 - opened for edit

 

不過通常不會這麼順利,像我一開始使用 Perforce plugin,

修改檔案並儲存後,就會看到 Console view 裡有一個錯誤訊息,如:

Perforce: Perforce password (P4PASSWD) invalid or unset.

 

研究了一下,目前確定可以解決問題的步驟是先在 terminal 裡,

執行 p4 login -p 來登入後,取得一個 ticket,

如下例中的 ABCD5905741C9F6E7A1A2511B30AABCD:

testuser@localhost ~ $ p4 login -p
Enter password:
ABCD5905741C9F6E7A1A2511B30AABCD

 

接著將環境變數 P4PASSWD 設定成這個 ticket 的值後,

再從這個已經設定好環境變數的 terminal 開啟 Sublime Text:

export P4PASSWD=ABCD5905741C9F6E7A1A2511B30AABCD
open -a "Sublime Text"

 

也許有其他比較簡單的方法,不過上面這個至少是目前可用的方法囉~^^

 

(本頁面已被瀏覽過 662 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料